Making a item damage x amount of damage with armor?

Mk, i’m bad at explaining things, but here’s a try
So, the max default health is 100
Armor gives 75 protection
A tool does 25 damage
How would you make it so 100 can be the default health but make it so each hit takes away an x amount of health each hit.
The hit amount for this should be 6,
Without knowing the hit amount, how would you get the result of it?

2 Likes

Well one way to do it could be this:
First we’ll setup an equation of: A = B * C

Where A = Absorbed Damage, B = Tool Damage Ammount, and C = Armor Protection % (Armor % should be a decimal)
So for example let’s plug in what you gave us; in this case it should look like this:
A = 25 * 0.75
A = 18.75

Next we’ll use another equation, this time: D = B - A

Where D = Damage Amount.
So we take what we got previously for A and plug it in along side the Tool Damage and get:
D = 25 - 18.75
D = 6.25

So D should be the ammount of damage being done to the player.
(Edit: Of course there is other ways of getting the damage that should be done to the player)

2 Likes

If the variables are given as shown, then:

math.floor(baseDmg * (100 - armor)/100)
1 Like

Right, so, if a player changes a tool, it should also take it away from the current health amount, so what parts of your code would need to be current health? Could you replace it with currentHealth?
@Darkmist101 I’m pretty sure you just replied some time ago but I couldn’t see the reply.

If this is like what I’m thinking of, you could do something as simple as this.

damage = (100) * (armor.Value ~= 0 and 0.40 or 1)

Basically, it’s saying the normal damage is 100 and it multiplies 100 by one of the multipliers on the right (0.40 and 1.) If the armor isn’t 0, then the damage reduction percentage is 60%. However, if they don’t have armor, then they take the blunt of the attack and most likely will die, unless you have tanky characters.

Hopefully this is what you were looking for (it’s the algorithm I use in Redshift Arena to handle armor protection and that sorta thing.)

For your use case, the variables would look like this:

damage = (25) * (armor.Value ~= 0 and 0.75 or 1)

What’d be armor.Value if you already have 0.75?
Or would it simply be the rest of my armor’s durability?

The way it works in my game is it’s a number value. You can have up to 200 armor for Instance.

You could change it to be a bool value or anything else really.

For your game, you might want to do Durability, though I’m not sure.

So if a weapon does 75 damage, and it takes 6 hits for armor with 75 protection for a player to die, and if a player has no armor, then in 2 hits, they’ll die, what’d be the algorithm for that?
if im not being clear enough,
original damage should be 75
The amount of hits till a player dies should be six,
protection should also be 75
If a player has no armor, then in two hits, they need to die.
How’d you do it this way?

It’s basically a compressed if / else statement. Instead of using if / else constantly, it simply uses &, ==, and or statements for the conditions.

damage = (25)

25 is the default damage

* (armor.Value ~= 0 and 0.75 or 1)

This is basically saying, if the armor isn’t 0, then damage is multiplied by 0.75, else, damage is multiplied by 1.

It’s a simple thing that a friend of mine helped out with a while back.

2 Likes

I’m gonna mark this as solved, thank you a lot for helping out!

1 Like