Xabache Posted February 7, 2015 Share Posted February 7, 2015 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
ikAkA07 Posted February 7, 2015 Share Posted February 7, 2015 hmm, i think you mean like this : ped = createPed(0, x, y, z) addEventHandler("onClientPedDamage", ped, function ( attacker ) if ( getElementType(attacker) == "player" ) then cancelEvent() end end ) Link to comment
Xabache Posted February 7, 2015 Author Share Posted February 7, 2015 Pardon me i did mean "how do i make my PLAYER 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
ikAkA07 Posted February 8, 2015 Share Posted February 8, 2015 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
TAPL Posted February 8, 2015 Share Posted February 8, 2015 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now