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) Discord: its.tails
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. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
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! Discord: its.tails
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. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Tails Posted August 8, 2012 Author Posted August 8, 2012 Thank you very much. Why does it say source in ,1000, 0, source ? Discord: its.tails
Castillo Posted August 8, 2012 Posted August 8, 2012 To pass the 'thePlayer' argument to the function executed by the timer. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
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 ) My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
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. "[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007
Jaysds1 Posted August 9, 2012 Posted August 9, 2012 well, it works for me My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
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