Help to set timer script and add So you need cops to pick drugs

The first thing is that i use esx_jk_drugs But the part i dont understand is If No cops are online you can pick drug how can i add so you cant pick drugs If not like say 2 cops is online

And my 2 second question is If you can make lets say esx_fishing a timer on like you cant fish frome 18:00 to23:00 for exampel thanks for anny help or ides :slight_smile:

To answer your first question, what you can do is:

Create a callback which ‘reads’ all users and check which ones have the ‘police’ jobs, ex:

local amount = 0
local players =  ESX.Game.GetPlayers()
for k, v in pairs(players) do
  local player = ESX.Game.GetPlayerData(v)
  if player ~= nil then
     -- Check for jobname, return amount + 1
  end
end

You’ll have to build this into a callback yourself. I’m working on a custom framework so I’m not quite sure how ESX does this exactly.

After that, you can simply ‘call’ your callback and specify a minimum amount of cops that need to be active.

For your second question:

if GetClockHours() >= 1 and GetClockHours() <= 6 then
     -- Do this...
end

For this, I’m reffering to the GetClockHours native reference: https://runtime.fivem.net/doc/natives/?_0x25223CA6B4D20B7F

1 Like

oh man thanks so mutch you are awsome ! thanks for all the help

No problem, happy to hear it helped :smiley:

I Will try it out tomorrow and se how it works out :slight_smile:

hi man i got the cops thing to work now thanks you but the time thing i trying out and i cant get a grip on how to make it working :confused: can you specife a bit more sorry for my bad english

if GetClockHours() >= 1 and GetClockHours() <= 6 then
     -- Do this...
end

>=1 means higher then 1:00, <= lower then 6:00 if I’m not wrong. You’ll need to change these hours yourself and it should work.

Hi i have try it some way to make it work But i cant make it work

1 shuld i add it in the client or server ?

2 do i need to have like

Registerserverevent(esx_fishing:tryfish)

And paste your solution under it ?

3 i have try as i told diffrent ways But im kinde off bad how to create a specifed funktion If you could show me i would understand like If you made a funktion of it If you know what i mean But thanks again for the cop help

You can do this… but I wouldn’t recommend it as if you run a server with 80 people on it… and 20 people goto the drug spawn at the same time the callbacks would cause server hitch warnings on your server.

If you are using esx you could look at [Dev Release] - esx_jobnumbers for a alternate method of seeing how many of any job are online at any time.

SpikE