problem with loop entities

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

Status
Not open for further replies.

Stefqnutz

Active Member
Sep 23, 2019
67
1
8
19
Okay so im working on a gamemode and I need to check loop entities around the attacker, so here's my code:
Code:
on damage:
    if victim is magma cube:
        set damage to 0
        if attacker is in world "%attacker%":
            remove 50 from {magmacubeadventurehealth::%uuid of attacker%}
            if attacker's held item is {@magmablade}:
                remove 300 from {magmacubeadventurehealth::%uuid of attacker%}
            if attacker's held item is {@witherbow}:
                remove 250 from {magmacubeadventurehealth::%uuid of attacker%}
            if attacker's held item is {@magmablademythic}:
                remove 400 from {magmacubeadventurehealth::%uuid of attacker%}
            if attacker's held item is {@endersword}:
                remove 200 from {magmacubeadventurehealth::%uuid of attacker%}
            if attacker's held item is {@pickaxeofthedead}:
                remove 500 from {magmacubeadventurehealth::%uuid of attacker%}
            if {magmacubeadventurehealth::%uuid of attacker%} is less than 1:
                kill victim
                set {magmacubeadventurehealth::%uuid of attacker%} to 5000
                loop all entities in radius 500 of attacker:
                    if loop-entity is not magma cube:
                        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"
                        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.
[doublepost=1617646768,1617646276][/doublepost]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.
 
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:
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.
 
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.
 
Status
Not open for further replies.