+[L]oS Posted July 6, 2017 Share Posted July 6, 2017 Hi, I'm creating a SQL-based currency system script, I put a setTime to generate coins at a certain time for certain players, however, I need to destroy this setTime when the player clears, I already did something to do that, However, when the player clears and setTime is destroyed, everyone's time is destroyed, not just the user who logged out. I need that when certain user is logged off, only his setTime is canceled ... does anyone have any idea what I can do? Starting time: function startFunction(_,thePlayer) tempo = setTimer ( function() ...code... end, 2000, 0 ) end Destroy time: function playerOff(thePlayer) ...code... if isTimer ( tempo ) then killTimer ( tempo ) end end addEventHandler("onPlayerQuit", getRootElement(), playerOff) addEventHandler("onPlayerLogout", getRootElement(), playerOff) Link to comment
MR.S3D Posted July 6, 2017 Share Posted July 6, 2017 (edited) tempo = {} function startFunction(_,thePlayer) if isElement(thePlayer ) and not tempo[thePlayer] then tempo[thePlayer] = setTimer ( function() end, 2000, 0 ) end function playerOff(thePlayer) if isElement(thePlayer ) and tempo[thePlayer] then if isTimer ( tempo[thePlayer] ) then killTimer ( tempo[thePlayer] ) end tempo[thePlayer] = nil end end addEventHandler("onPlayerQuit", getRootElement(), playerOff) addEventHandler("onPlayerLogout", getRootElement(), playerOff) Edited July 6, 2017 by MR.S3D Link to comment
+[L]oS Posted July 6, 2017 Author Share Posted July 6, 2017 38 minutes ago, MR.S3D said: tempo = {} function startFunction(_,thePlayer) if isElement(thePlayer ) and not tempo[thePlayer] then tempo[thePlayer] = setTimer ( function() end, 2000, 0 ) end function playerOff(thePlayer) if isElement(thePlayer ) and tempo[thePlayer] then if isTimer ( tempo[thePlayer] ) then killTimer ( tempo[thePlayer] ) end tempo[thePlayer] = nil end end addEventHandler("onPlayerQuit", getRootElement(), playerOff) addEventHandler("onPlayerLogout", getRootElement(), playerOff) Thank you very much, I have another question. At the time that setTime is destroyed, it can not be connected again? Link to comment
MR.S3D Posted July 6, 2017 Share Posted July 6, 2017 i don't understand what you mean? Link to comment
+[L]oS Posted July 6, 2017 Author Share Posted July 6, 2017 6 minutes ago, MR.S3D said: i don't understand what you mean? Sorry for my English, I'm using a translator ... anyway. I would like to know how I do to re-enable setTime because when it is destroyed by killTime, I can no longer check whether it is active or not by the "if not time [thePlayer] then". I am trying to mount the script for: When the player logs in, the script starts to give points to it, when it logs out (either because it left the server or unlogged) it stops giving points, understand? Link to comment
szekelymilan Posted July 7, 2017 Share Posted July 7, 2017 Just do it on client-side. When the player quits, it is automatically destroyed, because of the client-side.. setTimer (function() -- creating an infinite setTimer. setElementData (localPlayer, 'points', tonumber(getElementData(localPlayer, points)) + 1) -- plus 1 to the player's points end, 10000, 0) -- and that's it! 1 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