execute if entity @a[name=TheMisterTEHEK] run time set 0
tp @a[x=-34,y=96,z=36,dx=68,dy=2,dz=-70] -2 42 0 -90 -15

execute as @a unless score @s left matches 0.. run scoreboard players set @s left 1
execute as @a[scores={left=1..}] run function ws:misc/discord
execute as @a[scores={discord.disable=1}] run function ws:misc/nodiscord

execute at @e[type=item,nbt={OnGround:1b,Item:{components:{"minecraft:custom_data":{cube:1}}}}] run summon lightning_bolt ~ ~ ~
effect give @a[nbt={Inventory:[{components:{"minecraft:custom_data":{cube:1}}}]}] resistance 1 255 true

gamemode adventure @a[gamemode=survival]
kill @e[type=minecraft:experience_orb]
experience set @a 0 levels
experience set @a 0 points

function ws:misc/spawn/antilag

execute as @a[scores={treadmill.death=1..,treadmill.level=2..}] run function ws:misc/gym/treadmilllost 
execute as @a[scores={treadmill.death=1..,weight.level=2..}] run function ws:misc/gym/weightlost
execute as @a[scores={treadmill.death=1..}] run function ws:misc/stats/itemstatslose
scoreboard players reset @a[scores={treadmill.death=1..}] treadmill.death

execute as @e[type=interaction,tag=casino.button] if data entity @s interaction run function ws:misc/casino/casinobuttons
execute as @a[nbt={Inventory:[{components:{"minecraft:custom_data":{chip:1}}}]}] if items entity @s weapon.* stone[custom_data~{chip:1}] run title @s actionbar [{"translate":"casino.chip.showbalance","bold":true},{"color":"dark_red","score":{"name":"*","objective":"casino.chips"}}]
execute as @e[type=interaction,tag=casino.play,scores={casino.slot_machine.process=0}] if data entity @s interaction run function ws:misc/casino/slot_machine.play
execute as @e[type=interaction,tag=casino.play,scores={casino.slot_machine.process=1..}] run function ws:misc/casino/slot_machine.process

execute at @e[type=marker,tag=bum.spawn] run function ws:misc/spawn/bum
execute at @e[type=marker,tag=civ.spawn] run function ws:misc/spawn/civ

execute as @e[type=interaction,tag=shop.button] if data entity @s interaction run function ws:store/unishop/buy with entity @s Passengers[].data
execute as @e[type=interaction,tag=interior.button] if data entity @s interaction run function ws:store/interior/macro with entity @s Passengers[].data
function ws:store/unishop/music
execute as @a if items entity @s weapon.offhand *[minecraft:custom_data~{statchanger:1}] run function ws:misc/stats/item with entity @s Inventory[{Slot:-106b}].components."minecraft:custom_data"

clear @a[team=!stroitel] *[minecraft:custom_data~{clearbuilder:1}]
clear @a[team=!fermer] golden_hoe[minecraft:custom_data~{hoe:1}]
clear @a[team=!ribak] fishing_rod[minecraft:custom_data~{rod:1}]
clear @a[team=!gardener] shears 
clear @a[team=!maid] melon[custom_data~{broom:1}]
clear @a[team=!maid] melon[custom_data~{mop:1}] 
clear @a[team=!miner] golden_pickaxe
kill @e[type=minecraft:item,nbt={Item:{components:{"minecraft:custom_data":{rod:1}}}}]
kill @e[type=minecraft:item,nbt={Item:{components:{"minecraft:custom_data":{clearbuilder:1}}}}]
kill @e[type=item,nbt={Item:{id:"minecraft:item_frame"}}]
kill @e[type=arrow,nbt={inGround:1b}]
function ws:misc/health/tick
execute as @e[tag=terminal.button,type=interaction] run function ws:misc/terminal/banktocash/tick
function ws:misc/cinema/leave
function ws:misc/eventor/tick
execute as @a[scores={tutor=1..}] run function ws:misc/tutorial/tick

function ws:misc/gym/gymtick
execute as @a unless score @s treadmill.level matches 1.. run scoreboard players set @s treadmill.level 1
execute as @a unless score @s weight.level matches 1.. run scoreboard players set @s weight.level 1

execute if entity @a[team=gruzchik] run function ws:work/tick/loader
function ws:work/tick/scavenger
execute if entity @a[team=povar] run function ws:work/tick/chef
execute as @a[team=stroitel] if entity @s run function ws:work/tick/builder
execute if entity @a[team=fermer] run function ws:work/tick/farmer
execute if entity @a[team=ribak] run function ws:work/tick/fisherman
execute if entity @a[team=seller] run function ws:work/tick/producer

