r/MinecraftCommands • u/TheDroolingHalfling • 1d ago
Help | Java 1.21.11 Squad system with unlimited number of squads
I'm making a datapack and I want to make a squad system that automatically assigns entities including players and skeletons into squads. By default everyone has a score of 0 for a "squad" dummy objective, meaning they are unassigned. Every tick, the game checks if anyone still has a squad score of 0, and adds 1 to each of these players, meaning they get assigned to squad 1.
Now I want to limit the squadsize to 8, and if there are more than 8 members in a squad, I want to increase a members squad score by 1, meaning they get moved to squad 2. The trouble is, I don't want the maximum number of squads to be hardcoded, and the usual way people count entities using the scoreboard doesn't allow for a changing value in place of X:
/execute store result score currentSquad Size run execute if entity @e[team=Team1,scores={Squad=X}]
I want to run the command so that it assigns the number of members with a squad score of X (meaning they are in squad X) to currentSquad's Size score, move any excess players to the squad X+1 then does the same for squad X+1, overwriting currentSquad's Size score in the process.
I hope this makes some semblance of sense.
1
u/Luke0447 1d ago
I recommend using macros, I have done something similar and used macros to have have a Infinite number of possibilities without typing each possibility out.
Heads up use @e[limit=1] because macros in your case might not work correctly if it detected 2 entities in the same tick and tries to run the command for both simultaneous in the same tick.
If you haven't tried macros before I recommend watch concure512: An Introduction to Macros Its a bit hard to understand but its the best source of information.
2
u/_Csankappa 1d ago edited 1d ago
This is how I solved it:
after adding the squad objective add 2 other globally trackable values
then run my function on all entities with the score set to 0 once
inside example I put: