1
I'm trying to select random entities with command blocks, but sadly I cannot come up with a way to do so. Previously I could easily select a random entity by just doing @r[type=ENTITY], but it looks like this cannot be done anymore in 1.12. if anyone can tell me how i could do it, it would be much appreciated.
Nvm, I also dont know how to remove this post lol
Nvm, I also dont know how to remove this post lol
Create an account or sign in to comment.
3
1
You mentioned 1.12 but re-reading the post I think you meant 1.13. If you found the solution then it's much nicer to share it so that other players can also benefit from it.
Anyway, guess it's up to me then.
While you can't specify a type using @r in 1.13 you can do so using @e. This still leaves you with the problem of getting a random entity, that's where sort= and limit= come into play. You can use a random selection ('sort') and then limit it to 1 entity:
execute as @e[type=ENTITY,sort=random,limit=1] run say I am randomized :)
If you need to run the command at the entities location (for example: because you want to perform tests, like checking the block below it) then you can extend on this using: at @s.
Anyway, guess it's up to me then.
While you can't specify a type using @r in 1.13 you can do so using @e. This still leaves you with the problem of getting a random entity, that's where sort= and limit= come into play. You can use a random selection ('sort') and then limit it to 1 entity:
execute as @e[type=ENTITY,sort=random,limit=1] run say I am randomized :)
If you need to run the command at the entities location (for example: because you want to perform tests, like checking the block below it) then you can extend on this using: at @s.
1
What makes you think this doesn't work in 1.12? Works just fine for me.
Are you sure you used the right entity type?
Are you sure you used the right entity type?
1
Are you on 1.13? The change is worth it. Gives us a sort parameter which is neat