Jump to content

Player demage


Xwad

Recommended Posts

Hi i hahave made a script that changes the explosion demage on the skin 165 but its not working:/ pls help.

  
function noob(attacker, weapon, loss, x, y, z, tyre) 
    if (weapon == 51 and getElementModel(source) == 165) then 
        setElementHealth(source,getElementHealth(source) - 5) 
        cancelEvent() 
    end 
end 
addEventHandler("onClientPlayerDamage", root, noob) 
  

Link to comment

Ah, my bad i understood you by wrong, try this i think thats what you need

Do it ,at the client side because the event "onClientPlayerDamage" is client sided !

  
addEventHandler("onClientPlayerDamage", root, 
function (attacker, weapon, loss) 
    if ( isElement ( attacker ) and weapon and attacker== localPlayer and getElementModel(source) == 165) then 
    if (weapon == 51 and getElementModel(source) == 165) then 
        cancelEvent() 
        setElementHealth(source,getElementHealth(source) - 5) 
        end 
    end 
end) 

Link to comment
  • Moderators

You have to add the health loss, before you set the new health.

local newHealth = getElementHealth(source) + loss - 5 
if newHealth > 0 then 
setElementHealth(source,newHealth ) 
else 
setElementHealth(source,0) 
end 
  

And not to forget, put the handler on the localPlayer.

addEventHandler("onClientPlayerDamage", localPlayer, 

You can't set the health of a remote player with success, only the localPlayer as source can give correct result.

and attacker== localPlayer 

The attacker can also be a vehicle.

getElementType(attacker) == "player" 

Link to comment

KariiiM i testet it but it still not works. IIYAMA you mean add to that script?

  
addEventHandler("onClientPlayerDamage", root, 
function (attacker, weapon, loss) 
    if ( isElement ( attacker ) and weapon and attacker== localPlayer and getElementModel(source) == 165) then 
    if (weapon == 51 and getElementModel(source) == 165) then 
        cancelEvent() 
        setElementHealth(source,getElementHealth(source) - 5) 
        end 
    end 
end) 
  

Link to comment

is it now good?xD

  
local newHealth = getElementHealth(source) + loss - 5 
  
function setHP(attacker, weapon, loss) 
if getElementType(attacker) == "player" 
if (weapon == 51 and getElementModel(source) == 165) then 
if newHealth > 0 then 
setElementHealth(source,newHealth ) 
else 
setElementHealth(source,0) 
end 
end 
end 
  
  
addEventHandler("onClientPlayerDamage", localPlayer, setHP ) 
  

Link to comment
  • Moderators

no, you missed placed it.

Try this: (not tested)

addEventHandler("onClientPlayerDamage", localPlayer,  
function (attacker, weapon, loss) 
    -- source is the player that got damaged. 
    if isElement ( attacker ) and weapon == 51 and getElementType(attacker) == "player" and getElementModel(source) == 165 then 
        local oldHealth = getElementHealth(source) 
        local newHealth = oldHealth + loss - 5 
        if newHealth > 0 then 
            setElementHealth(source,newHealth ) 
            cancelEvent() 
        elseif oldHealth > 0 then 
            setElementHealth(source,0) 
        end 
    end 
end) 

Make sure you are wearing skin 165, when somebody attacks you.

Edited by Guest
Link to comment

its working but there are sopme bugs. I changed the 51 id to 30 (ak47) and shooted the id 165 skin player with the gun. It was working but if i shoted the legs or the head then the player was healed not demaged pls help:/ Maybe need i define bodyparts?

its only damaging on the torso.

Link to comment
  • Moderators

Yea, you should have. You can't just leave an argument open. Last time it was using the bodypart as loss.

addEventHandler("onClientPlayerDamage", localPlayer,  
function (attacker, weapon,bodypart, loss) 
    -- source is the player that got damaged. 
    if isElement ( attacker ) and weapon == 51 and getElementType(attacker) == "player" and getElementModel(source) == 165 then 
        local oldHealth = getElementHealth(source) 
        local newHealth = oldHealth + loss - 5 
        if newHealth > 0 then 
            setElementHealth(source,newHealth ) 
            cancelEvent() 
        elseif oldHealth > 0 then 
            setElementHealth(source,0) 
        end 
    end 
end) 

Link to comment

Last question. why is it not working if add more weapons?

  
 if isElement ( attacker ) and weapon == 30 and weapon == 22 and weapon == 28 and weapon == 29 and getElementType(attacker) == "player" and getElementModel(source) == 165 then 
  

Link to comment
  • Moderators

because the variable "weapon" can contain only one number. And "and" mean AND and not OR.

Put it exactly like this:

if isElement ( attacker ) and  
    (weapon == 30 or weapon == 22 or weapon == 28 or weapon == 29)  
-- between (), because it have to be 1 result. 
    and getElementType(attacker) == "player" and getElementModel(source) == 165 then 

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