Jump to content

[HELP] script


1LoL1

Recommended Posts

Hello, please how i can when zombies attacking me so first will armour down and next health. Now its when i have armour and health 100% and zombies attacked me so zombies taked me only health.

function zombieattack ( attacker, weapon, bodypart ) 
    if (attacker) then 
        if getElementType ( attacker ) == "ped" then 
            if (getElementData (attacker, "zombie") == true) then 
                local playerHealth = getElementHealth ( getLocalPlayer() ) 
                if playerHealth > 15 then 
                    setElementHealth ( source, playerHealth - 15 ) 
                else 
                    triggerServerEvent ("playereaten", source, source, attacker, weapon, bodypart ) 
                end 
            end 
        end 
    end 
end 
addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), zombieattack ) 

Link to comment

Try this:

    function zombieattack ( attacker, weapon, bodypart, loss ) 
        if (attacker) then 
            if getElementType ( attacker ) == "ped" then 
                if (getElementData (attacker, "zombie") == true) then 
                    local playerHealth = getElementHealth ( getLocalPlayer() ) 
                    local playerArmor = getPedArmor ( getLocalPlayer() ) 
                    if playerArmor > 0 then 
            setPedArmor ( source, playerArmor - loss ) 
            elseif playerArmor == 0 then 
            setElementHealth ( source, playerHealth - loss ) 
                    elseif playerHealth > 15 then 
                        setElementHealth ( source, playerHealth - 15 ) 
                    else 
                        triggerServerEvent ("playereaten", source, source, attacker, weapon, bodypart ) 
                    end 
                end 
            end 
          end 
end 
    addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), zombieattack ) 

Edited by Guest
Link to comment
Sorry for the first one the Submit button activated accidentally :v

ah ok :D but i have here error and you forgot to local loss = 15

attempt to call global "setPedArmor" (a nil value)

function zombieattack ( attacker, weapon, bodypart, loss ) 
        if (attacker) then 
            if getElementType ( attacker ) == "ped" then 
                if (getElementData (attacker, "zombie") == true) then 
                    local playerHealth = getElementHealth ( getLocalPlayer() ) 
                    local playerArmor = getPedArmor ( getLocalPlayer() ) 
                    if playerArmor > 0 then 
                    local loss = 15 
            setPedArmor ( source, playerArmor - loss ) 
            elseif playerArmor == 0 then 
            local loss = 15 
            setElementHealth ( source, playerHealth - loss ) 
                    elseif playerHealth > 15 then 
                        setElementHealth ( source, playerHealth - 15 ) 
                    else 
                        triggerServerEvent ("playereaten", source, source, attacker, weapon, bodypart ) 
                    end 
                end 
            end 
          end 
end 
    addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), zombieattack ) 

Link to comment
Sorry for the first one the Submit button activated accidentally :v

ah ok :D but i have here error and you forgot to local loss = 15

attempt to call global "setPedArmor" (a nil value)

function zombieattack ( attacker, weapon, bodypart, loss ) 
        if (attacker) then 
            if getElementType ( attacker ) == "ped" then 
                if (getElementData (attacker, "zombie") == true) then 
                    local playerHealth = getElementHealth ( getLocalPlayer() ) 
                    local playerArmor = getPedArmor ( getLocalPlayer() ) 
                    if playerArmor > 0 then 
                    local loss = 15 
            setPedArmor ( source, playerArmor - loss ) 
            elseif playerArmor == 0 then 
            local loss = 15 
            setElementHealth ( source, playerHealth - loss ) 
                    elseif playerHealth > 15 then 
                        setElementHealth ( source, playerHealth - 15 ) 
                    else 
                        triggerServerEvent ("playereaten", source, source, attacker, weapon, bodypart ) 
                    end 
                end 
            end 
          end 
end 
    addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), zombieattack ) 

Because setPedArmor is server side

So just trigger it

Link to comment

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