Jump to content

Get +2 hp when kill zombies


Adde

Recommended Posts

Posted

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) 

My ingame nickname is: Mr.Snus

Posted

There is, onClientPedWasted. Whenever in doubt, always refer to the MTA Wiki since it for the most part has very thorough examples and explanations of how every(most) functions and events work.

Also, you'll need to use setElementHealth, not getElementHealth.

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted

Yes i know but i couldn´t find onClientPedWasted on wiki.

Wtf, I din´t notice that :o

My ingame nickname is: Mr.Snus

Posted

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) 

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

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

My ingame nickname is: Mr.Snus

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