- Joined
- Nov 17, 2010
- Messages
- 6,756
- Solutions
- 578
- Reaction score
- 5,305
How do you know he wants the damage before everything is already calculated from the sources?
From original post, taking 100 down to 95 from a 5% damage reduction looks like it is exactly what he wants.
I must be very confused... Would this script not work as I think it would?
Code:function onStatsChange(cid, attacker, type, combat, value) if combat == COMBAT_PHYSICALDAMAGE then if type == STATSCHANGE_HEALTHLOSS and getCreatureStorage(cid, PHYS_RESIST_STORAGE_VALUE) then value = value * PHYS_RESIST_STORAGE_VALUE doTargetCombatHealth(attacker, cid, COMBAT_PHYSICALDAMAGE, -value, -value, CONST_ME_NONE) return false end end return true end
Or better yet, why would this not work the way the OP wants it to?
First, let's assume someone is wearing 10 armor, with 5% physical reduction, and has taken 100 physical damage.
This armor also has 1% extra physical protection, via the script.
Armor reduction is as follows..
Minimum reduction = armor / 2
maximum reduction = (armor / 2) * 2 - 1 (I've never understood why it's not just armor - 1 though.)
So, 5 to 9 reduction.
We also know this 10 armor, has 5% physical reduction.
physical reduction = math.floor((100 - 5) / 100 * damage)
We also know that physical percentage reduction happens after the armor has been taken into account. (Note: this is only if the shield has been by-passed. Aka: your actually taking damage.)
So in our example, we'll just say the armor will reduce 7, being the median.
Initial damage = 100
100 - 7 = 93
math.floor((100 - 5) / 100 * 93) = 88
Alright, so the player is taking 88 damage.
Now it goes over to your statsChange script.
The player is supposed to take 1% less physical damage.
math.floor(88 * 0.99) = 87 damage.
So now you are going to return false the 88 damage, and put the 87 damage through as the new damage to the player.
87 - 7 = 80
math.floor((100 - 5) / 100 * 80) = 76
Minimum reduction = armor / 2
maximum reduction = (armor / 2) * 2 - 1 (I've never understood why it's not just armor - 1 though.)
So, 5 to 9 reduction.
We also know this 10 armor, has 5% physical reduction.
physical reduction = math.floor((100 - 5) / 100 * damage)
We also know that physical percentage reduction happens after the armor has been taken into account. (Note: this is only if the shield has been by-passed. Aka: your actually taking damage.)
So in our example, we'll just say the armor will reduce 7, being the median.
Initial damage = 100
100 - 7 = 93
math.floor((100 - 5) / 100 * 93) = 88
Alright, so the player is taking 88 damage.
Now it goes over to your statsChange script.
The player is supposed to take 1% less physical damage.
math.floor(88 * 0.99) = 87 damage.
So now you are going to return false the 88 damage, and put the 87 damage through as the new damage to the player.
87 - 7 = 80
math.floor((100 - 5) / 100 * 80) = 76
Now you could by-pass the armor the second time and get a correct value using
Code:
doCreatureAddHealth(cid, -87)
return false
Not to mention, onStatsChange will only ever give you the value of damage UP to the players current remaining life pool.
So if you get damaged 500 damage, and you only have 400 life.. onStatsChange will tell you the damage is 400.
You can see where that is problematic I'm sure..
The only way to fix this issue.. is to either have a new function that finds the damage values Before they are applied to the player and alter them then..
Or to change the values inside the damage formula.. aka, adjusting the armor reduction on the items themselves.. which without a source edit to provide that functionality, is impossible.
Last edited: