How do I set up a delay within a command block [closed]

I'm trying to recreate Runner in Minecraft 1.9 singleplayer, but I cannot get how to set up a delay so that the player can run without getting killed.


Solution 1:

Add an scoreboard objective: /scoreboard objectives add Moving stat.walkOneCm

Run the following commands in a clock(in exactly that order):

/kill @a[score_Moving=0,m=!1]
/scoreboard players set @a Moving 0

Warning: Be careful when setting this up. You will get killed, when not walking/running. And when the machine is killing you the whole time, you have no chance to disable it(except for external tools).

Solution 2:

I think what you want is a "grace period" for not running? I.e. the command blocks kill you if you stand still for more than, say, a second?

If so, you can run these in a repeat/chain setup:

/scoreboard players set @a OnGround 0 {OnGround:0b}
/scoreboard players set @a OnGround 1 {OnGround:1b}
/scoreboard players remove @a[score_Moving_min=1] Moving 1
/scoreboard players set @a[score_Moving_min=20] Moving 20
/kill @a[score_Moving=0,score_OnGround_min=1,tag=Running]
/scoreboard players tag @a[score_Moving=0,score_OnGround_min=1,tag=Running] remove Running

Moving is a stat.walkOneCm type objective, the OnGround tag is dummy. Moving does not increase while jumping/falling, which makes this addition necessary or else jumping or falling could kill you. The Running tag is to prevent an endless kill loop, add it to anyone that has to run to not die.

To adjust the timing, adjust the score set in the second command (both in the target selector and the set command) to the number of ticks the player may stand still (20 ticks = 1 second). This command acts like a "hard cap" on the Moving score (it can never exceed the value given).