Skip to content

Commit

Permalink
Rework respawn timer and spectator handling
Browse files Browse the repository at this point in the history
  • Loading branch information
fenhl committed Jul 17, 2020
1 parent 02199eb commit 238fb3e
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 16 deletions.
6 changes: 4 additions & 2 deletions data/usc/functions/prep.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ worldborder set 2901
worldborder warning time 300
# set up scoreboard
scoreboard objectives add deathsInternal deathCount
#TODO rework to start at 600 and count down once per second
scoreboard objectives add respawnTimer dummy "respawn at 12000"
scoreboard objectives add respawnTimer dummy "seconds until respawn"
scoreboard objectives add minigameScore dummy "Golden Apple minigame"
scoreboard objectives setdisplay sidebar minigameScore
scoreboard objectives add health health
Expand All @@ -24,6 +23,9 @@ scoreboard objectives add isSpectating dummy
scoreboard objectives add variables dummy
scoreboard players set enderDragonParticipates variables 0
scoreboard players set showAdvancements variables 0
scoreboard players set started variables 0
scoreboard players set gameTimer variables 0
scoreboard players set gameTimerModSec variables 0
# set up teams
team add white
team add gold
Expand Down
23 changes: 23 additions & 0 deletions data/usc/functions/second.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Runs once every second after game start.
# respawn timer
scoreboard players set @a[scores={deathsInternal=1..,health=1..},gamemode=survival] respawnTimer 600
gamemode adventure @a[scores={deathsInternal=1..,health=1..},gamemode=survival]
scoreboard players set @a[gamemode=adventure] deathsInternal 0
scoreboard players remove @a[gamemode=adventure] respawnTimer 1
tellraw @a[scores={respawnTimer=599}] {"text":"","extra":[{"text":"[USC] If you died because of a player or while in the End, you're out of the game. In that case, click ","color":"gray"},{"text":"here","underlined":true,"clickEvent":{"action":"run_command","value":"/trigger spectate set 1"}},{"text":" to spectate.","color":"gray"}]}
tellraw @a[scores={respawnTimer=540}] {"text":"","extra":[{"text":"[USC] Some suggestions while you're waiting:\n• Take a bathroom break\n• Grab some snacks\n• Remember to stay hydrated\n• Strategize\n• Hold ","color":"gray"},{"keybind":"key.playerlist","color":"gray"},{"text":" to watch players' health","color":"gray"}]}
gamemode survival @a[scores={respawnTimer=0}]
execute if entity @a[scores={respawnTimer=0}] run say @a[scores={respawnTimer=0}] respawned!
scoreboard players reset @a[gamemode=spectator] respawnTimer
scoreboard players reset @a[gamemode=survival] respawnTimer
# update respawn radius to stay inside the world border
execute if score gameTimer variables matches 0..23999 run spreadplayers 0 0 400 1300 true @a[gamemode=survival,x=-17,dx=34,y=1,dy=34,z=-17,dz=34]
execute if score gameTimer variables matches 24000..47999 run spreadplayers 0 0 350 1150 true @a[gamemode=survival,x=-17,dx=34,y=1,dy=34,z=-17,dz=34]
execute if score gameTimer variables matches 48000..71999 run spreadplayers 0 0 300 1000 true @a[gamemode=survival,x=-17,dx=34,y=1,dy=34,z=-17,dz=34]
execute if score gameTimer variables matches 72000..95999 run spreadplayers 0 0 250 850 true @a[gamemode=survival,x=-17,dx=34,y=1,dy=34,z=-17,dz=34]
execute if score gameTimer variables matches 96000..119999 run spreadplayers 0 0 200 700 true @a[gamemode=survival,x=-17,dx=34,y=1,dy=34,z=-17,dz=34]
execute if score gameTimer variables matches 120000..143999 run spreadplayers 0 0 150 550 true @a[gamemode=survival,x=-17,dx=34,y=1,dy=34,z=-17,dz=34]
execute if score gameTimer variables matches 144000..167999 run spreadplayers 0 0 100 400 true @a[gamemode=survival,x=-17,dx=34,y=1,dy=34,z=-17,dz=34]
execute if score gameTimer variables matches 168000..191999 run spreadplayers 0 0 50 250 true @a[gamemode=survival,x=-17,dx=34,y=1,dy=34,z=-17,dz=34]
execute if score gameTimer variables matches 192000..215999 run spreadplayers 0 0 25 150 true @a[gamemode=survival,x=-17,dx=34,y=1,dy=34,z=-17,dz=34]
execute if score gameTimer variables matches 216000.. run spreadplayers 0 0 10 100 true @a[gamemode=survival,x=-17,dx=34,y=1,dy=34,z=-17,dz=34]
5 changes: 2 additions & 3 deletions data/usc/functions/start.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ setidletimeout 20
execute unless score showAdvancements variables matches 1 run gamerule announceAdvancements false
# update scoreboard
scoreboard objectives setdisplay sidebar respawnTimer
# start fill clock #TODO move fill clock to functions
setblock 16 22 10 minecraft:redstone_block
# set players to Survival to scatter them
# set players to Survival and scatter them
gamemode survival @a[gamemode=adventure]
spreadplayers 0 0 400 1300 true @a[gamemode=survival]
# spawn End portal if playing against Ender dragon
execute if score enderDragonParticipates variables matches 1 run setblock 0 36 0 minecraft:structure_block[mode="load"]{mode:"LOAD",name:"usc:end_portal",ignoreEntities:1b}
execute if score enderDragonParticipates variables matches 1 run setblock 0 37 0 minecraft:redstone_block
Expand Down
1 change: 1 addition & 0 deletions data/usc/functions/start_delayed.mcfunction
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# called from start.mcfunction with a 5-second delay to allow players to fall to the ground after being scattered
scoreboard players set started variables 1
# start daylight and weather cycles
gamerule doDaylightCycle true
gamerule doWeatherCycle true
Expand Down
25 changes: 14 additions & 11 deletions data/usc/functions/tick.mcfunction
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Runs every tick.
# update respawn radius to stay inside the world border
execute if score gameTimer variables matches 0..23999 run spreadplayers 0 0 150 1300 true @a[gamemode=survival,x=-17,dx=34,y=1,dy=34,z=-17,dz=34]
execute if score gameTimer variables matches 24000..47999 run spreadplayers 0 0 150 1150 true @a[gamemode=survival,x=-17,dx=34,y=1,dy=34,z=-17,dz=34]
execute if score gameTimer variables matches 48000..71999 run spreadplayers 0 0 150 1000 true @a[gamemode=survival,x=-17,dx=34,y=1,dy=34,z=-17,dz=34]
execute if score gameTimer variables matches 72000..95999 run spreadplayers 0 0 150 850 true @a[gamemode=survival,x=-17,dx=34,y=1,dy=34,z=-17,dz=34]
execute if score gameTimer variables matches 96000..119999 run spreadplayers 0 0 150 700 true @a[gamemode=survival,x=-17,dx=34,y=1,dy=34,z=-17,dz=34]
execute if score gameTimer variables matches 120000..143999 run spreadplayers 0 0 150 550 true @a[gamemode=survival,x=-17,dx=34,y=1,dy=34,z=-17,dz=34]
execute if score gameTimer variables matches 144000..167999 run spreadplayers 0 0 150 400 true @a[gamemode=survival,x=-17,dx=34,y=1,dy=34,z=-17,dz=34]
execute if score gameTimer variables matches 168000..191999 run spreadplayers 0 0 150 250 true @a[gamemode=survival,x=-17,dx=34,y=1,dy=34,z=-17,dz=34]
execute if score gameTimer variables matches 192000..215999 run spreadplayers 0 0 150 150 true @a[gamemode=survival,x=-17,dx=34,y=1,dy=34,z=-17,dz=34]
execute if score gameTimer variables matches 216000.. run spreadplayers 0 0 150 100 true @a[gamemode=survival,x=-17,dx=34,y=1,dy=34,z=-17,dz=34]
# increment game timers and run second.mcfunction
execute if score started variables matches 1 run scoreboard players add gameTimer variables 1
execute if score started variables matches 1 run scoreboard players add gameTimerModSec variables 1
execute if score gameTimerModSec matches 20 run function usc:second
execute if score gameTimerModSec matches 20 run scoreboard players set gameTimerModSec variables 0
# handle spectators
scoreboard players enable @a[gamemode=adventure] spectate
scoreboard players enable @a[gamemode=survival] spectate
tellraw @a[scores={spectate=1..}] {"text":"","extra":[{"text":"[USC] Please mute yourself, or leave your team call, or leave the game.","color":"gray"}]}
gamemode spectator @a[scores={spectate=1..}]
scoreboard players set @a[gamemode=spectator] spectate 0
#TODO remove isSpectating objective and replace with gamemode checks
scoreboard players set @a[gamemode=spectator] isSpectating 1
scoreboard players set @a[gamemode=!spectator] isSpectating 0
Binary file modified data/usc/structures/bne.nbt
Binary file not shown.
Binary file modified data/usc/structures/bse.nbt
Binary file not shown.
Binary file modified data/usc/structures/tse.nbt
Binary file not shown.

0 comments on commit 238fb3e

Please sign in to comment.