Decrease lives when a player dies

Decrease lives when a player dies - Retro turntable playing vinyl disc in living room

I'm working on a mini-game that requires lives. I set up the scoreboards that show the lives on the sidebar, as shown here -enter image description here

I set up that board by adding a deathcount objective and then dummied it by adding a dummy objective for it that replaces it on the sidebar. I want to find out how to made that number decrease for any player that has died. Also I would like to how to put a player into spectator mode a player reaches zero "lives."

These are the scoreboard commands (in order) that sets them up.

scoreboard objectives add Deaths deathCount
scoreboard objectives add Lives dummy
scoreboard objectives setdisplay sidebar Lives
scoreboard players set @a Lives 5


Best Answer

First, add the lives count objective (for display) and the death count objective (for behind the scenes):

/scoreboard objectives add lives dummy Lives
/scoreboard objectives add deaths Deathcount

Then wire these up to a redstone clock:

/scoreboard scoreboard players set * lives 5
/scoreboard players operation @a lives -= @a deaths
/gamemode 3 @a[score_deaths_min=5]
/scoreboard players set @a[playerGameType=3] deaths 0

Make sure the first two lines are executed in that order, otherwise players will always have what looks like 5 lives.
Note: I have not tested this, so there are probably some bugs in it.

Lives will then be the number of lives remaining, which you can display wherever you want to.




Pictures about "Decrease lives when a player dies"

Decrease lives when a player dies - Interior of stylish living room with comfortable couch placed near shelf with collection of vintage vinyl records and wooden cabinet decorated with classic table lamp
Decrease lives when a player dies - High angle of crop anonymous female pianist sitting at piano and pressing keys while practicing music
Decrease lives when a player dies - Vintage vinyl record player placed on table against wall with blurred photos of musicians in light living room





Football Players who nearly DIED on the field | Tragic Moments




Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Matthias Groeneveld, Charlotte May, Charles Parker, Matthias Groeneveld