LiOneLMeSsIShoT Posted August 5, 2013 Posted August 5, 2013 I made this script to when the player write /relax...set ped animation and give him health +10 every 10 seconds...but i get ERRORS: Check it please..and tell me what the problem? function relax (theplayer, command) setPedAnimation (theplayer, "Lay_Bac_Loop") setTimer (health, 10000, 1) end addCommandHandler ("relax", relax) function health () setElementHealth ( localplayer, health +10) end Debugscript ERROR script.lua:11: attempt to perform arithmetic on global "health" (a function value) script.lua:3: Bad argument @ 'setPedAnimation"
OGF Posted August 5, 2013 Posted August 5, 2013 function relax (theplayer) setPedAnimation (theplayer, "Lay_Bac_Loop") hpTimer = setTimer ( function() if getElementHealth ( theplayer ) < 100 then setElementHealth ( theplayer, getElementHealth ( theplayer ) + 10 ) else killTimer ( hpTimer ) end end, 10000, 0 ) end addCommandHandler ("relax", relax) This is just for the health part, of course you should make sure the person is doing the animation
LiOneLMeSsIShoT Posted August 5, 2013 Author Posted August 5, 2013 function relax (theplayer) setPedAnimation (theplayer, "Lay_Bac_Loop") hpTimer = setTimer ( function() if getElementHealth ( theplayer ) < 100 then setElementHealth ( theplayer, getElementHealth ( theplayer ) + 10 ) else killTimer ( hpTimer ) end end, 10000, 0 ) end addCommandHandler ("relax", relax) This is just for the health part, of course you should make sure the person is doing the animation Debugscript ERROR: script.lua:9: unexpected symbol near ',' end, 10000, 0 ) also here..i dont understand why it's end, 1000, 0 ?
OGF Posted August 5, 2013 Posted August 5, 2013 try to copy my script again and try it. I just nested a function within the timer one, also the 10000, 0 are the next 2 required arguments for setTimer which as you probably know are interval and times to execute the function.
Bssol Posted August 5, 2013 Posted August 5, 2013 (edited) -- Server Side function relax (theplayer) if not ( isPedDead(theplayer) ) then -- checking wheather the player is dead or not setPedAnimation (theplayer, "BEACH", "Lay_Bac_Loop") -- you missed to put the 'block' setTimer (health, 10000, 1, theplayer) -- making the player first argument of 'health' fun end end addCommandHandler ("relax", relax) function health (theplayer) if ( isElement(theplayer) ) then -- make sure the player didn't quit local theHealth = getElementHealth ( theplayer ) setElementHealth ( theplayer, theHealth +10 ) end end Edited August 5, 2013 by Guest
LiOneLMeSsIShoT Posted August 5, 2013 Author Posted August 5, 2013 -- Server Side function relax (theplayer) if not ( isPedDead(theplayer) ) then -- checking wheather the player is dead or not setPedAnimation (theplayer, "BEACH", "Lay_Bac_Loop") -- you missed to put the 'block' setTimer (health, 10000, 1, theplayer) -- making the player first argument of 'health' fun end end addCommandHandler ("relax", relax) function health (theplayer) if ( isElement(theplayer) ) then -- make sure the player didn't quit local theHealth = getElementHealth ( localplayer ) setElementHealth ( localplayer, theHealth +10 ) end end Gonna test it and thanks
LiOneLMeSsIShoT Posted August 5, 2013 Author Posted August 5, 2013 function relax (theplayer) setPedAnimation (theplayer, "Lay_Bac_Loop") hpTimer = setTimer ( function() if getElementHealth ( theplayer ) < 100 then setElementHealth ( theplayer, getElementHealth ( theplayer ) + 10 ) else killTimer ( hpTimer ) end end, 10000, 0 ) end addCommandHandler ("relax", relax) This is just for the health part, of course you should make sure the person is doing the animation ERRORS script.lua:2: Bad argument @ 'setPedAnimation' script.lua:4: bad argument @ 'getElementHealth' script.lua:4: attempt to compare boolean with number
LiOneLMeSsIShoT Posted August 5, 2013 Author Posted August 5, 2013 You're not using this clientsided are you? Nope i don't
LiOneLMeSsIShoT Posted August 5, 2013 Author Posted August 5, 2013 Copy my code again, there were some errors. True..gonna test it now
LiOneLMeSsIShoT Posted August 5, 2013 Author Posted August 5, 2013 Copy my code again, there were some errors. True..gonna test it now ERROR: script.lua:2: attempt to call global 'isPedDead' (a nil value) also i want the player stop the anim and giving health when he click "Space" and when his health reach to 100..then stop giving health to him...and if his current health 200...then stop giving health to him when his health reach to 200...AND THANK YOU A LOT
OGF Posted August 5, 2013 Posted August 5, 2013 @ bssol pls learn the difference between client and server you also liOneLMeSsIshoT. isPedDead is a server only function.... so you are running this script clientside
LiOneLMeSsIShoT Posted August 5, 2013 Author Posted August 5, 2013 @ bssol pls learn the difference between client and server you also liOneLMeSsIshoT.isPedDead is a server only function.... so you are running this script clientside Saw in Meta client side!! Shit...mistake. Gonna try the script again
LiOneLMeSsIShoT Posted August 5, 2013 Author Posted August 5, 2013 -- Server Side function relax (theplayer) if not ( isPedDead(theplayer) ) then -- checking wheather the player is dead or not setPedAnimation (theplayer, "BEACH", "Lay_Bac_Loop") -- you missed to put the 'block' setTimer (health, 10000, 1, theplayer) -- making the player first argument of 'health' fun end end addCommandHandler ("relax", relax) function health (theplayer) if ( isElement(theplayer) ) then -- make sure the player didn't quit local theHealth = getElementHealth ( theplayer ) setElementHealth ( theplayer, theHealth +10 ) end end Working good .....but i want the player stop the anim and giving health when he click "Space" and when his health reach to 100..then stop giving health to him...and if his current health 200...then stop giving health to him when his health reach to 200...AND THANK YOU A LOT if you can and Thank you a lot
LiOneLMeSsIShoT Posted August 5, 2013 Author Posted August 5, 2013 @ bssol pls learn the difference between client and server you also liOneLMeSsIshoT.isPedDead is a server only function.... so you are running this script clientside Saw in Meta client side!! :~...mistake. Gonna try the script again Thank you too man
OGF Posted August 5, 2013 Posted August 5, 2013 function relax() setPedAnimation (localPlayer, "BEACH", "Lay_Bac_Loop") if isTimer ( hpTimer ) then return end hpTimer = setTimer ( function() if getElementHealth ( localPlayer ) < 200 then setElementHealth ( localPlayer, getElementHealth ( localPlayer ) + 10 ) else killTimer ( hpTimer ) end end, 10000, 0 ) end addCommandHandler ("relax", relax) Try this. as for the animation i'll leave that to you.
LiOneLMeSsIShoT Posted August 5, 2013 Author Posted August 5, 2013 function relax() setPedAnimation (localPlayer, "BEACH", "Lay_Bac_Loop") if isTimer ( hpTimer ) then return end hpTimer = setTimer ( function() if getElementHealth ( localPlayer ) < 200 then setElementHealth ( localPlayer, getElementHealth ( localPlayer ) + 10 ) else killTimer ( hpTimer ) end end, 10000, 0 ) end addCommandHandler ("relax", relax) Try this. as for the animation i'll leave that to you. got Errors... hate to write too much so bad argument 'setPedAnimation setElemntHealth expected argument got 1 nil and anothe SPAM SPAM errors cant write them
OGF Posted August 5, 2013 Posted August 5, 2013 That one is for the client. and I know it's working fine.
LiOneLMeSsIShoT Posted August 5, 2013 Author Posted August 5, 2013 That one is for the client. and I know it's working fine. okay...what function to stop the anim?
OGF Posted August 5, 2013 Posted August 5, 2013 setPedAnimation(localPlayer,false) Just remember localPlayer = getLocalPlayer() ---this function is only used when you are scripting on the client side.
Bssol Posted August 5, 2013 Posted August 5, 2013 -- Server Side local timersT = {} function relax (theplayer) if not ( isPedDead(theplayer) ) and not ( isTimer(timersT[theplayer]) ) then -- checking wheather the player is die or not setPedAnimation (theplayer, "BEACH", "Lay_Bac_Loop") -- you missed to put the 'block' timersT[theplayer] = setTimer (health, 10000, 0, theplayer) -- making the player first argument of 'health' fun bindKey ( theplayer, "space", "down", endHealing ) end end addCommandHandler ("relax", relax) function health (theplayer) if ( isElement(theplayer) ) then -- make sure the player didn't quit local is200health = false if ( getPedStat(theplayer,24) > 990 ) then is200health = true end local newHealth = getElementHealth ( theplayer ) + 10 if ( is200health ) then if ( newHealth >= 200 ) then setElementHealth ( theplayer, 200 ) return endHealing(theplayer) end else if ( newHealth >= 100 ) then setElementHealth ( theplayer, 100 ) return endHealing(theplayer) end end setElementHealth ( theplayer, newHealth ) else killTimer(timersT[theplayer]) timersT[theplayer] = nil end end function endHealing(theplayer) setPedAnimation(theplayer) killTimer(timersT[theplayer]) timersT[theplayer] = nil unbindKey ( theplayer, "space", "down", endHealing ) end function onPlayerQuit ( ) if ( isTimer(timersT[source]) ) then killTimer(timersT[source]) timersT[source] = nil end end addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) function onPlayerWasted ( ) if ( isTimer(timersT[source]) ) then endHealing(source) end end addEventHandler( "onPlayerWasted", root, onPlayerWasted )
LiOneLMeSsIShoT Posted August 5, 2013 Author Posted August 5, 2013 -- Server Side local timersT = {} function relax (theplayer) if not ( isPedDead(theplayer) ) and not ( isTimer(timersT[theplayer]) ) then -- checking wheather the player is die or not setPedAnimation (theplayer, "BEACH", "Lay_Bac_Loop") -- you missed to put the 'block' timersT[theplayer] = setTimer (health, 10000, 0, theplayer) -- making the player first argument of 'health' fun bindKey ( theplayer, "space", "down", endHealing ) end end addCommandHandler ("relax", relax) function health (theplayer) if ( isElement(theplayer) ) then -- make sure the player didn't quit local is200health = false if ( getPedStat(theplayer,24) > 990 ) then is200health = true end local newHealth = getElementHealth ( theplayer ) + 10 if ( is200health ) then if ( newHealth >= 200 ) then setElementHealth ( theplayer, 200 ) return endHealing(theplayer) end else if ( newHealth >= 100 ) then setElementHealth ( theplayer, 100 ) return endHealing(theplayer) end end setElementHealth ( theplayer, newHealth ) else killTimer(timersT[theplayer]) timersT[theplayer] = nil end end function endHealing(theplayer) setPedAnimation(theplayer) killTimer(timersT[theplayer]) timersT[theplayer] = nil unbindKey ( theplayer, "space", "down", endHealing ) end function onPlayerQuit ( ) if ( isTimer(timersT[source]) ) then killTimer(timersT[source]) timersT[source] = nil end end addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) function onPlayerWasted ( ) if ( isTimer(timersT[source]) ) then endHealing(source) end end addEventHandler( "onPlayerWasted", root, onPlayerWasted ) THank you a lot! But may you make it...like...if the player stat in health 100 then don't give him more health when he reach to this health...and the same with 200...300..400..500 to 1000 ...if you understand what i mean..then Please try to do it for me . And Thank you
Bssol Posted August 5, 2013 Posted August 5, 2013 I made it as you wanted, It stopped at 100 if the player's max health is 100, and the same with 200. OGF, I know that and i'm sorry lol
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