M3Mori3s93 Posted July 9, 2017 Share Posted July 9, 2017 Hello. Guys I have a question , how I can make a payday system on everyday at 7:00 AM in real time for all players, Which fuctions should I use? Link to comment
Swagy Posted July 9, 2017 Share Posted July 9, 2017 well, no specific, you have to set a timer using setTimer(function, timeInterval, timestoexecute) and then run the script at 7:00AM and set time interval to 1000*60*60*24 and the times to execute to 0 this will work for you 1 Link to comment
Gordon_G Posted July 9, 2017 Share Posted July 9, 2017 As @MaK$iM said, there is only the getRealTime() func. You can for exemple do this : - Save the last payday with an account data - Loop a timer to check every X minutes to check if the day changed and then give the payday 1 Link to comment
Sticmy Posted July 9, 2017 Share Posted July 9, 2017 setTimer(function() local time = getRealTime() local hours = time.hour local minutes = time.minute if hours == 7 and minutes == 00 then outputChatBox("Time: "..hours..":"..minute"", source, 255, 0, 0) givePlayerMoney(source, 1500) end end, 1000, 0) i have not tried it Link to comment
Swagy Posted July 9, 2017 Share Posted July 9, 2017 12 minutes ago, Steven'Bc said: setTimer(function() local time = getRealTime() local hours = time.hour local minutes = time.minute if hours == 7 and minutes == 00 then outputChatBox("Time: "..hours..":"..minute"", source, 255, 0, 0) givePlayerMoney(source, 1500) end end, 1000, 0) i have not tried it Actually, if you increase the time interval it would be better and it will save CPU usage, so each 1second? what about adding each one hour? setTimer(function() local time = getRealTime() local hours = time.hour local minutes = time.minute if hours == 7 and minutes == 00 then outputChatBox("Time: "..hours..":"..minute"", source, 255, 0, 0) givePlayerMoney(source, 1500) end end, 60000*60, 0) This would work fine and comfortable Link to comment
Sticmy Posted July 9, 2017 Share Posted July 9, 2017 2 hours ago, UDC said: Actually, if you increase the time interval it would be better and it will save CPU usage, so each 1second? what about adding each one hour? setTimer(function() local time = getRealTime() local hours = time.hour local minutes = time.minute if hours == 7 and minutes == 00 then outputChatBox("Time: "..hours..":"..minute"", source, 255, 0, 0) givePlayerMoney(source, 1500) end end, 60000*60, 0) This would work fine and comfortable Put the second you want if it appears in 30 seconds or whatever seconds you want Link to comment
Administrators Lpsd Posted July 10, 2017 Administrators Share Posted July 10, 2017 (edited) I'm not sure if I'd rely on using that timer. I see a flaw in the logic of setting the timer to 1 per hour, what if the script was initiated at 5 minutes past the hour? If the timer is only then checking once per hour, it'll never work. Here's how I'd prefer to do it Clientside: local paydayValid = true local function realtime() local time = getRealTime() local hours = time.hour local minutes = time.minute if paydayValid == true then if hours == 7 and minutes == 0 then outputChatBox("Payday, ka-ching!") triggerServerEvent("onClientPayday", resourceRoot) paydayValid = false end else if hours == 6 and minutes == 59 then paydayValid = true end end end addEventHandler("onClientRender", getRootElement(), realtime) Serverside: local function payday() givePlayerMoney(client, 1500) end addEvent("onClientPayday", true) addEventHandler("onClientPayday", getRootElement(), payday) Not tested, but it's not exactly a complicated script excuse the indenting, the forum code editor uses 2 spaces whereas I use tab Edited July 10, 2017 by LopSided_ 1 Link to comment
Sticmy Posted July 10, 2017 Share Posted July 10, 2017 2 hours ago, LopSided_ said: I'm not sure if I'd rely on using that timer. I see a flaw in the logic of setting the timer to 1 per hour, what if the script was initiated at 5 minutes past the hour? If the timer is only then checking once per hour, it'll never work. Here's how I'd prefer to do it Clientside: local paydayValid = true local function realtime() local time = getRealTime() local hours = time.hour local minutes = time.minute if paydayValid == true then if hours == 7 and minutes == 0 then outputChatBox("Payday, ka-ching!") triggerServerEvent("onClientPayday", resourceRoot) paydayValid = false end else if hours == 6 and minutes == 59 then paydayValid = true end end end addEventHandler("onClientRender", getRootElement(), realtime) Serverside: local function payday() givePlayerMoney(client, 1500) end addEvent("onClientPayday", true) addEventHandler("onClientPayday", getRootElement(), payday) Not tested, but it's not exactly a complicated script excuse the indenting, the forum code editor uses 2 spaces whereas I use tab lol forget the onClientRender sorry event 1 Link to comment
Popular Post pa3ck Posted July 10, 2017 Popular Post Share Posted July 10, 2017 (edited) local diffTimer, paydayTimer local lastPayDay = false addEventHandler("onResourceStart", resourceRoot, function() diffTimer = setTimer(function() local time = getRealTime() local hours = time.hour local minutes = time.minute paydayTimer = setTimer(payDay, 60 * 60000, 0) if hours == 7 then -- in case you were lucky enough to start the resource between 6 and 7 payDay() end end, (60 - minutes) * 60000, 1) -- timer that will start the actual payday timer exactly at hour:00 minutes -- 60 - currentMinutes; if the time is 12:44 |-> 60 - 44 = 12 -> 12 * 60000ms = 12 mins so the timer will start in 12 minutes end) function payDay() local time = getRealTime() local hours = time.hour local minutes = time.minute if hours == 7 and not lastPayDay then outputChatBox("payday...") lastPayDay = true -- just to be safe and make sure it cannot run twice else lastPayDay = false end end Make sure you are using getRealTime server side.. it will use the client PC's timer on client side.. not tested, but should work. Edited July 10, 2017 by pa3ck 4 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now