Jump to content

OnClientPlayerDamage cause...?


Xabache

Recommended Posts

This event handler protects the player from all damage except sudden death

addEventHandler ( "onClientPlayerDamage", localPlayer, 
    function ( _, _, _, loss ) 
        local playerHealth = getElementHealth ( getLocalPlayer() ) 
        outputChatBox ( "Your health: " .. playerHealth) 
        outputChatBox ( "Your health: " .. loss) 
        if ( playerHealth and playerHealth > 0 ) then 
            cancelEvent ( ) 
        end 
    end 
) 

This event handler protects vehicles from all damage except punching, and allows real world damage such as accidents.

addEventHandler ( "onClientVehicleDamage", root, 
    function ( _, _, loss ) 
        local vehicleHealth = getElementHealth ( source ) 
        outputChatBox ( "Your health: " .. vehicleHealth) 
        outputChatBox ( "Your health: " .. loss) 
        if ( vehicleHealth and vehicleHealth > 0 ) then 
            cancelEvent ( ) 
        end 
    end 
) 

What is the difference that gives two nearly identical bits of code different capabilities? Or to my point, how do i make my ped suffer real world damage such as falling accidents or zombie attacks while remaining effectively invulnerable to damage caused by other players such as shooting or punching?

Link to comment

What is the difference that gives two nearly identical bits of code different capabilities? Or to my point, how do i make my ped suffer real world damage such as falling accidents or zombie attacks while remaining effectively invulnerable to damage caused by other players such as shooting or punching?

Anyway, try this :

addEventHandler("onClientPlayerDamage", getLocalPlayer(), 
 function ( attacker ) 
    if ( getElementType( attacker ) == "player" ) then 
    cancelEvent() 
    end 
 end 
) 

Link to comment
addEventHandler("onClientPlayerDamage", localPlayer, 
function(attacker) 
    if attacker and attacker ~= source and getElementType(attacker) == "player" then 
        cancelEvent() 
    end 
end) 

And there's no way to prevent punching other than setting all players in one team and disable friendly fire with setTeamFriendlyFire.

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