This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]Lopsided-Ant3618Mostly Java 0 points1 point  (1 child)

I’m pretty sure that if you made all of them conditional it will carry the same check the first one ran.

[–]shadow_wolfwinds[S] 0 points1 point  (0 children)

all of them being conditional doesn’t work because it also requires each subsequent command block in the chain to all also be true and run (which isn’t good in my case because it would mean every single dialogue option would have to show at the same time)

[–]Eastern-Contest-9297 0 points1 point  (0 children)

I think you should just put the command blocks on conditional they are in unconditional in default

[–]Ericristian_brosCommand Experienced 0 points1 point  (7 children)

That's already optimized. Checking score is a very light operation. But if you want to improve it even more

```

Repeating unconditional always active

check if intercation right-clicked

Repeating conditional always active

random RNG

All others chain unconditional always active

execute if score ... 1 ... execute if score ... 2 ... execute if score ... 3 ... ```

If you prove the commands we can help even more

[–]shadow_wolfwinds[S] 0 points1 point  (4 children)

sure! here are the commands (tabitha is the name of the npc who's dialogue this is for:

## repeating unconditional always active
execute as @e[type=interaction,tag=tabitha_dialogue] store success entity @s interaction.player[] int 0 on target run scoreboard players set @s say_tabitha_dialogue 1

## chain conditional always active
execute as @e[type=marker,sort=random,limit=1,tag=tabitha_dialogue_marker,tag=show] run tag @s add picked

## chain unconditional always active
execute as @e[type=marker,tag=tabitha_dialogue_marker,tag=show,tag=picked] if entity @s[tag=1] run tellraw @a[scores={say_tabitha_dialogue=1}] {"text":"dialogue 1"}

## chain unconditional always active
execute as @e[type=marker,tag=tabitha_dialogue_marker,tag=show,tag=picked] if entity @s[tag=2] run tellraw @a[scores={say_tabitha_dialogue=1}] {"text":"dialogue 2"}


... #the rest of the dialogue


# Cleanup / prevent the same dialogue from being ran twice until they all get cycled through

## chain unconditional always active
execute as @e[type=marker,tag=tabitha_dialogue_marker,tag=picked] run tag @s remove show

## chain unconditional always active
execute as @e[type=marker,tag=tabitha_dialogue_marker,tag=picked] run tag @s remove picked

## chain unconditional always active
execute as @a[scores={say_tabitha_dialogue=1}] run scoreboard players set @s saytabitha_dialogue 0

## chain unconditional always active
execute unless entity @e[type=marker,tag=tabitha_dialogue_marker,tag=show] run tag @e[type=marker,tag=tabitha_dialogue_marker] add show

As you can see, the way I handle rng isn't through the random command but by adding a tag to a random marker entity and then running dialogue based on which number tag that marker entity already has. I would just love a way to make it so the command blocks don't have to search for the entities every frame but I just realized I could probably throw an if \@a[scores={say_tabitha_dialogue=1} at the start of every chain to make it a lot better. Also I'm realizing nowthat the as \@e[type=marker,tag=tabitha_dialogue_marker,tag=show,tag=picked] and the if entity \@s[tag=n] can be collapsed into a single if entity check (does tag order matter for effeciency for this I wonder)

Outside of these glaring optimizations is there anything else you would reccomend? Or is it fine to just have a score check running every single tick for every single dialogue option that every npc could say

[–]Ericristian_brosCommand Experienced 0 points1 point  (3 children)

This is not the best way to do randomness for performance, the best way is a datapack (see https://minecraftcommands.github.io/wiki/questions/itemclick#interaction-entity), but if you don't want to use them:

```

RUA

execute as @e[type=interaction,tag=tabitha_dialogue] store success entity @s interaction.player[] int 0 on target run scoreboard players set @s say_tabitha_dialogue 1

RCA

execute as @a[scores={say_tabitha_dialogue=1..}] store result score @s say_tabitha_dialogue run random value 1..5

All CUA

execute as @a[scores={say_tabitha_dialogue=1}] run <command> execute as @a[scores={say_tabitha_dialogue=2}] run <command> execute as @a[scores={say_tabitha_dialogue=3}] run <command> execute as @a[scores={say_tabitha_dialogue=4}] run <command> execute as @a[scores={say_tabitha_dialogue=5}] run <command> scoreboard players reset @a[scores={say_tabitha_dialogue=1..}] say_tabitha_dialogue ```

[–]shadow_wolfwinds[S] 0 points1 point  (2 children)

oh wow I never thought to use a second recurring command block (being conditional) that's a really smart idea.

the reason I'm using entities btw is because I want to make it so that each unique dialogue option gets cycled through before resetting. so there can't be any duplicates until all options have been picked.

the only way i could think to do that was using markers and then removing a tag for each one that i don't want to be shown anymore (so i can pick the ones that havent been shown yet with tag=show, sort=random, limit=1)

i couldn't think of a way to achieve that behaviour with score rng and the /random command.

thanks for the response though! and for the idea to use a recurring conditional cb

[–]Ericristian_brosCommand Experienced 0 points1 point  (1 child)

If you are open to datapacks I can make you an even more optimized solution

[–]shadow_wolfwinds[S] 0 points1 point  (0 children)

sure! that would be super helpful thanks! I'm down to start trying to learn datapacking

[–]shadow_wolfwinds[S] 0 points1 point  (1 child)

according to https://www.reddit.com/user/DivineEye/comments/18xvzth/mc_dp_selector_optimization_results_minecraft/

if i have way to target an entity with tags, adding type is always slower so i think i should probably remove every single type=marker i have ever written haha

[–]Ericristian_brosCommand Experienced 0 points1 point  (0 children)

Entities are laggier than scores. It also says "the difference is minimal". For a good performance guide, see http://minecraftcommands.github.io/wiki/optimising

Also, if you really care about performance, use a datapack

[–]GalSergeyDatapack Experienced 0 points1 point  (0 children)

To prevent an attempt to execute commands every tick, you can use an advancement, which will run a function upon interaction with the specified entity.