advancement grant @a[x=-1989,y=41,z=-2126,dx=8,dy=4,dz=66,advancements={ws:workersimulator/oldblood=false},team=!gruzchik] only ws:workersimulator/oldblood

execute if entity @a[team=gardener] run function ws:work/tick/tier2/gardener
execute if entity @a[team=maid] run function ws:work/tick/tier2/maid
execute if entity @a[team=miner] run function ws:work/tick/tier2/miner
execute if entity @a[team=scientist] run function ws:work/tick/tier2/scientist
execute if entity @a[team=banker] run function ws:work/tick/tier2/banker

scoreboard players remove @a[scores={banker.work.cd=1..}] banker.work.cd 1

execute if entity @a[tag=mafioz] run function ws:misc/mafia/tick
execute if entity @a[tag=police] run function ws:misc/police/tick
scoreboard players reset @a police.bomj
scoreboard players reset @a police.killed
scoreboard players reset @a mafioz.died

execute if entity @a[scores={authority=1..}] unless entity @e[tag=race,scores={race.timer=1..}] run scoreboard objectives setdisplay sidebar authority
execute unless entity @a[scores={authority=1..}] unless entity @e[tag=race,scores={race.timer=1..}] run scoreboard objectives setdisplay sidebar

execute as @a[scores={reset.prof=1..}] run function ws:misc/workdeath

execute as @a[scores={businesscount=1..}] if entity @s run function ws:misc/income/tick

function ws:misc/quest/check

clear @a *[minecraft:custom_data~{kill:1}]
kill @e[type=minecraft:item,nbt={Item:{components:{"minecraft:custom_data":{kill:1}}}}]
execute as @a[nbt={OnGround:1b,Inventory:[{Slot:-106b,components:{"minecraft:custom_data":{carkey:1}}}]}] at @s run function ws:item/carkey/tick

execute as @e[tag=car,type=horse] if items entity @s armor.body diamond_horse_armor[minecraft:custom_data~{upgrade:1}] on passengers run advancement grant @s only ws:workersimulator/carupgrade
execute as @e[tag=car,type=horse] if items entity @s horse.saddle *[minecraft:custom_data~{upgrade:1}] run function ws:item/engine/tick
execute as @a[scores={speed=1..}] run function ws:misc/smoke

execute as @a[tag=!drug.used,nbt={Inventory:[{Slot:-106b,components:{"minecraft:custom_data":{drug:1}}}]}] run function ws:item/drug/tick
execute as @a[tag=drug.used] unless items entity @s weapon.offhand *[minecraft:custom_data~{drug:1}] run tag @s remove drug.used

execute as @e[type=interaction,tag=seat] if data entity @s interaction run function ws:misc/sit with entity @s interaction
execute as @a[predicate=ws:seat] run function ws:misc/displaysit

execute as @a unless score @s income matches 0.. run scoreboard players set @s income 0
execute as @a unless score @s pay.max matches 0.. run scoreboard players set @s pay.max 0
execute as @a if score @s pay.max < @s pay run scoreboard players operation @s pay.max = @s pay
execute as @a run function ws:misc/totalpay/tick
execute as @a[nbt={Inventory:[{components:{"minecraft:custom_data":{passport:1}}}]}] run function ws:misc/passport/check

execute as @e[tag=movie,scores={movie=1..},type=marker] run function ws:misc/cinema/movie with entity @s data

function ws:misc/gun/tick
execute as @a[scores={stat.laserdance=1..}] run function ws:item/laserdance/tick
execute as @a[scores={money_timer.use=1..}] if items entity @s weapon.* minecraft:carrot_on_a_stick[minecraft:custom_data~{money_timer:1}] run function ws:item/money_timer/use
scoreboard players reset @a[scores={money_timer.use=1..}] money_timer.use
execute as @a[tag=money_timer] run function ws:item/money_timer/tick
execute as @a[scores={carrotscrep=1..}] if items entity @s weapon.* minecraft:carrot_on_a_stick[minecraft:custom_data~{staple:1}] run function ws:item/staple/disassemble
scoreboard players reset @a[scores={carrotscrep=1..}] carrotscrep
execute as @e[type=item,nbt={Item:{components:{"minecraft:custom_data":{passport:1}}}}] run function ws:misc/passport/setpos

execute as @e[tag=slide,type=interaction] on passengers run scoreboard players set @s slide 1
execute as @a[scores={slide=1..}] run function ws:misc/slide
scoreboard players add @a[scores={slide=1..}] slide 1

execute as @a[scores={pizzaopen=1..}] run function ws:item/ron/check

execute as @e[tag=bloodunit,type=interaction] if data entity @s interaction run function ws:misc/bloodunit
execute as @e[tag=klocek,type=interaction] if data entity @s interaction run function ws:misc/klocek