Tails Posted August 8, 2012 Share 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) Link to comment
Castillo Posted August 8, 2012 Share 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. Link to comment
Tails Posted August 8, 2012 Author Share 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! Link to comment
Castillo Posted August 8, 2012 Share 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. Link to comment
Tails Posted August 8, 2012 Author Share Posted August 8, 2012 Thank you very much. Why does it say source in ,1000, 0, source ? Link to comment
Castillo Posted August 8, 2012 Share Posted August 8, 2012 To pass the 'thePlayer' argument to the function executed by the timer. Link to comment
Jaysds1 Posted August 8, 2012 Share 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 ) Link to comment
Anderl Posted August 9, 2012 Share 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. 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