Jump to content

rocket explosion damage change


#nofear

Recommended Posts

how can i change the damage of rocket explosion?
when I tried it before, when I fired with a rocket, I was taking damage when any player took damage, I don't want this and I want their cars to take extra damage.

please help me 

Link to comment
local rocketDmg = 50

function changeRocketDmg(attacker, dmgType, bodypart, loss)
	if (dmgType == 39) then
		cancelEvent()
    local playerHealth = getElementHealth ( localPlayer ) - rocketDmg
    if playerHealth <= 0 then
      killPed(localPlayer, attacker)
      else
      setElementHealth(localPlayer, playerHealth)
      end
	end
end
addEventHandler("onClientPlayerDamage", localPlayer, changeRocketDmg)

Hello you can try this, i did this quickly on my phone so i didnt test it and there is maybe mistakes but the general idea should work i think.

The problem with this method is that the rocket dmg is a set value when in reality you should take less dmg if you are far from the explosion or a lot of dmg if you stand right into it.

You could do a percentage instead, you keep the first part of the code but then reduce loss value by 50% or something like that.

local rocketDmgModifier = 0.5 -- from 0 to 1, 0 for 0% of the dmg and 1 for 100% of the dmg
function changeRocketDmg(attacker, dmgType, bodypart, loss)
	if (dmgType == 39) then
		cancelEvent()
    local playerHealth = getElementHealth ( localPlayer ) - ( loss * rocketDmgModifier )
    if playerHealth <= 0 then
      killPed(localPlayer, attacker)
      else
      setElementHealth(localPlayer, playerHealth)
      end
	end
end
addEventHandler("onClientPlayerDamage", localPlayer, changeRocketDmg)

An other version with percentage rather than a set value. Again i didnt test it

Edited by Spakye
Link to comment
--you can manipulate the vehicle health
addEventHandler("onClientVehicleDamage", root,
    function(attacker, weapon, loss)
        if attacker == localPlayer and weapon == 36 then
            local currentHealth = getElementHealth(source)
            setElementHealth(source, currentHealth - loss*2) -- doubling the damage
        end
    end
)

you can’t directly change the dmg the damage values are usually hard coded in the game itself but you can try what I’ve posted above

Link to comment
21 hours ago, FLUSHBICEPS said:
--you can manipulate the vehicle health
addEventHandler("onClientVehicleDamage", root,
    function(attacker, weapon, loss)
        if attacker == localPlayer and weapon == 36 then
            local currentHealth = getElementHealth(source)
            setElementHealth(source, currentHealth - loss*2) -- doubling the damage
        end
    end
)

you can’t directly change the dmg the damage values are usually hard coded in the game itself but you can try what I’ve posted above

I tried but it didn't work :(

On 22/05/2023 at 13:47, Spakye said:
local rocketDmg = 50

function changeRocketDmg(attacker, dmgType, bodypart, loss)
	if (dmgType == 39) then
		cancelEvent()
    local playerHealth = getElementHealth ( localPlayer ) - rocketDmg
    if playerHealth <= 0 then
      killPed(localPlayer, attacker)
      else
      setElementHealth(localPlayer, playerHealth)
      end
	end
end
addEventHandler("onClientPlayerDamage", localPlayer, changeRocketDmg)

Hello you can try this, i did this quickly on my phone so i didnt test it and there is maybe mistakes but the general idea should work i think.

The problem with this method is that the rocket dmg is a set value when in reality you should take less dmg if you are far from the explosion or a lot of dmg if you stand right into it.

You could do a percentage instead, you keep the first part of the code but then reduce loss value by 50% or something like that.

local rocketDmgModifier = 0.5 -- from 0 to 1, 0 for 0% of the dmg and 1 for 100% of the dmg
function changeRocketDmg(attacker, dmgType, bodypart, loss)
	if (dmgType == 39) then
		cancelEvent()
    local playerHealth = getElementHealth ( localPlayer ) - ( loss * rocketDmgModifier )
    if playerHealth <= 0 then
      killPed(localPlayer, attacker)
      else
      setElementHealth(localPlayer, playerHealth)
      end
	end
end
addEventHandler("onClientPlayerDamage", localPlayer, changeRocketDmg)

An other version with percentage rather than a set value. Again i didnt test it

When you set the damage type to 19 it works for peds but not for vehicles :(

function changeRocketDmgCar(attacker, dmgType, bodypart, loss, x, y, z, tire)
	if (dmgType == 19) then
		cancelEvent()
            local currentHealth = getElementHealth(source)
            if currentHealth <= 0 then
            blowVehicle(root, currentHealth)
            else
            setElementHealth(source, currentHealth - loss*2) -- doubling the damage
        end
    end
)
addEventHandler("onClientVehicleDamage", root, changeRocketDmgCar)
----------------------------------------------------------------------------------------------
addEventHandler("onClientVehicleDamage", root,
    function(attacker, dmgType, bodypart, loss, x, y, z, tire)
        if (dmgType == 19) then
		cancelEvent()
            local currentHealth = getElementHealth(source)
            setElementHealth(source, currentHealth - loss*2) -- doubling the damage
        end
    end
)

I have tried such things, but I am not very experienced and cannot reach the result.

Link to comment

Cause the vehicle damage event parameters are different

addEventHandler("onClientVehicleDamage", root,
    function(theAttacker, dmgType, loss,)
        if (dmgType == 19) then
		cancelEvent()
            local currentHealth = getElementHealth(source)
            setElementHealth(source, currentHealth - loss*2) -- doubling the damage
        end
    end
)
Edited by Spakye
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...