Jump to content

OnPlayerDamage check if has armor


knightscript

Recommended Posts

Hello, im trying to create a new damage system, first by Setting all weapon´s properties damage to 0, and afterwards, and then getelementdata of the player, if he is in group "Everyone" then get the damage in the element, etc, but what I want to do is this:

1.) check if the player has armor, 2.) if he has armor, check how much is it, 3.) if the damage specified in getelementdata of the attacker is for example, 20, and the player has 10% armor, i want to be able to remove 10% armor and 10% health. I don´t know if im explaining myself. I hope yes, what functions should i use? thanks.

Link to comment

What you could do is check if the amount going off of the armor (ex. 20) is greater then the remaining armor (ex. 10).

Then do; (if 20 > 10 then), In that case you could do (20 - 10) and then 10 is your difference. Set armor to 0 and take the remaining 10 off of the health.

Example in LUA (might not be the best solution)

function damageFunc (attacker, attackerweapon, bodypart, loss) 
   cancelEvent() -- Not sure but I think if not cancelling it the damage is doubled 
   local armor = getPedArmor(source) -- example. no armor, armor is 0 
  
   if (loss > armor) then 
      loss = loss - armor -- Loss example 20, loss = 20 - 0 = 20 
      setPedArmor(source, 0)  
      setElementHealth(source, (getElementHealth(source) - loss) -- health - 20 
   else 
      setPedArmor(source, (armor - loss)) 
   end 
end 
  
addEventHandler("onPlayerDamage", getRootElement(), damageFunc) 

Link to comment
setWeaponProperty requires more than just editing the damage. You can better cancel the event and create a table in lua with all the weapons and their damages. Just know that if you want to make it more realistic, you should count in body parts too.

I was actually thinking the same but thought that the weapon property would be easier.

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