Jump to content

Get +2 hp when kill zombies


Adde

Recommended Posts

Hello, I want to create a script that set the players hp +2 everytime he/she kills a zombie. I have done something like this but it wont work. I don´t know if there is a "onClientPedWasted". Or should I set add health to server side and use triggerServerEvent?

client

function Zombie(attacker, weapon, bodypart, loss) 
if (getElementData(source, "zombie") == true) then 
 if ( attacker == player ) then 
    if (getElementHealth(attacker) < 100) then 
        local Heal = getElementHealth(attacker) + 50 
               killPed(source, attacker, weapon, bodypart) 
        end 
    end 
end 
addEventHandler("onClientPedWasted", getRootElement(), Zombie) 

Link to comment

Did you get it to work?

I just wrote this up a bit fast, I've never worked with Peds before so it might or might not work :P Also I got rid of the killPed part since the event is triggered when the ped is killed, I don't see a reason to kill what's already been killed :P

function onClientKillZombie(killer, weapon, bodypart) 
    if (getElementData(source, "zombie") == true) then 
        if(getElementType(killer) == "player") then 
            if(getElementHealth(killer) < 100) then 
                setElementHealth(killer, getElementHealth(killer)+2) 
            end 
        end 
    end 
end 
addEventHandler("onClientPedWasted", getRootElement(), onClientKillZombie) 

Link to comment
Did you get it to work?

I just wrote this up a bit fast, I've never worked with Peds before so it might or might not work :P Also I got rid of the killPed part since the event is triggered when the ped is killed, I don't see a reason to kill what's already been killed :P

function onClientKillZombie(killer, weapon, bodypart) 
    if (getElementData(source, "zombie") == true) then 
        if(getElementType(killer) == "player") then 
            if(getElementHealth(killer) < 100) then 
                setElementHealth(killer, getElementHealth(killer)+2) 
            end 
        end 
    end 
end 
addEventHandler("onClientPedWasted", getRootElement(), onClientKillZombie) 

Yea, that works. I did almost the same. But I forgot [ If getElementType(killer) == "player") == true) then ]

The reason why I may had some things that not was needed is bcs I copied my zombieheadshot script and replaced playsound with setElementHealth. I didn´t think of delete the "killPed".

But thx :)

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