gokalpfirat Posted September 5, 2011 Share Posted September 5, 2011 (edited) edit. Edited September 5, 2011 by Guest Link to comment
gokalpfirat Posted September 5, 2011 Author Share Posted September 5, 2011 No one can fix? Link to comment
gokalpfirat Posted September 5, 2011 Author Share Posted September 5, 2011 I can wait Link to comment
JR10 Posted September 5, 2011 Share Posted September 5, 2011 The functions uses a player element, you are not specifying a player. function all() for index , player in ipairs ( getElementsByType ( "player" ) ) do control(player) check(player) end end Link to comment
gokalpfirat Posted September 5, 2011 Author Share Posted September 5, 2011 Now i dont get error but i cant see my online time at scoreboard function joinTime ( ) setElementData ( source, "joinTime", getTickCount() ) setElementData (source, "joinS", 0 ) setElementData (source, "joinM", 0 ) setElementData (source, "joinH", 0 ) setElementData (source, "joinD", 0 ) setElementData (source, "Online Time", nil ) end addEventHandler ( "onPlayerJoin", getRootElement(), joinTime ) function onResourceStart(res) call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Online Time") end addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),onResourceStart) function control(source) endTime = getElementData(source,"joinTime") - getTickCount() if (endTime == 1000) then setElementData (source, "joinS", tonumber(getElementData(source,"joinS"))+1 ) setElementData ( source, "joinTime", getTickCount()-1000 ) end if (getElementData(source,"joinS") == 60) then setElementData (source, "joinM", tonumber(getElementData(source,"joinM"))+1 ) setElementData ( source, "joinS", tonumber(getElementData(source,"joinS"))-60 ) end if (getElementData(source,"joinM") == 60) then setElementData (source, "joinH", tonumber(getElementData(source,"joinH"))+1 ) setElementData ( source, "joinM", tonumber(getElementData(source,"joinM"))-60 ) end if (getElementData(source,"joinH") == 24) then setElementData (source, "joinD", tonumber(getElementData(source,"joinD"))+1 ) setElementData ( source, "joinH", tonumber(getElementData(source,"joinH"))-24 ) end end function check(source) Second = getElementData(source,"joinS") Minute = getElementData(source,"joinM") Hour = getElementData(source,"joinH") Day = getElementData(source,"joinD") if (Second >= 1) then setElementData(source,"Online Time",Second.."second") elseif (Minute >= 1) then setElementData(source,"Online Time",Minute.."minute"..Second.."second") elseif (Hour >= 1) then setElementData(source,"Online Time",Hour.."Hour"..Minute.."minute"..Second.."second") elseif (Day >= 1) then setElementData(source,"Online Time",Day.."Day"..Hour.."Hour"..Minute.."minute"..Second.."second") end end function all() for index , player in ipairs ( getElementsByType ( "player" ) ) do control(player) check(player) end end setTimer(all,1000,0) Link to comment
SDK Posted September 5, 2011 Share Posted September 5, 2011 Why are you making it that hard, you can calculate it much easier (not tested) function onResourceStart() call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Online Time") end addEventHandler("onResourceStart",resourceRoot,onResourceStart) function joinTime() setElementData (source, "joinTime", getTickCount() ) setElementData (source, "Online Time", "0 hours, 0 minutes, 0 seconds" ) end addEventHandler ( "onPlayerJoin", root, joinTime ) function all() for index , player in ipairs ( getElementsByType ( "player" ) ) do local s = getElementData(player,"joinTime") or getTickCount() s = (s - getTickCount()) / 1000 local string = string.format("%02d hours, %02 minutes, %02d seconds", s/3600, (s%3600)/60, s%60) setElementData(player,"Online Time",string) end end setTimer(all,1000,0) Link to comment
gokalpfirat Posted September 5, 2011 Author Share Posted September 5, 2011 I get error at line 16(SDK) Error is: invalid option '%' to 'format' Link to comment
gokalpfirat Posted September 5, 2011 Author Share Posted September 5, 2011 Waiting for fixing Link to comment
Castillo Posted September 5, 2011 Share Posted September 5, 2011 What does that mean? because what I get is that we're your "slaves" and we have to fix it for you, I think you're WRONG, why don't you try to fix it yourself? Link to comment
gokalpfirat Posted September 5, 2011 Author Share Posted September 5, 2011 I try but i cant thats because i write this topic. Link to comment
Castillo Posted September 5, 2011 Share Posted September 5, 2011 Yes, but the way you ask for help is not right, you are like telling us to FIX it Link to comment
gokalpfirat Posted September 5, 2011 Author Share Posted September 5, 2011 No i say please fix it sorry for my old "fix it" posts Link to comment
Castillo Posted September 5, 2011 Share Posted September 5, 2011 Try this: function onResourceStart() call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Online Time") for index, player in pairs (getElementsByType("player")) do setElementData (player, "joinTime", getTickCount() ) setElementData (player, "Online Time", "0 hours, 0 minutes, 0 seconds" ) end end addEventHandler("onResourceStart",resourceRoot,onResourceStart) function joinTime() setElementData (source, "joinTime", getTickCount() ) setElementData (source, "Online Time", "0 hours, 0 minutes, 0 seconds" ) end addEventHandler ( "onPlayerJoin", root, joinTime ) function all() for index , player in ipairs ( getElementsByType ( "player" ) ) do local s = getElementData(player,"joinTime") or getTickCount() s = (s - getTickCount()) / 1000 local string = string.format("%02d hours, %02d minutes, %02d seconds", s/3600, s%3600/60, s%60) setElementData(player,"Online Time",string) end end setTimer(all,1000,0) I think SDK missed a "d" in " %02d minutes" Link to comment
gokalpfirat Posted September 5, 2011 Author Share Posted September 5, 2011 It works now but it starts at 59 Minutes and 59 second and goes backward. Link to comment
SDK Posted September 5, 2011 Share Posted September 5, 2011 Don't pm me, you can just ask here. My logic failed on line 19: s = (getTickCount() - s) / 1000 Link to comment
gokalpfirat Posted September 5, 2011 Author Share Posted September 5, 2011 Works perfectly Thank You! 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