Jump to content

onVehicleDamage and onPlayerDamage


Dzsozi (h03)

Recommended Posts

Posted

Hello community! I want to make script which is removes health if you crash with your vehicle and I don't want to use setElementHealth, I want to define it as a PlayerDamage and use onPlayerDamage event, because I have other scripts which are works with onPlayerDamage, and if I use setElementHealth they wont work. So how can I define something as a player damage? I've tried this, but I have headshot resource running and if I crash a little bit I die immediately, but if I define bodypart for example as torso (number 3) the crash script is not working. Debugscript doesn't show me errors, but I can't fix it. I would be happy if someone could help me!

  
function lossHealthOnHurt(loss) 
    if getVehicleOccupant(source) then 
        player = getVehicleOccupant(source) 
        health = getElementHealth(player) 
        if loss >= 50 and loss < 349 then 
            --setElementHealth(player, health - loss/10) 
            triggerEvent("onPlayerDamage", player, nil, nil, 9, loss/10) 
        elseif loss >= 350 then 
            killPed(player) 
        end 
    end 
end 
addEventHandler("onVehicleDamage", getRootElement(), lossHealthOnHurt) 
  

Thanks in advance!

Your signature image is too large.

Removed

Posted

test this :

function lossHealthOnHurt ( loss  ) 
    if ( getVehicleController ( source ) ) then 
        local player = getVehicleController ( source ) 
        local health = getElementHealth ( player ) 
        if ( loss >= 50 and loss < 349 ) then 
            setElementHealth ( player, health - loss/10 ) 
        elseif ( loss >= 350 ) then 
             killPed ( player ) 
        end 
    end 
end 
addEventHandler( "onVehicleDamage", getRootElement (  ), lossHealthOnHurt ) 

To Contact Me at Skype : [email protected]

Posted
I don't want to use setElementHealth, I want to define it as a PlayerDamage and use onPlayerDamage event, because I have other scripts which are works with onPlayerDamage, and if I use setElementHealth they wont work.

Your signature image is too large.

Removed

Posted

If it's so important to use onPlayerDamage then do this:

setElementHealth ( player, health - loss/10 ) 
triggerEvent("onPlayerDamage", player, nil, nil, 9, loss/10) 

No other way on serverside, write it on clientside then, onClientVehicleDamage. This or rewrite all your damage scripts to be compatible with your new scripts.

Powered by Kimsufi©

n-560x95_FFFFFF_FFFFFF_000000_000000.png

ZHP on FacebookZHP on YoutubeSupport us

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