TransWikia.com

Detect where a specific player died?

Arqade Asked by xornob on April 18, 2021

So I am making a capture the flag game.
I have a objective for picking up the flag:

scoreboard objectives add red_flag stat.mineBlock.minecraft.wool Has the red flag

I want it so that when a player dies, if the have the flag, they drop it where they were standing, (as a block, using setblock).
I tried, where h is a health scoreboard:

execute @p[score_h=0] ~ ~ ~ setblock ~ ~1 ~ wool 14

This doesn’t work, because the player is dead, and score_h=1 means that if a player has exactly 1/2 heart, then they continuously setblock wool.

Currently, the only solution I can think of is this command, and /kill all players with 1/2 heart. I would like a cleaner solution. Any ideas?

4 Answers

Have you tried adding a scoreboard to detect whether he has the flag? Look at how to get and store player name? This time, attempt to /clear the flag.
– aytimothy

I've answered a question looking to identify a player, and perform something at their death.

Long story short, follow the instructions to make the gate and to identify the players, but replace the /clear command in the second step with:

/clear @p[score_playerID=1,score_playerID_min=1] minecraft:Wool 14 0

and the identifier with something else like... Say:

/scoreboard objectives create hasWool dummy hasWool
/scoreboard players set @p[score_playerID=1,score_playerID_min=1] hasWool 1
/scoreboard players set @p[score_playerID=1,score_playerID_min=1] hasWool 0

in order to identify whether someone has the flag or not. (This only works with /gamerule keepinventory true.)

Next, when the player dies, simply do your command, since you know that they're dead, and they have the wool.

Update:

These commands all work, but the problem is: if the player is dead, they can't execute commands. You can't /execute as a player if the player is dead.
– xornob

Let's say we'll use a Creeper to be the placeholder for the /execute command.

Run the conditional flip-flop gates (outlined in that first answer), testing for /testfor @a[score_h=0,hasWool_min=1] (looks for a player who's dead and had the wool.

When a player is dead and has the wool (condition sets to true), run /tp @e[type=Creeper] @p[score_h=0,hasWool_min=1], make that creeper place the block /execute @e[type=Creeper] ~ ~ ~ setblock ~ ~1 ~ wool 14 and teleport away /tp @e[type=Creeper] 0 0 0.
The false condition is up to you; you can either make it teleport the creeper back (since it's already done when the true condition runs anyway)

Just make sure that command is executed before they are respawn (or gets teleported to the respawn point)


Note: You can't directly @a as when you use /clear @a minecraft:Wool 14 0, it'll output true to everyone, even if only one person has it, while @p just gets messy. (You're detecting the closest player)

Correct answer by aytimothy on April 18, 2021

@MBraedley pointed out that dead players aren't valid targets for teleportation.

Disclaimer: The following idea should work, but I haven't tested it yet.

This answer requires the red_flag objective to work correctly. That is, it should be 1 for the player that carries the red flag, and 0 for everyone else.

Run this once

/summon ArmorStand 0 0 0 {Invisible:1,Marker:1,NoGravity:1,CustomName:"Marker"}

Then run this on a fast clock

/tp @e[type=ArmorStand,name=Marker] @p[score_red_flag_min=1]

This will make an invisible Armor stand with no hitbox continuously teleport to flag-bearer.

The moment the flag carrier dies, the tp command fails continuously, until a new valid target appears. Grab the output of tp with a comparator and invert the signal using a torch. Note that the comparator signal will be constant, unless something changes, according to the wiki:

SuccessCount: Represents the strength of the analog signal output by redstone comparators attached to this command block. Only updated when the command block is activated with a redstone signal.

This means, that the torch will be continuously on when no one has the flag and turn off when someone picks up the flag, after which it is continuously off. It will turn on exactly the moment the tp command fails, at which point it will power another command block with

/execute @e[type=ArmorStand,name=Marker] setblock ~ ~ ~ minecraft:wool 14 keep

Note that this will also happen when the red_flag objectives drops below 1 for any reason other than death, such as scoring. This can be easily remedied by removing all red wool blocks from the scoring area using

/fill <x1> <y1> <z1> <x2> <y2> <z2> minecraft:air replace minecraft:wool 14

Answered by MrLemon on April 18, 2021

I have an idea no-one proposed so far, also I'm not sure: Are you OK with using mods?

If you are, you can use the OpenBlocks mod, the GraveStone mod or any other mod that generates gravestones upon player death, and then repeatedly run a command replacing all gravestone blocks containing red wool block items with a red wool block.

(Not sure about the GraveStone mod, the OpenBlocks mod however should work cleanly when installed to the server only, at least the Forge version, I know that from LeKoopa's ChaosCraft projects. To those who don't know LeKoopa, it's a german MineCraft youtuber with lots of mod projects - mod reviews, multiplayer mod LP, lucky block minigames and untextured (as in all TNT textures are replaced by white wool textures) Too Many TNT survival quests are just a few examples.)

Answered by Egor Hans on April 18, 2021

The @a selector is the only selector capable of targeting dead players. You can set the c (maximum targets) parameter to 1 to reduce the number of targets.

You would need to track player deaths with the deathCount objective-type instead of health (which is read-only), as the dead player would otherwise constantly be setting the block:

/scoreboard objectives add deaths deathCount

The following would need to be run in numerical order:

  1. Cause dead players to run a /setblock command.

    /execute @a[score_deaths_min=1,score_red_flag_min=1,c=1] ~ ~ ~ /setblock ~ ~ ~ minecraft:wool 14
    
  2. Reset the "deaths" score so the previous command does not constantly run.

    /scoreboard players reset @a[score_deaths_min=1,score_red_flag_min=1] deaths
    

Answered by Skylinerw on April 18, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP