Jump to content

Player demage


Xwad

Recommended Posts

Posted

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) 
  

Posted

Try this

addEventHandler("onClientPedDamage",root, 
function () 
        if ( getElementModel(source) == 165) then 
        cancelEvent() 
    end 
end) 

Posted

its not working:/ But i dont want to cancel the event i just want to set that the explosion will make 5 hp demage on skin id 165

Posted

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) 

  • Moderators
Posted

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" 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

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) 
  

  • Moderators
Posted

Add(new stuff), replace(that look a like) and remove.(strike)

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

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 ) 
  

  • Moderators
Posted (edited)

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

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

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.

  • Moderators
Posted

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) 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

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 
  

  • Moderators
Posted

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 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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