rublisk19 Posted January 1, 2012 Posted January 1, 2012 function expcalculate ( source, command ) setElementData(source, "EXP",tonumber(getElementData(source, "EXP"))+1) end setTimer(expcalculate, 20000,0) I get error : Bad argument @ 'getElementData' [Expected element ar argument 1, got nil] attempt to perform arithmetic on a nil value If you can pls fix this script to make working ;] . I need this to get exp every 20sec!!
TAPL Posted January 1, 2012 Posted January 1, 2012 client-side function expcalculate () setElementData(localPlayer, "EXP",tonumber(getElementData(localPlayer, "EXP"))+1) end setTimer(expcalculate, 20000,0)
FatalTerror Posted January 1, 2012 Posted January 1, 2012 Where is the element? source ? If you are in client side you can try function expcalculate () setElementData(getLocalPlayer(), "EXP",tonumber(getElementData(getLocalPlayer(), "EXP"))+1) end setTimer(expcalculate, 20000,0) And if you are in server side... You must have an player addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function() for i, player in ipairs(getElementsByType ( "player" )) do setTimer(expcalculate, 20000, 0, player) end end) function expcalculate(player) setElementData(player, "EXP",tonumber(getElementData(player, "EXP"))+1) end
TAPL Posted January 1, 2012 Posted January 1, 2012 addEventHandler("onResourceStart", resourceRoot, function() setTimer(expcalculate, 20000, 0) end) function expcalculate() for i, player in ipairs(getElementByType("players")) do setElementData(player, "EXP",tonumber(getElementData(player, "EXP"))+1) end end
rublisk19 Posted January 1, 2012 Author Posted January 1, 2012 addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function() for i, player in ipairs(getElementsByType ( "player" )) do setTimer(expcalculate, 20000, 0, player) end end) function expcalculate(player) setElementData(player, "EXP",tonumber(getElementData(player, "EXP"))+1) end Thanks Works good ;]
TAPL Posted January 1, 2012 Posted January 1, 2012 addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function() for i, player in ipairs(getElementsByType ( "player" )) do setTimer(expcalculate, 20000, 0, player) end end) function expcalculate(player) setElementData(player, "EXP",tonumber(getElementData(player, "EXP"))+1) end Thanks Works good ;] does it work good if you rejoin to the server? lol
FatalTerror Posted January 1, 2012 Posted January 1, 2012 addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function() for i, player in ipairs(getElementsByType ( "player" )) do setTimer(expcalculate, 20000, 0, player) end end) function expcalculate(player) setElementData(player, "EXP",tonumber(getElementData(player, "EXP"))+1) end Thanks Works good ;] does it work good if you rejoin to the server? lol Yea, i don't test x)
rublisk19 Posted January 1, 2012 Author Posted January 1, 2012 TAPL your script doesn't work ;[ and fatal i get error then i reconnect
Castillo Posted January 1, 2012 Posted January 1, 2012 (edited) local timers = {} addEventHandler("onResourceStart",resourceRoot, function() for i, player in ipairs(getElementsByType ( "player" )) do timers[player] = setTimer(expcalculate, 20000, 0, player) end end) addEventHandler("onPlayerJoin",root, function () timers[source] = setTimer(expcalculate, 20000, 0, source) end) addEventHandler("onPlayerQuit",root, function () if isTimer(timers[source]) then killTimer(timers[source]) end end) function expcalculate(player) if (not player and isTimer(timers[player])) then killTimer(timers[player]) timers[player] = nil end if (not getElementData(player, "EXP")) then setElementData(player, "EXP", 0) end setElementData(player, "EXP",tonumber(getElementData(player, "EXP"))+1) end Edited January 1, 2012 by Guest
rublisk19 Posted January 1, 2012 Author Posted January 1, 2012 Script Error then i reconnect ;[ error : bad argument [getElementData] expected element at argument 1
Castillo Posted January 1, 2012 Posted January 1, 2012 function expcalculate() for index, player in ipairs(getElementsByType("player")) do if (not getElementData(player, "EXP")) then setElementData(player, "EXP", 0) end setElementData(player, "EXP",tonumber(getElementData(player, "EXP"))+1) end end setTimer(expcalculate,20000,0)
rublisk19 Posted January 1, 2012 Author Posted January 1, 2012 function expcalculate() for index, player in ipairs(getElementsByType("player")) do if (not getElementData(player, "EXP")) then setElementData(player, "EXP", 0) end setElementData(player, "EXP",tonumber(getElementData(player, "EXP"))+1) end end setTimer(expcalculate,20000,0) Thanks man :kiss:
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