Jump to content

Script Error


Recommended Posts

Posted

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" 

Posted
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

Posted
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 ?

Posted

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.

Posted (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 by Guest
Posted
-- 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

Posted
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 o.O

script.lua:2: Bad argument @ 'setPedAnimation' 

script.lua:4: bad argument @ 'getElementHealth' 

script.lua:4: attempt to compare boolean with number 

Posted

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

Posted

@ 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

Posted
@ 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

xD Saw in Meta client side!! Shit...mistake. xD Gonna try the script again

Posted
-- 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

Posted
@ 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

xD Saw in Meta client side!! :~...mistake. xD Gonna try the script again

Thank you too man :)

Posted
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.

Posted
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

Posted
setPedAnimation(localPlayer,false) 

Just remember localPlayer = getLocalPlayer() ---this function is only used when you are scripting on the client side.

Posted

-- 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 ) 

Posted
-- 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

Posted

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...