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

problem with loop entities

Discussion in 'Skript' started by Stefqnutz, Apr 5, 2021.

  1. Stefqnutz

    Stefqnutz Active Member

    Joined:
    Sep 23, 2019
    Messages:
    52
    Likes Received:
    1
    Okay so im working on a gamemode and I need to check loop entities around the attacker, so here's my code:
    Code (Text):
    1. on damage:
    2.     if victim is magma cube:
    3.         set damage to 0
    4.         if attacker is in world "%attacker%":
    5.             remove 50 from {magmacubeadventurehealth::%uuid of attacker%}
    6.             if attacker's held item is {@magmablade}:
    7.                 remove 300 from {magmacubeadventurehealth::%uuid of attacker%}
    8.             if attacker's held item is {@witherbow}:
    9.                 remove 250 from {magmacubeadventurehealth::%uuid of attacker%}
    10.             if attacker's held item is {@magmablademythic}:
    11.                 remove 400 from {magmacubeadventurehealth::%uuid of attacker%}
    12.             if attacker's held item is {@endersword}:
    13.                 remove 200 from {magmacubeadventurehealth::%uuid of attacker%}
    14.             if attacker's held item is {@pickaxeofthedead}:
    15.                 remove 500 from {magmacubeadventurehealth::%uuid of attacker%}
    16.             if {magmacubeadventurehealth::%uuid of attacker%} is less than 1:
    17.                 kill victim
    18.                 set {magmacubeadventurehealth::%uuid of attacker%} to 5000
    19.                 loop all entities in radius 500 of attacker:
    20.                     if loop-entity is not magma cube:
    21.                         send "&c[BOSS] Extreme Magma Cube&f: &4ENOUGH! &fHow did you manage to kill all of my magma cubes? Well, nevermind, it's time you see true power." to attacker
    22.                         spawn 1 slime at location of attacker
    23.                         set slime size of last spawned slime to 15
    24.                         set name of last spawned slime to "&4&lEXTREME MAGMA CUBE"
    25.                         kill loop-entity
    if you look at the last lines of code, you can see that im checking for entities in radius 500 of the attacker, and if the loop entity isn't a magma cube, it should do the following things.
    Now, this code simply dosent work, I dont get any errors in Skript but it dosent work properly.
    What happens is it simply spams:
    send "&c[BOSS] Extreme Magma Cube&f: &4ENOUGH! &fHow did you manage to kill all of my magma cubes? Well, nevermind, it's time you see true power." to attacker
    spawn 1 slime at location of attacker
    set slime size of last spawned slime to 15
    set name of last spawned slime to "&4&lEXTREME MAGMA CUBE"

    even if theres still magma cubes in radius 500 of the attacker, it will spam that no matter what.

    Another weird thing is that I have an item called "Pickaxe Of The Dead" and it has an ability where when you right click, it kills all mobs in radius 10 of you. You know what happens? It only kills 1 mob even if theres still more mobs. Funny how it actually worked before but now all of a sudden it stopped working.
    So can anyone help me? Thanks.
    --- Double Post Merged, Apr 5, 2021, Original Post Date: Apr 5, 2021 ---
    New Update: I made another skript where I made a command that loops entities in radius 10 of player, and if that loop entity is slime it will kill it.
    Guess what? It worked with no problems, meaning the problem is because of my skript.
     
  2. TheRealUnderscore

    TheRealUnderscore New Member

    Joined:
    Mar 31, 2019
    Messages:
    5
    Likes Received:
    1
    It's because you're doing the check in the loop.

    Imagine there's 4 entities in a radius of 500: a cow, a magma cube, a slime, and a zombie.

    The condition will get passed for the cow and do the code, sending the message and whatsoever, then it won't for the magma cube. But... since it's a loop, it'll keep going, do the slime and zombie, and do the code as well.

    The best solution to this is:
    Code (Text):
    1. if (all magma cubes in radius 500 of attacker) is not set:
    What this does is get all the magma cubes in a radius of 500. If there aren't any, it'll pass the condition, but if there are, it'll be set, therefore not passing the condition.
     
  3. Stefqnutz

    Stefqnutz Active Member

    Joined:
    Sep 23, 2019
    Messages:
    52
    Likes Received:
    1
    Im afraid its a problem with my script, since it worked before with the system that I used, but I think I added something that broke it.
     

Share This Page

Loading...