Solved Detect damage AGAIN in a while loop

  • 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!

  • LOOKING FOR A VERSION OF SKRIPT?

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

YW_Beta

Member
Jul 14, 2023
2
1
3
32
I'm trying to detect if a victim is damaged AGAIN in this while loop after damage, but the loop is exited instantly instead of waiting for a second attack to happen like I want it to.
Code:
On damage:
if type of victim is a slime:
while block below victim is not grass block or oak leaf or moss carpet:
send "hi there" to attacker #just to ensure that I get into the loop
wait 1 tick
if victim is damaged:
send "damaged" to attacker #just to make sure that this is the reason the loop stops
exit loop
currently I receive 1 "hi there" and 1 "damaged" after punching the slime
If someone could help me make it so that the loop is only exited after 2 punches that would be great :emoji_slight_smile:
 
You could try setting a separate variable like {_dmg} where a numerical value is added to it. So like:

Player punches slime once, it adds one to {_dmg}, player punches slime again and it adds more to {_dmg}, code checks if {_dmg} is 2 then resets the variable and does the rest of your code.

Keep in mind if you want a system like this for multiple players, it could be more effective to use a player assigned variable rather than a local one to prevent players interfering with each others variables.
 
  • Like
Reactions: YW_Beta