Skip to content

Commit

Permalink
Update derangement-function.md
Browse files Browse the repository at this point in the history
  • Loading branch information
zheaEvyline authored Sep 15, 2024
1 parent cc74996 commit b826a4a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions docs/commands/derangement-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ A derangement is a permutation of 'N' elements where no element appears in its o

For example, if Player1 was at `0,0,1`, Player2 at `0,0,2`, and Player3 at `0,0,3`, Player1 can only be relocated to `0,0,2` or `0,0,3`. The same rule applies to all other players.

---
<br>

**Key Features of this Function Pack:**

Expand All @@ -27,7 +27,7 @@ For example, if Player1 was at `0,0,1`, Player2 at `0,0,2`, and Player3 at `0,0,

To derange the positions of 100 targets, this function pack requires only 4-6 iterations, executing a total of 7 commands for the initiation, and 7 per iteration.

---
<br>

The number of iterations increases proportionally with the number of elements.

Expand Down Expand Up @@ -74,7 +74,8 @@ execute if entity @e [name="Fake Player", scores={id=0}] run scoreboard players
## Assign the New ID
scoreboard players operation @r [type=armor_stand, name="Fake Player", scores={id=0}] id = Total id
```
---

<br>

This is the function you run (once) each time you need to derange the positions of all targets:

Expand Down Expand Up @@ -105,7 +106,8 @@ tag @a remove posAllocated

In case a single target is left with no available position except its original, the final 3 commands will resolve the collision. We call it a collision because when this occurs, the target will be at the allocated position of another target.

---
<br>

The actual randomized derangement process will be performed by this function below:

<CodeHeader>BP/functions/events/player/derange_position/process.mcfunction</CodeHeader>
Expand Down Expand Up @@ -133,7 +135,9 @@ execute as @a [tag=!posAllocated] run scoreboard players add NonAllocatedPlayers
## Loop Function if 2+ Players Are Not Allocated a Position
execute if score NonAllocatedPlayers count matches 2.. run function events/player/derange_position/process
```
---

<br>

Now, for our functions to actually work, we will need to add the following objectives on our world:

<CodeHeader>BP/functions/scoreboards/objective/add_all.mcfunction</CodeHeader>
Expand All @@ -142,7 +146,9 @@ Now, for our functions to actually work, we will need to add the following objec
scoreboard objectives add id dummy
scoreboard objectives add count dummy
```
---

<br>

If you wish to add the objectives automatically as soon as you load the world, you may create the function file below:

<CodeHeader>BP/functions/events/world/on_initialise.mcfunction</CodeHeader>
Expand Down

0 comments on commit b826a4a

Please sign in to comment.