On death of player: if {lastdeath.%uuid of player%} is not set: # last death not set on player. set {lastdeath.%uuid of player%} to now # Make sure death counter is zero before we begin. subtract {deathcounter.%uuid of player%} from {deathcounter.%uuid of player%} else if difference between {lastdeath.%uuid of player%} and now is smaller than 30 seconds: # Assuming it takes a player less than 30 seconds to die from lava or suffication each time when bed trapped. add 1 to {deathcounter.%uuid of player%} set {lastdeath.%uuid of player%} to now set {deathlocation.%uuid of player%} to location of player else: # Make sure to set last death time when last death was more than 30 seconds ago. set {lastdeath.%uuid of player%} to now if {deathcounter.%uuid of player%} is 2: send "%{deathcounter.%uuid of player%}% deaths within 30 seconds of each other." to player send "Bed trap detection started." to player send "Continue to respawn to a count of 5 times to be set free." to player else if {deathcounter.%uuid of player%} is 3: send "%{deathcounter.%uuid of player%}% deaths within 30 seconds of each other." to player else if {deathcounter.%uuid of player%} is 4: send "%{deathcounter.%uuid of player%}% deaths within 30 seconds of each other." to player else if {deathcounter.%uuid of player%} is 5: send "%{deathcounter.%uuid of player%}% deaths within 30 seconds of each other." to player # Player has died five times in rapid succession. # Very high probability of being bed trapped. # Get rid of any obsidian or lava in the area as well. loop blocks in radius 20 around player: loop-blocks is equal to obsidian or lava set loop-blocks to air loop blocks in radius 2 around player: set loop-blocks to glass loop blocks in radius 1 around player: set loop-blocks to air # Two second delay needed for items to be able to be placed in player inventory. wait 2 seconds give a iron pickaxe to the player give a iron axe to the player send "You were bed trapped and are now free. Unfortunately you may have lost the items you were carrying." to player send "Here are a couple of tools to dig your way out." to player subtract {deathcounter.%uuid of player%} from {deathcounter.%uuid of player%}