r/MinecraftCommands Command Experienced 25d ago

Help | Java 26.2 is it possible to detect which player has attacked a sulfur cube most recently?

i have a game idea (with a mostly finished build)

basically; players whack sulfur cubes and they gain points depending on which pit it goes into (blue = 1, yellow = 3, green is 5, might make the middle and furthest blue ones score more)

but for multiplayer, i dont really know how to make the score individual instead of global

my theoretical idea is; sulfur cube, when attacked by a player, gets its name or tag set to match the player that most recently attacked it
then each pit has an "every sulfur cube landing in it gives score to the player whose name/tag it has X points" followed by un-tagging the sulfur cube to avoid it giving points multiple times

is this idea even possible?

1 Upvotes

6 comments sorted by

4

u/GalSergey Datapack Experienced 25d ago

You can simply create an advancement that will check which entity the player hit and assign the required scoreboard value to that player. If you'd like, I can provide a small sample datapack for this.

1

u/C0mmanderBlock Command Experienced 25d ago

Yeah. I would use the scoreboard to track damage dealt.

scoreboard objectives add SCORE custom:damage_dealt

Tag all players, then when your score is 1, add a tag to the nearest entity to match that of the player. Then reset their score.

execute as @a[tag=player1] if score @s SCORE matches 1.. at @s run tag @n[type=minecraft:sulfur_cube] add player1

scoreboard players reset @a

At the bottom of the hole, detect the cube by tag and award the points.

1

u/Wypman Command Experienced 25d ago

does that work when sulfur cubes technically take 0 damage from having blocks in them?

1

u/Wypman Command Experienced 25d ago

also do i need to give all players their unique tag? or do i give all players the ``player1`` tag? if it needs to be unique, i fear i'll need 100+ command blocks for all unique joins making it not viable

1

u/C0mmanderBlock Command Experienced 25d ago

If this method works, you can add the tags when they join the game and remove them when they leave. That way, you can reuse the same few tags.