Solved Loop entities between 2 locations

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

Donut

Well-Known Member
Mar 27, 2017
1,336
177
0
U.S.
I'm trying to loop entities between 2 points but I can't get it to work. My code:
code_language.skript:
loop entities between {loc1} and {loc2}:
The error on reload: 'entities between <...>' can only accept a single world, not more.

This same code works if I replace 'entities' with 'blocks' so am I missing something or is looping entities between 2 locations just not supported?
 
No method exists for this. You can loop all entities then check if it's between the 2 locations, or preferably use a where filter to accomplish that
 
If you really need to, you could do something like:
code_language.skript:
loop blocks between {_loc1} and {_loc2}:
    loop entities in radius 0.7 of loop-block:
        if {_entityListID::%entity id of loop-entity%} is not set:
            add loop-entity to {_entityList::*}
            # just making sure we don't add a single entity twice
            set {_entityListID::%entity id of loop-entity%} to true
loop {_entityList::*}:
    # do stuff

It's untested, and I'm not sure if it'll work; but it's a start.
 
No method exists for this. You can loop all entities then check if it's between the 2 locations, or preferably use a where filter to accomplish that
If you really need to, you could do something like:
code_language.skript:
loop blocks between {_loc1} and {_loc2}:
    loop entities in radius 0.7 of loop-block:
        if {_entityListID::%entity id of loop-entity%} is not set:
            add loop-entity to {_entityList::*}
            # just making sure we don't add a single entity twice
            set {_entityListID::%entity id of loop-entity%} to true
loop {_entityList::*}:
    # do stuff

It's untested, and I'm not sure if it'll work; but it's a start.

Thanks for the responses guys. I thought about stuff like his but was hoping there was more efficient way to do it.

As far as performance goes, whose method would be better? Pikachu's suggestion of looping every entity on the server or Orendigo's suggestion of looping all the blocks then looping all the entities around the blocks? I guess I could just test them both and see but I was just wondering if anyone knew for certain which has the best performance.
 
Thanks for the responses guys. I thought about stuff like his but was hoping there was more efficient way to do it.

As far as performance goes, whose method would be better? Pikachu's suggestion of looping every entity on the server or Orendigo's suggestion of looping all the blocks then looping all the entities around the blocks? I guess I could just test them both and see but I was just wondering if anyone knew for certain which has the best performance.
Probably mine. Mine coupled with a where filter would definitely be the best because the check is then done in java loops which are more efficient than skript's loops
 
Okay I've never worked with where filters and im having some trouble getting it to work properly. i have this:
code_language.skript:
command /test:
    trigger:
        loop all entities where [entity's location is within {loc1} to {loc2}]:
            broadcast "%loop-value%"

however 'entity' (or event-entity) is me, the player executing the command, so 'entity's location' is my location which is obviously not what i want.

What would i put in place of 'entity's location' in order to the get the location of the entity being looped (i have tried 'loop-value's location' but it said theres no loop that matches 'loop-value's location')
 
Okay I've never worked with where filters and im having some trouble getting it to work properly. i have this:
code_language.skript:
command /test:
    trigger:
        loop all entities where [entity's location is within {loc1} to {loc2}]:
            broadcast "%loop-value%"

however 'entity' (or event-entity) is me, the player executing the command, so 'entity's location' is my location which is obviously not what i want.

What would i put in place of 'entity's location' in order to the get the location of the entity being looped (i have tried 'loop-value's location' but it said theres no loop that matches 'loop-value's location')
entity input's location
 
Status
Not open for further replies.