rublisk19 Posted January 1, 2012 Share 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!! Link to comment
TAPL Posted January 1, 2012 Share Posted January 1, 2012 client-side function expcalculate () setElementData(localPlayer, "EXP",tonumber(getElementData(localPlayer, "EXP"))+1) end setTimer(expcalculate, 20000,0) Link to comment
FatalTerror Posted January 1, 2012 Share 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 Link to comment
TAPL Posted January 1, 2012 Share 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 Link to comment
rublisk19 Posted January 1, 2012 Author Share 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 ;] Link to comment
TAPL Posted January 1, 2012 Share 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 Link to comment
FatalTerror Posted January 1, 2012 Share 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) Link to comment
rublisk19 Posted January 1, 2012 Author Share Posted January 1, 2012 TAPL your script doesn't work ;[ and fatal i get error then i reconnect Link to comment
Castillo Posted January 1, 2012 Share 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 Link to comment
rublisk19 Posted January 1, 2012 Author Share Posted January 1, 2012 Script Error then i reconnect ;[ error : bad argument [getElementData] expected element at argument 1 Link to comment
Castillo Posted January 1, 2012 Share 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) Link to comment
rublisk19 Posted January 1, 2012 Author Share 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: 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