scoreboard players add @a[tag=SmallGraveActivate] KyuSmallGraveTimer 1
#reset at start
execute as @a[scores={KyuSmallGraveTimer=-14}] run execute at @s run execute as @e[type=marker,distance=..15,sort=nearest,limit=1,tag=SmallGraveKyuChest] run execute at @s positioned ~ ~-2 ~ run function zzzzdonotuse:structures/commandblocks/smallgravechest
execute as @a[scores={KyuSmallGraveTimer=-15}] run scoreboard players set @s KyuDummy5 0
execute as @a[scores={KyuSmallGraveTimer=-15}] run tag @s remove GraveSolo
execute as @a[scores={KyuSmallGraveTimer=-15}] run tag @s remove GraveDuo
execute as @a[scores={KyuSmallGraveTimer=-15}] run tag @s remove GraveTrioPlus

#give tag based on players alive
execute as @a[scores={KyuSmallGraveTimer=-15}] run execute at @a[gamemode=!spectator] run scoreboard players add @s KyuDummy5 1
execute as @a[scores={KyuSmallGraveTimer=-15}] run execute as @s[scores={KyuDummy5=1}] run tag @s add GraveSolo
execute as @a[scores={KyuSmallGraveTimer=-15}] run execute as @s[scores={KyuDummy5=2}] run tag @s add GraveDuo
execute as @a[scores={KyuSmallGraveTimer=-15}] run execute as @s[scores={KyuDummy5=3..}] run tag @s add GraveTrioPlus


#spooky
execute as @a[scores={KyuSmallGraveTimer=-8}] run effect give @s minecraft:nausea 15
execute as @a[scores={KyuSmallGraveTimer=1}] run execute at @s run playsound minecraft:block.conduit.ambient ambient @s ~ ~100 ~ 55 0.9 1
execute as @a[scores={KyuSmallGraveTimer=1}] run execute at @s run playsound minecraft:block.conduit.ambient ambient @s ~ ~100 ~ 55 0.9 1
execute as @a[scores={KyuSmallGraveTimer=1}] run execute at @s run playsound minecraft:block.conduit.ambient ambient @s ~ ~100 ~ 55 0.9 1

execute as @a[scores={KyuSmallGraveTimer=90}] run execute at @s run playsound minecraft:block.conduit.ambient ambient @s ~ ~100 ~ 55 0.9 1
execute as @a[scores={KyuSmallGraveTimer=90}] run execute at @s run playsound minecraft:block.conduit.ambient ambient @s ~ ~100 ~ 55 0.9 1
execute as @a[scores={KyuSmallGraveTimer=90}] run execute at @s run playsound minecraft:block.conduit.ambient ambient @s ~ ~100 ~ 55 0.9 1

