Jump to content

[Question] Reduce the damage


XML

Recommended Posts

Posted

Hello guys, I was wondering if it's possible to reduce the damage

for a specific player by using an ability or stuff like that ?

Posted
2 hours ago, XML said:

Hello guys, I was wondering if it's possible to reduce the damage

for a specific player by using an ability or stuff like that ?

For the player of such functions I did not find, but for transport it is quite possible
setVehicleHandling
See collisionDamageMultiplier on table

Posted (edited)

Or if you add a specific elementData, you can write something like this:
 

addEventHandler("onClientPlayerDamage",root,function(attacker, weapon, bodypart,loss)
  if source == localPlayer and getElementData(localPlayer,"less.damage") == true then
	cancelEvent()
	setElementHealt(localPlayer,getElementHealt(localPlayer)-loss*0.8)
  end
end)

For the player, who have the elementData will only get the 80% of the real damage.

Edited by Awang
Posted (edited)
17 minutes ago, ShayF said:

local reductionPercent = '50'

addEventHandler('onClientPlayerDamage',root,function(attacker,weapon,bodypart,loss)
    if loss then
      local health = getElementHealth(localplayer)
      setElementHealth(localplayer,health+(loss/reductionPercent))
    end
end)

Something like this.

No offense, I was using a phone to type this, so code might look wonky..

You shuld check this by matematically... For example, the loss is 10, 10/50 will not the 50% of 10....
if you really want to do with percent parameter, you need to use like this:
 

    local reductionPercent = 50

    addEventHandler('onClientPlayerDamage',root,function(attacker,weapon,bodypart,loss)
        if loss then
          local health = getElementHealth(localplayer)
          setElementHealth(localplayer,health+(loss*(reductionPercent/100))
        end
    end)

Still I think, cancel the root damage and recalculate it will be the simpliest way to understand how this event work...
Even the question was reduce the damage for a specific player, not for everbody...
With elementData you can change it real time in the server, like an admin can take this ability or give it to a player by using setElementData()

Edited by Awang
Posted
1 minute ago, Awang said:

You shuld check this by matematically... For example, the loss is 10, 10/50 will not the 50% of 10....
if you really want to do with percent parameter, you need to use like this:
 


    local reductionPercent = 50

    addEventHandler('onClientPlayerDamage',root,function(attacker,weapon,bodypart,loss)
        if loss then
          local health = getElementHealth(localplayer)
          setElementHealth(localplayer,health+(loss*(reductionPercent)/100))
        end
    end)

Still I think, cancel the root damage and recalculate it will be the simpliest way to understand how this event work...

Thank you, I'm on a phone and a bit busy, hard to type or even thing of reasonable math. So thank you for fixing my code.

  • Like 1
Posted

@Awang

Thank you, Your way is the one i need exactly.

 

@ShayF

Thanks for your help, But i guess your code have some issues

I remember i used this way once, And i noticed some problems in it

like your hp reloaded automatically sometimes when you get hit by another player

specially if the other player have a lag or something, or also you.

 

  • Like 1
Posted
15 hours ago, XML said:

@Awang

Thank you, Your way is the one i need exactly.

 

@ShayF

Thanks for your help, But i guess your code have some issues

I remember i used this way once, And i noticed some problems in it

like your hp reloaded automatically sometimes when you get hit by another player

specially if the other player have a lag or something, or also you.

 

This is due to improper math calculations.

  • Like 1
  • Moderators
Posted

Reloading health happens when you are setting the health below 0.

But the main issue is with the reduction of loss. Because with this code the health should never reach 0 in the first place. The loss can never be higher then the remaining health. Which means that if you have 1 health, the damage is 1000 but the loss will remain 1. If you reduce the loss with 50%. 1 health / 2 = 0.5 / 2 = 0.25 / 2 = 0.125 etc.

Until mta thinks you are dead...

 

And yes it can be a little bit buggy sometimes for an unknown reason, which doesn't happen really often if you write the code correct.

 

 

  • Thanks 1

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