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

  2. LOOKING FOR A VERSION OF SKRIPT??:

    You can always check our our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Help with Final Damage expression

Discussion in 'Skript' started by CreeperOverLord7, Jun 10, 2019.

Thread Status:
Not open for further replies.
  1. CreeperOverLord7

    Joined:
    Jan 19, 2018
    Messages:
    12
    Likes Received:
    1
    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:

    Code (Text):
    1. on damage:
    2.  
    3.     if attacker is not set:
    4.         exit trigger
    5.  
    6.     set {_netdmg} to entity_getDamage(attacker)
    7.     set {_truedmg} to entity_getTrueDamage(attacker)
    8.     set {_defence} to entity_getDefence(victim)
    9.  
    10.     broadcast "&eNETDMG: %{_netdmg}%, DEF: %{_defence}%, TRUEDMG: %{_truedmg}%"
    11.     set damage to {_netdmg} - ({_defence} * 0.75)
    12.  
    13.     if damage <= 0:
    14.         set damage to 0
    15.  
    16.     set damage to damage + {_truedmg}
    17.  
    18.     set damage to round(damage) * 0.5
    19.  
    20.     if damage <= 0:
    21.         set damage to 0.5
    22.  
    23.     broadcast "&aATTC: %attacker%, VICTIM: %victim%, VICTIM HP: %health of victim%, DMG: %damage%, FINAL DMG: %final damage%"
    24.     wait 1 tick
    25.     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.

    Problem:

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

    Troubleshooting:

    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):
    upload_2019-6-10_12-11-7.png

    Spider 2 (Defence 3):
    upload_2019-6-10_12-12-46.png
    upload_2019-6-10_12-13-12.png
    upload_2019-6-10_12-13-43.png
    upload_2019-6-10_12-13-57.png
    (As you can see, the final damage does not go below -4.5)

    Spider 3 (Defence 20):
    upload_2019-6-10_12-15-10.png

    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!
    --- Double Post Merged, Jun 10, 2019, Original Post Date: Jun 10, 2019 ---
    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.
     
Thread Status:
Not open for further replies.
Loading...