Solved Help with Final Damage expression

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!


    You can always check out skUnity Downloads for downloads and any other information about Skript!

Not open for further replies.
Jan 19, 2018
Hi! Thread too long for you? Scroll to the bottom and read the last line!

Skript Version (do not put latest): 2.2-dev36
Skript Author: Bensku
Minecraft Version: 1.12.2

(Note about Skript version: I know that it is old, but in the server that I plan on putting this script in, I cannot update it. I do not think the Skript version is causing this issue, but if you would like, I can test this with whatever latest version on a localhost.)

Full Code:

on damage:
    if attacker is not set:
        exit trigger
    set {_netdmg} to entity_getDamage(attacker)
    set {_truedmg} to entity_getTrueDamage(attacker)
    set {_defence} to entity_getDefence(victim)
    broadcast "&eNETDMG: %{_netdmg}%, DEF: %{_defence}%, TRUEDMG: %{_truedmg}%"
    set damage to {_netdmg} - ({_defence} * 0.75)
    if damage <= 0:
        set damage to 0
    set damage to damage + {_truedmg}
    set damage to round(damage) * 0.5
    if damage <= 0:
        set damage to 0.5
    broadcast "&aATTC: %attacker%, VICTIM: %victim%, VICTIM HP: %health of victim%, DMG: %damage%, FINAL DMG: %final damage%"
    wait 1 tick
    broadcast "&cVICTIM HP (after 1 tick): %health of victim%"

All 3 functions return a number which is broadcasted right after, so the calculation the functions use is probably not needed to be shown here.


(True Damage: Damage that is supposed to ignore all defence.)
(Victim Entity: A spider!)

The damage that is set in the damage event is correct. The final damage, which cannot be set, however, is not.

When an attack with 4 damage strikes an entity with 0 defence, it does 4 damage as expected.
When an attack with 4 damage strikes an entity with 3 defence, it does 2 damage as expected.
When an attack with 4 true damage strikes an entity with 0 defence, it does 4 damage as expected.

When an attack with 4 true damage strikes an entity with 3 defence, it does a negative amount of final damage, even though the set damage is correct and the attacked entity does not have any kind of resistance effects. The negative amount of final damage done is almost random, but it somehow goes down by 0.5 with each hit. The final damage stops going down at -4.5. (-0.5 -> -0.1 ... -4.5). The negative final damage heals the victim entity.

Here's where things get even more weird:
When a normal attack strikes the entity which is being hit by the negative-final-damaging-true-damage, it does 1 of 2 things:

1. Does the appropriate amount of damage it is supposed to.
2. If the victim entity was hit by several negative final damage up to the point where it stopped healing but also did not take any damage, i.e., it reached maximum health with the healing, it would take a few hits with a normal damage weapon to finally get it to do the appropriate amount of damage. In those few hits, the normal damage weapon would do 0 damage to the victim entity. On the hit where the appropriate damage for that weapon would be restored, the final damage would be a fraction of the appropriate damage.

Basically, the victim entity sort-of had an additional "health buffer" above the normal maximum health that we cannot see. I do not know where this comes from, but I think this would be fixed if the final damage stopped going negative, so I guess this is nothing to worry about for now.

Errors on Reload:

None, the code is not working as it is supposed to.

Console Errors: (if applicable)

None, the code is not working as it is supposed to.

Other Useful Info:

Addons using (including versions):
Skellett 1.9.6b, SkQuery 3.6.0-Lime, jNBT 0.3.2.
I do not think any of these are related to my issue.


Have you tried searching the docs? No, this is not a syntax error.
Have you tried searching the forums? No, but I doubt anyone else has this problem as google gave me nothing.
What other methods have you tried to fix it? I have tried broadcasting several expressions, as shown in the 'Full Code' section. Here is a list of results:

Test Tools: 3 Spiders (0 Defence, 3 Defence, 20 Defence and 2 swords (4 normal damage, 4 true damage)

Spider 1 (Defence 0):

Spider 2 (Defence 3):




(As you can see, the final damage does not go below -4.5)

Spider 3 (Defence 20):

Those are all of the tests.

I am hoping someone here can help me.

TL;DR: The final damage goes negative when the damage is positive!!!! WUT?? HOW IS THAT POSSIBLE?! SOME1 HELP ME!
[doublepost=1560151436,1560149435][/doublepost]Never mind, this is fixed.
For those who have this problem: Do not set the 'damage' expression for calculating the damage. Use a variable like {_damage}, and when you are done calculating, set damage to the variable. This should minimize issues.
Not open for further replies.