gokalpfirat Posted September 5, 2011 Posted September 5, 2011 (edited) edit. Edited September 5, 2011 by Guest
JR10 Posted September 5, 2011 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 Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
gokalpfirat Posted September 5, 2011 Author 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)
SDK Posted September 5, 2011 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) Learn Lua - Learn to script - GUI scripting Scripter tools - Find/fix errors yourself(!) Don't pm me for scripting help, keep it for the Scripting subforum!
gokalpfirat Posted September 5, 2011 Author Posted September 5, 2011 I get error at line 16(SDK) Error is: invalid option '%' to 'format'
Castillo Posted September 5, 2011 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? San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
gokalpfirat Posted September 5, 2011 Author Posted September 5, 2011 I try but i cant thats because i write this topic.
Castillo Posted September 5, 2011 Posted September 5, 2011 Yes, but the way you ask for help is not right, you are like telling us to FIX it San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
gokalpfirat Posted September 5, 2011 Author Posted September 5, 2011 No i say please fix it sorry for my old "fix it" posts
Castillo Posted September 5, 2011 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" San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
gokalpfirat Posted September 5, 2011 Author Posted September 5, 2011 It works now but it starts at 59 Minutes and 59 second and goes backward.
SDK Posted September 5, 2011 Posted September 5, 2011 Don't pm me, you can just ask here. My logic failed on line 19: s = (getTickCount() - s) / 1000 Learn Lua - Learn to script - GUI scripting Scripter tools - Find/fix errors yourself(!) Don't pm me for scripting help, keep it for the Scripting subforum!
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