execute as @a[scores={KyuSmallGraveTimer=100}] run effect give @s minecraft:blindness 47
execute as @a[scores={KyuSmallGraveTimer=100}] run effect give @s minecraft:resistance 47 5
execute at @a[scores={KyuSmallGraveTimer=150}] run execute at @e[type=marker,limit=1,sort=nearest,distance=..55,tag=SmallGraveKyu2] positioned ~ ~-1 ~ run fill ~-4 ~-4 ~-4 ~4 ~4 ~4 air replace minecraft:dark_oak_wall_sign
execute at @a[scores={KyuSmallGraveTimer=150}] run execute at @e[type=marker,limit=1,sort=nearest,distance=..55,tag=SmallGraveKyu2] positioned ~ ~-1 ~ run fill ~-4 ~-4 ~-4 ~4 ~4 ~4 air replace minecraft:black_candle
execute at @a[scores={KyuSmallGraveTimer=150}] run execute at @e[type=marker,limit=1,sort=nearest,distance=..55,tag=SmallGraveKyu2] positioned ~ ~-1 ~ run fill ~-4 ~-4 ~-4 ~4 ~4 ~4 air replace minecraft:polished_deepslate_wall
execute at @a[scores={KyuSmallGraveTimer=150}] run execute at @e[type=marker,limit=1,sort=nearest,distance=..55,tag=SmallGraveKyu2] positioned ~ ~-1 ~ run fill ~-4 ~4 ~-4 ~4 ~-4 ~4 air replace minecraft:peony
execute at @a[scores={KyuSmallGraveTimer=150}] run execute at @e[type=marker,limit=1,sort=nearest,distance=..55,tag=SmallGraveKyu2] positioned ~ ~-1 ~ run fill ~-1 ~-1 ~-1 ~1 ~-1 ~1 grass_block
execute at @a[scores={KyuSmallGraveTimer=150}] run execute at @e[type=marker,limit=1,sort=nearest,distance=..55,tag=SmallGraveKyu2] positioned ~ ~-1 ~ run fill ~-4 ~-4 ~-4 ~4 ~4 ~4 dirt replace minecraft:trapped_chest
execute at @a[scores={KyuSmallGraveTimer=150}] run execute at @e[type=marker,limit=1,sort=nearest,distance=..55,tag=SmallGraveKyu2] positioned ~ ~-1 ~ run fill ~-4 ~-4 ~-4 ~4 ~4 ~4 grass_block replace minecraft:coarse_dirt
execute at @a[scores={KyuSmallGraveTimer=150}] run execute at @e[type=marker,limit=1,sort=nearest,distance=..55,tag=SmallGraveKyu2] positioned ~ ~-1 ~ run kill @e[type=item,distance=..5]
execute at @a[scores={KyuSmallGraveTimer=150}] run execute as @e[type=marker,limit=1,sort=nearest,distance=..55,tag=SmallGraveKyu2] run kill @s
execute as @a[scores={KyuSmallGraveTimer=150}] run execute at @s run spreadplayers ~ ~ 25 50 false @s
execute as @a[scores={KyuSmallGraveTimer=150}] run execute at @s run playsound minecraft:ambient.cave hostile @s ~ ~200 ~ 35 2 1
execute as @a[scores={KyuSmallGraveTimer=150}] run execute at @s run playsound minecraft:ambient.cave hostile @s ~ ~200 ~ 35 2 1
execute as @a[scores={KyuSmallGraveTimer=150}] run execute at @s run playsound minecraft:ambient.cave hostile @s ~ ~200 ~ 35 2 1
execute as @a[scores={KyuSmallGraveTimer=150}] run execute at @s run playsound minecraft:ambient.cave hostile @s ~ ~200 ~ 35 2 1
execute as @a[scores={KyuSmallGraveTimer=150}] run execute at @s run playsound minecraft:ambient.cave hostile @s ~ ~200 ~ 35 2 1
execute as @a[scores={KyuSmallGraveTimer=150}] run execute at @s run playsound minecraft:ambient.cave hostile @s ~ ~200 ~ 55 0.5 1
execute as @a[scores={KyuSmallGraveTimer=150}] run execute at @s run playsound minecraft:ambient.cave hostile @s ~ ~200 ~ 55 0.5 1
execute as @a[scores={KyuSmallGraveTimer=150}] run execute at @s run playsound minecraft:ambient.cave hostile @s ~ ~200 ~ 55 0.5 1
execute as @a[scores={KyuSmallGraveTimer=150}] run execute at @s run playsound minecraft:ambient.cave hostile @s ~ ~200 ~ 55 0.5 1
execute as @a[scores={KyuSmallGraveTimer=150}] run execute at @s run playsound minecraft:ambient.cave hostile @s ~ ~200 ~ 55 0.5 1
execute as @a[scores={KyuSmallGraveTimer=150}] run execute at @s run playsound minecraft:ambient.cave hostile @s ~ ~200 ~ 55 0.5 1
execute as @a[scores={KyuSmallGraveTimer=150}] run execute at @s run playsound minecraft:ambient.cave hostile @s ~ ~200 ~ 55 0.5 1
execute as @a[scores={KyuSmallGraveTimer=150}] run execute at @s run playsound minecraft:ambient.cave hostile @s ~ ~200 ~ 55 0.5 1
execute as @a[scores={KyuSmallGraveTimer=150}] run execute at @s run playsound minecraft:ambient.cave hostile @s ~ ~200 ~ 55 0.5 1

#reset at end
execute as @a[scores={KyuSmallGraveTimer=1005}] run tag @s remove SmallGraveActivate
execute as @a[scores={KyuSmallGraveTimer=1005}] run tag @s remove GraveSolo
execute as @a[scores={KyuSmallGraveTimer=1005}] run tag @s remove GraveDuo
execute as @a[scores={KyuSmallGraveTimer=1005}] run tag @s remove GraveTrioPlus
execute if entity @a[scores={KyuSmallGraveTimer=1005}] run execute unless entity @a[scores={KyuSmallGraveTimer=..1004}] run data merge block ~ ~ ~ {auto:0b}
execute as @a[scores={KyuSmallGraveTimer=1005}] run scoreboard players set @s KyuSmallGraveTimer 0




#run text based on number of players alive
execute as @a[scores={KyuSmallGraveTimer=1..1005},tag=GraveSolo] run function zzzzdonotuse:structures/smallgrave/smallgravetimersolotext
execute as @a[scores={KyuSmallGraveTimer=1..1005},tag=GraveDuo] run execute at @s run function zzzzdonotuse:structures/smallgrave/smallgravetimerduotext
execute as @a[scores={KyuSmallGraveTimer=1..1005},tag=GraveTrioPlus] run execute at @s run function zzzzdonotuse:structures/smallgrave/smallgravetimerduotext
