[ESX] Update table values every minute BUT SERVER SIDED

Hey, so Im making a drug dealers script, and they will spawn in certain locations for 30 minutes.
So when the value minutesRemaining is 30 or lower the NPC will spawn (already coded)
Im having trouble to automatically update the minutesRemaining value every minute and if it is <= 0 change it to 300

Why update it every minute? Create a timestamp 30 minutes in the future and check if that has been reached - you’ll need way less database writes this way.

Agreed. This is the most performant and in reality less hassle way to handle this style system.

why would u even need a db for that

Use Citizen.CreateThread and Citizen.Wait to achieve that, don’t use DB for that.

Just place a timer (kinda) on the server side by Citizen.Wait(milliseconds)

   while true do
      -- Say you like you spawn the NPC after 30 minutes
      -- So 30 minutes would be (1000 * 60) * 30 in millis
      Citizen.Wait((1000 * 60) * 30)

      -- [Your code here to spawn the drug dealer NPC]

Just one annyoing thing, why would you do 1000 * 60 * 30 instead of 60000 * 30, it’s just useless cycles.

Edit: Also why do you have parentheses on it?

Bruh if you already point this out, why not have 1800000 to avoid even more “”“useless cycles”""?

Jokes aside - Lua is compiled into bytecode before execution, so this point is completely moot.
It does not matter, as the compiler will optimize it anyway.

Why are you so mad about ((1000 * 60) * 30), I did it for readability. Why bother about my code, instead help the dude solve his problem

I literally provided the answer to his question before you did? I’m not bothering about your code KEKW

I pointed out that it was annoying me, I find 60000 * 30 more readable than 1000 * 60 * 30 but people can’t take criticism anyways :man_shrugging:

Yes you rock mister, keep up the good work and help people.

I need the DB in case the server restarts the time until next NPC spawn is saved somewhere