WhoAmI Posted February 28, 2015 Share Posted February 28, 2015 Hello. Is there any way to call a function after 24h or after 7 days? I need it for my house system and renting house for day or 7 days. Thank you. Link to comment
launemax Posted February 28, 2015 Share Posted February 28, 2015 Hy WhoAmI, sure, you can save the starting timestamp in a variable and check with a Timer (every Minute or if possible every hour) if the new timestamp is higher or equal to the starting timestamp+24h. Or you can save the timestamp + 24h in the variable and check against this. getRealTime() setTimer() Link to comment
WhoAmI Posted February 28, 2015 Author Share Posted February 28, 2015 Well, good idea, but is it optimal way to do this? I mean if it won't increase much usage of server. Link to comment
Mr_Moose Posted February 28, 2015 Share Posted February 28, 2015 Would probably be more optimal to assign the timer on resource start and let it execute with 24 hours delay. setTimer(function, 1000*60*60*24, 0) Link to comment
Ab-47 Posted February 28, 2015 Share Posted February 28, 2015 Would probably be more optimal to assign the timer on resource start and let it execute with 24 hours delay. setTimer(function, 1000*60*60*24, 0) And restarting the script 1 minute before 24 hours will give the player another 24 hours. It's better you use an SQL database. Link Link to comment
Mr_Moose Posted February 28, 2015 Share Posted February 28, 2015 @Ab-47, First reply had the same issue, it's all about how often you want to execute these functions, using the start/stop events of the resource may also be a good solution that would bypass this issue, without wasting to much performance. Link to comment
Addlibs Posted February 28, 2015 Share Posted February 28, 2015 getTimerDetails returns how much time is left - when the resource stops, you could store all these values somewhere (preferably in a database) and when the resource starts, check if the values exist, if yes, set timers for that time, else, set for another 24 hours. Link to comment
WhoAmI Posted February 28, 2015 Author Share Posted February 28, 2015 MrTasty, I think that your idea is the best one. Thanks for advice. Link to comment
Ab-47 Posted February 28, 2015 Share Posted February 28, 2015 Yeah like "getRealTime()", start the timer, and when the resource stops, set the account data for the time it was stopped. Then when the resource starts again it could "getRealTime()" and add account data for the time it started again and calculate the difference between the stopped and started time. Would need a bit of math, but I'm sure it's possible. 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