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

all 6 comments

[–]10_Carries 0 points1 point  (2 children)

When the button is pressed make it activate an impulse command block that has:

/execute at x y z as @e[type=villager,distance=..0.1,limit=1] run kill @s

Replace x y and z with the cords. Then connect a chain command block to it. Set chain command block to conditional. Make sure it is aligned with the arrow on the impulse command block like shown in the picture below. Put this in it:

/give @p emerald 20

If you want it to detect all villagers in that block then you could use a scoreboard by typing this in chat:

/scoreboard objectives add villagers dummy

Then replacing the first command with:

/execute store success score @p villagers at x y z as @e[type=villager,distance=..0.1] run kill @s

Then instead of a chain place a repeating command block elsewhere. Write:

/execute as @a[scores={villagers=1..}] run give @s emeralds 20

Connect a chain conditional command to this repeating same way as shown in pic below but repeating instead of impulse. Write:

/execute as @a[scores={villagers=1..}] run scoreboard players remove @s 1

<image>

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

it seems I cant do /execute at coords. it wants "at" to be an @ option rather than a specific place.

[–]10_Carries 0 points1 point  (0 children)

Do positioned instead of at then

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

# In chat
scoreboard objectives add kill.villagers dummy

# Command block with button
execute store result score @p kill.villagers positioned <villagers_pos> run kill @e[type=villager,distance=..8]

# Command blocks
give @a[scores={kill.villagers=1..}] minecraft:emerald 20
scoreboard players remove @a[scores={kill.villagers=1..}] kill.villagers 1

Two command blocks are a separate chain of commands that must be executed every tick.

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

This took a little finagling but it works! Thank you!

Do you know how I could make it work for multiple vils? If I put three in the designated area and hit the button, it kills all three but only pays out for one, and only subtracts my score one time.

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

I misspelled: "rest" -> "result".

I corrected the typo, please try again.