
#join leave detection
scoreboard players operation @a login_id -= .total login_id
execute @a[scores={login_id=1..}] ~ ~ ~ function login
execute @a[scores={login_id=..-1}] ~ ~ ~ function login

scoreboard players add .total login_id 1
scoreboard players operation @a login_id = .total login_id

execute @a[scores={login_id=100000000..}] ~ ~ ~ scoreboard players set @a login_id 1
execute @a[scores={login_id=100000000..}] ~ ~ ~ scoreboard players set .total login_id 1



#check start
execute @a ~ ~ ~ detect ~ ~-1 ~ concrete 15 execute @e[tag=dummy,scores={ingame=0}] ~ ~ ~ function startcheck
scoreboard players add @a titledelay 0
scoreboard players remove @a[scores={titledelay=1..}] titledelay 1





#tickingame
execute @e[tag=dummy,scores={ingame=2}] ~ ~ ~ function tick_frozen
execute @e[tag=dummy,scores={ingame=1}] ~ ~ ~ function tick_ingame




#spectator
execute @e[tag=dummy,scores={ingame=0}] ~ ~ ~ titleraw @a[tag=spectator] actionbar {"rawtext": [{"text": "§7You're a spectator!"}]}
event entity @a stop_spectating
execute @e[tag=dummy,scores={ingame=1..2}] ~ ~ ~ event entity @a[tag=spectator] start_spectating




#kill item
kill @e[type=item]



#effect
effect @a instant_health 1 9 true



#scoreboard
scoreboard objectives setdisplay belowname
scoreboard objectives setdisplay belowname wins
scoreboard players remove @e[tag=dummy,scores={resetlb=0..}] resetlb 1
scoreboard players set @e[tag=dummy,scores={resetlb=21}] resetlb 0
execute @e[tag=dummy,scores={resetlb=0}] ~ ~ ~ clone 112 20 -75 112 20 -75 109 21 -75



#scoreboard leaderboard
scoreboard players reset * leaderboard
scoreboard players add @a leaderboard 0
execute @a ~ ~ ~ scoreboard players operation @s leaderboard = @s wins

#stop game if left during startanimation
execute @e[tag=dummy,scores={ingame=2,startanimation=1..}] ~ ~ ~ function stop



#blockinteract other
tag @e[tag=blockinteract] add killmeinteract
execute @a[tag=spectator] ~ ~1.5 ~ execute @e[tag=blockinteract,r=1] ~ ~ ~ tag @s remove killmeinteract
execute @e[type=cero:blockinteract,tag=killmeinteract] ~ ~ ~ function blockinteract_kill