XML Posted January 16, 2018 Share Posted January 16, 2018 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 ? Link to comment
HairyMeets Posted January 16, 2018 Share Posted January 16, 2018 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 possiblesetVehicleHandling See collisionDamageMultiplier on table Link to comment
XML Posted January 16, 2018 Author Share Posted January 16, 2018 this is for vehicles .. only i meant for the player to reduce the damage of the player Link to comment
KaMi Posted January 16, 2018 Share Posted January 16, 2018 You can use this https://community.multitheftauto.com/index.php?p=resources&s=details&id=5195 ( from castillo, Solidsnake14 ). that don´t going to reduce the damage but gives extra health to the player ( it would be the closest thing because going to give a effect like reducing damage ) . Link to comment
Awang Posted January 16, 2018 Share Posted January 16, 2018 (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 January 16, 2018 by Awang Link to comment
ShayF2 Posted January 16, 2018 Share Posted January 16, 2018 (edited) 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.. Edited January 16, 2018 by ShayF Link to comment
Awang Posted January 16, 2018 Share Posted January 16, 2018 (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 January 16, 2018 by Awang Link to comment
ShayF2 Posted January 16, 2018 Share Posted January 16, 2018 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. 1 Link to comment
XML Posted January 16, 2018 Author Share Posted January 16, 2018 @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. 1 Link to comment
ShayF2 Posted January 17, 2018 Share Posted January 17, 2018 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. 1 Link to comment
Moderators IIYAMA Posted January 17, 2018 Moderators Share Posted January 17, 2018 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. 1 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