Tails Posted August 8, 2012 Posted August 8, 2012 Hi, I'm trying to create a script that lets the players health gradually drop by -1, kind of as if they were starving. I have no idea how to learn this because the wiki doesn't explain me this. function Starve(thePlayer) setTimer(function() SetElementHealth( thePlayer, getElementHealth(thePlayer) - 2 ), 1000, 0) end end addEventHandler("onResourceStart", Starve)
Castillo Posted August 8, 2012 Posted August 8, 2012 1: You got missing argument 2 at addEventHandler. 2: "onResourceStart" has no player argument. 3: Lua is case-sensetive, so is not SetElementHealth, but setElementHealth.
Tails Posted August 8, 2012 Author Posted August 8, 2012 Ty Solidsnake14. Do I need to put type="client" in the meta file, server or none? function Starve(thePlayer) setTimer( function() setElementHealth( thePlayer, getElementHealth(thePlayer) - 2 ) , 1000, 0) end end addEventHandler("onPlayerSpawn", getRootElement(), Starve) Right now it's saying unexpected symbol near "," when debugging. Can you also explain me a little bit as to why I need to put a 2nd argument in the eventHandler while on other scripts I don't? And what exactly means rootElement and what is the different between root and getRootElement? Thanks in advance! It is much appreciated!
Castillo Posted August 8, 2012 Posted August 8, 2012 function Starve ( ) setTimer ( function ( thePlayer ) if ( thePlayer and isElement ( thePlayer ) ) then setElementHealth ( thePlayer, getElementHealth ( thePlayer ) - 2 ) end end ,1000, 0, source ) end addEventHandler ( "onPlayerSpawn", getRootElement(), Starve ) Is a server side script.
Tails Posted August 8, 2012 Author Posted August 8, 2012 Thank you very much. Why does it say source in ,1000, 0, source ?
Castillo Posted August 8, 2012 Posted August 8, 2012 To pass the 'thePlayer' argument to the function executed by the timer.
Jaysds1 Posted August 8, 2012 Posted August 8, 2012 To pass the 'thePlayer' argument to the function executed by the timer. but if the timer has it's own function: setTimer(function()end,ms,exec) then you don't really have to pass the argument through. example: function Starve ( ) setTimer(function() if ( source and isElement ( source ) ) then setElementHealth ( source, getElementHealth ( source ) - 2 ) end end,1000, 0) end addEventHandler ( "onPlayerSpawn", getRootElement(), Starve )
Anderl Posted August 9, 2012 Posted August 9, 2012 To pass the 'thePlayer' argument to the function executed by the timer. but if the timer has it's own function: setTimer(function()end,ms,exec) then you don't really have to pass the argument through. example: function Starve ( ) setTimer(function() if ( source and isElement ( source ) ) then setElementHealth ( source, getElementHealth ( source ) - 2 ) end end,1000, 0) end addEventHandler ( "onPlayerSpawn", getRootElement(), Starve ) You need, it's a separated function.
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