#How to do this in a better way ?

1 messages · Page 1 of 1 (latest)

restive dagger
#

Hi there,

I'm searching a way to code one thing in the better way possible, in terms of optimisation. I have a "take or leave" (deal or no deal) 1.21.4 game, where the players that are not chosen to be the main player are replaced by armor stands with their heads. Following the next screen, for each box that hasn't a player behind, an armor stand with the head of one of my friends (listed in a random function code) is summoned...

The problem is i temporaly made it random, so more than 1 armor stand can choose the same head, but i would like each head to appear only 1 time, like if we remove it from a list and it can't be chosen anymore. I could code it hardcoded, but i'm sure there's a easy trick to auto that...

I know we can store many elements in a list, in a storage, but i just don't get how to remove elements randomly from it. Maybe you'll have ideas.

Thanks

proud daggerBOT
#

<@&1201956957406109788>

Someone will come and help soon!

💬 While you wait, take this time to provide more context and details.

🙇 If nobody has answered you by <t:1737380838:t>, feel free to use the Summon Helpers button to ping our helper team.

✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve

restive dagger
#

There, 2 armor stands choose the same friend's name

sacred locust
#

You could make a global scoreboard that records which heads are currently in existence ^^

restive dagger
#

so when an armor stand choose a head, he gets a score and if an armor stand with this score existe, the random loop until if find something new ?

sacred locust
#

Yep!

restive dagger
#

i though to something like that, but i was curious about storages too

sacred locust
#

Storage is another interesting option

restive dagger
#

i used them in many way and i think there's a way to do it by that

#

but if we don't find, i'll use the first idea

sacred locust
#

You can put the head names into storage, then use execute if data to check which ones exist

restive dagger
#

yes i just though if i could remove them from the storage when they are chosen,

#

i could test for the data still being in the storage

#

and accept the random's choice

sacred locust
#

O yea

#

You could use data remove storage for that easily

#

^^

restive dagger
#

i tried but i don't find how to remove only 1 elements randomly

#

it removes all the .temp

sacred locust
#

Well, you know key-value pairs?

restive dagger
#

maybe i know this in french x)

sacred locust
#

You need to have a data set for each head, with the head name as the key

restive dagger
#

bot not sure in english

#

explain the idea

#

i think i see

#

i'm gonna do some tests with this

sacred locust
#

Okiii!

restive dagger
#

for example custom_data={Krono7:1b} ?

#

It seems possible this way

#

i'm gonna change the random function to make it store random name and then follows it by a macro function doing the test and replace

restive dagger
#

This seems to work !
Note : the armor stand can't choose a random head if the player exists on the game's zone, because the head will simply be replaced by the player looting his head in his main hand.

Function 1 :

`data remove storage take:players name
execute store result score TakeArmorstand2 TakeTime run random value 1..32
execute if score TakeArmorstand2 TakeTime matches 1 unless entity @a[name=Krono7,distance=..100] run data modify storage take:players name set value Krono7
execute if score TakeArmorstand2 TakeTime matches 2 unless entity @a[name=Lunaria45,distance=..100] run data modify storage take:players name set value Lunaria45
...

execute if data storage take:players name run function take:armorstand3 with storage take:players
execute if score TakeStart TakeTime matches 870 run item replace entity @s armor.head from entity @p weapon.mainhand
execute unless data entity @s ArmorItems[3].id run function take:armorstand2`

Function 2 :

tag @s add TakeHeadReplace $item replace entity @s armor.head with player_head[profile=$(name),custom_data={$(name):1b}] $execute as @e[type=armor_stand,tag=Take,tag=!TakeHeadReplace,distance=..100] at @s if data entity @s ArmorItems[3].components."minecraft:custom_data".$(name) run item replace entity @n[type=armor_stand,tag=TakeHeadReplace] armor.head with air tag @s remove TakeHeadReplace

So basically the name randomly chosen if stored, the armorstand searching for a head get a tag and the head and if any armor stand without this tag, in a distance, have already the chosen head, they remove the head from him. He looses his tag and until he hasn't head, he loops the first function

#

Seems working !

#

i have no clones anymore, the custom_data was a great idea, thanks!

proud daggerBOT
#
Question Closed

Your question, #1330888888755032114 (How to do this in a better way ?), was resolved!

Original Message

#1330888888755032114 message

Duration open

46m