4

I have a command block line set up so that it detects for a players death, then gives them weakness for 600 seconds. It applies weakness to soon before they get out of the respawn time. If there is not way to delay a command is there a way to detect a player respawn?

4
  • you may try to use the event fired when the player respawn. I don't create an answer as I don't know if it is feasible, but this may be a good start.
    – Zoma
    Commented Jul 19, 2019 at 7:29
  • If you need a specific timing on the command block, you use redstone.
    – SF.
    Commented Jul 19, 2019 at 8:17
  • 1
    @Zoma They mentioned command blocks, so this is not about modding. If you want to help with mod development, this is the place for you: gamedev.stackexchange.com Commented Jul 19, 2019 at 15:49
  • @SF. No, redstone is generally evil for performance, response times, safety and much more. See also here: gaming.stackexchange.com/questions/345884/… Commented Jul 19, 2019 at 15:51

5 Answers 5

13

Your real problem is that the players can wait arbitrarily long until they click "respawn", so no fixed delay would help you. What you can instead do is detecting when they have respawned. This can for example be done by checking if they are at a location (because dead players are nowhere*):

/execute as @a[scores={deaths=1..},distance=0..] run <command>

This distance=0.. might seem useless, because you're testing for a distance of 0 or more from the command block, but what it does is only activating if you have an alive player in the same dimension. You could also do the same for Nether and End, but since you want to detect respawning, that's not necessary. Dead players have no location, so their distance from the command block isn't 0 or more, it's nothing.


*This got a bit more complicated in 1.15, because the player is still registered as being at their death location for about a second after dying. That could be very helpful in some cases, I think it even used it in an answer here already, but it complicates this case. Now you need to check if they are not at any location first and then at a location again:

execute as @a[tag=!dead,scores={deaths=1..}] unless entity @a[scores={deaths=1},distance=0..] run tag @s add dead
execute as @a[tag=dead,distance=0..] run <command>
execute as @a[tag=dead,distance=0..] run scoreboard players set @s deaths 0
execute as @a[tag=dead,distance=0..] run tag @s remove dead

The first command is the real magic: Every player who died gets tagged, but only once no player who died can be found at any location anymore. This still fails if another player is currently in its death animation, I don't think this can be avoided.
Then you just run whatever command you want at a player that used to be at no location, but is at some location now. Finally, you reset the scoreboard (implied in my 1.14 solution) and the tag.

1
  • Oh this is very good. I tried writing out a commands thing like that but couldn't think of a way to figure out if the player had clicked respawn.
    – Nik3141
    Commented Jul 19, 2019 at 17:13
4

Can you use repeaters? If you can, have one command block that detects the player's death and then have a few redstone repeaters lined up to delay the signal to the block that gives the effect.

2

Target a player who died only once they've respawned by using the @e target selector instead of @a or @p and specifying [type = player] along with any other selector arguments you're using to pick the correct player (probably a tag or scoreboard value). This works because @a targets any player while @e only targets alive entities as of 1.18.1 Java Edition. So, to solve your problem, you'd do something like execute as @e[type = player, tag = dead] run effect give @s weakness 600 1 true or execute as @e[scores = {deaths=1..}] run effect give @s weakness 600 1 true. Note that if you're using a scoreboard, specifying the type is redundant because only players can have scores.

1

The repeater is a redstone block that when you give a redstone signal from the back, there will be a delay and then will transmit the redstone signal from the front. Try adding a repeater between the redstone source and your command block. Each repeater can be set to give a different delay, and if you need a longer delay, try lining up several.

0

You can make a scoreboard that detects when they spawn back in and set a /execute command when the scoreboard reaches a certain value. Depending on the spawn location, you can use /execute at or execute if to detect when a player spawns and we’re they spawn. There are probably better videos of explaining this but I use this a lot

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .