Kenix Posted April 12, 2011 Share Posted April 12, 2011 do that every second add to ElementData + 1 and when such ElementData == 60 seconds, then zero out seconds and do a minute to. but the script does not work exports.dxscoreboard:addScoreboardColumn ( "Seconds" ) exports.dxscoreboard:addScoreboardColumn ( "Minuts") exports.dxscoreboard:addScoreboardColumn ( "Hours") function JoinStartTime(thePlayer) local TimeSec = setElementData(source,"Seconds",0) local TimeMins = setElementData(source,"Minuts",0) local TimeHour = setElementData ( source, "Hours", 0 ) StartSecondsTime = setTimer(function() local SecondsTime5 = getElementData(thePlayer,"Seconds") if (SecondsTime5) then local getSecondsTime5 = getElementData(thePlayer, "Seconds") if getSecondsTime5 then setElementData(thePlayer,"Seconds",tonumber(getSecondsTime5+1)) else outputChatBox("I can't get the Seconds!") end end end,1000,0) end addEventHandler("onPlayerJoin", getRootElement(),JoinStartTime) function SetNewTimers(CurrentCurrentDataName) -- using dataName does not help and use thePlayer does not help outputChatBox("1") local getSecondsTime2 = getElementData(source,"Seconds") local getMinutsTime3 = getElementData(source,"Minuts") local SecondsTime1 = getElementData(source,"Hours") --[[ if (SecondsTime1) then local getSecondsTime1 = getElementData(source, "Seconds") if getSecondsTime1 then setElementData(source,"Seconds",tonumber(getSecondsTime1+1)) end end ]] if (CurrentDataName == "Seconds") then --[[ local getSecondsTime7 = getElementData(source, "Seconds") if getSecondsTime7 then setElementData(source,"Seconds",tonumber(getSecondsTime7+1)) end]] if tonumber( getSecondsTime2 ) == 60 then local MinutsTime2 = getElementData(source,"Minuts") if (MinutsTime2) then local getMinutsTime2 = getElementData(source, "Minuts") if getMinutsTime2 then setElementData(source,"Minuts",tonumber(getMinutsTime2+1)) setElementData(source,"Seconds",0) end end end if (CurrentDataName == "Minuts") then if tonumber( getMinutsTime3 ) == 60 then local HourTime2 = getElementData(source,"Hours") if (HourTime2) then local getHourTime3 = getElementData(source, "Hours") if getHourTime3 then setElementData(source,"Hours",tonumber(getHourTime2+1)) setElementData(source,"Minuts",0) end end end end end end addEventHandler("onElementDataChange",getRootElement(),SetNewTimers) added check once again writes an error on line 12 Bad Argument@ `getElementData` no errors in create dates outputChatBox("Create data"..tostring(TimeSec).." , "..tostring(TimeMins).." , "..tostring(TimeHour)) Link to comment
Wojak Posted April 12, 2011 Share Posted April 12, 2011 you will never lern... replace function JoinStartTime(thePlayer) with function JoinStartTime() local thePlayer = source and change all source in this function to thePlayer note that source will not work in anonimus function (in setTimer) so you need to asign it to thePlayer Link to comment
Kenix Posted April 12, 2011 Author Share Posted April 12, 2011 I altered the code now it is fully working. yes it work THX DUDE but WARNING : level/test.lua:13 Bad `element` pointer @ `getElementData`(1) this 13 line local SecondsTime5 = getElementData(thePlayer,"Seconds") full code setTimer . StartSecondsTime = setTimer(function() local SecondsTime5 = getElementData(thePlayer,"Seconds") if (SecondsTime5) then local getSecondsTime5 = getElementData(thePlayer, "Seconds") if getSecondsTime5 then setElementData(thePlayer,"Seconds",tonumber(getSecondsTime5+1)) else outputChatBox("I can't get the Seconds!") end end end,1000,0) how fix it? it is spam in the server window. Link to comment
Wojak Posted April 12, 2011 Share Posted April 12, 2011 StartSecondsTime = setTimer(function() if isElement(thePlayer) then local SecondsTime5 = getElementData(thePlayer,"Seconds") if (SecondsTime5) then local getSecondsTime5 = getElementData(thePlayer, "Seconds") if getSecondsTime5 then setElementData(thePlayer,"Seconds",tonumber(getSecondsTime5+1)) else outputChatBox("I can't get the Seconds!") end end end end,1000,0) Link to comment
DakiLLa Posted April 12, 2011 Share Posted April 12, 2011 What's actually stored in this 'thePlayer' variable inside the function that called by a timer? I assume it should be setTimer( function( thePlayer ) ... end, 1000, 0, playerVariable ) Otherwise it's nil. Link to comment
Wojak Posted April 13, 2011 Share Posted April 13, 2011 the problem is that setTimer creates a infinit loop, even if the player quits it still try to perform operations on him... the solution is to check if the element exist (isElement(thePlayer)) and (what i should done in previous post) kill the timer when the player left the game full code: function JoinStartTime() local thePlayer = source local TimeSec = setElementData(thePlayer,"Seconds",0) local TimeMins = setElementData(thePlayer,"Minuts",0) local TimeHour = setElementData ( thePlayer, "Hours", 0 ) local StartSecondsTime = setTimer(function() if isElement(thePlayer) then local SecondsTime5 = getElementData(thePlayer,"Seconds") if (SecondsTime5) then local getSecondsTime5 = getElementData(thePlayer, "Seconds") if getSecondsTime5 then setElementData(thePlayer,"Seconds",tonumber(getSecondsTime5+1)) else outputChatBox("I can't get the Seconds!") end end else killTimer(StartSecondsTime) end end,1000,0) end addEventHandler("onPlayerJoin", getRootElement(),JoinStartTime) Link to comment
Kenix Posted April 13, 2011 Author Share Posted April 13, 2011 the problem is that setTimer creates a infinit loop, even if the player quits it still try to perform operations on him...the solution is to check if the element exist (isElement(thePlayer)) and (what i should done in previous post) kill the timer when the player left the game full code: function JoinStartTime() local thePlayer = source local TimeSec = setElementData(thePlayer,"Seconds",0) local TimeMins = setElementData(thePlayer,"Minuts",0) local TimeHour = setElementData ( thePlayer, "Hours", 0 ) local StartSecondsTime = setTimer(function() if isElement(thePlayer) then local SecondsTime5 = getElementData(thePlayer,"Seconds") if (SecondsTime5) then local getSecondsTime5 = getElementData(thePlayer, "Seconds") if getSecondsTime5 then setElementData(thePlayer,"Seconds",tonumber(getSecondsTime5+1)) else outputChatBox("I can't get the Seconds!") end end else killTimer(StartSecondsTime) end end,1000,0) end addEventHandler("onPlayerJoin", getRootElement(),JoinStartTime) it working if remove KillTimer Thx guys 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