scoreboard players set @a stats_divide_by_10 10
scoreboard players set @a credit_conversion_rate 20

data merge entity @e[type=text_display,tag=limitbreak_text_display_total_runs,limit=1] {billboard:"fixed",alignment:"center",Tags:["limitbreak_text_display_total_runs"],transformation:{left_rotation:[0f,1f,0f,0f],right_rotation:[0f,0f,0f,1f],translation:[0f,0f,0f],scale:[1f,1f,1f]},text:'[{"bold":true,"color":"green","italic":false,"text":"Total Runs:  "},{"bold":true,"color":"green","italic":false,"score":{"name":"world","objective":"RunCounter"}}]',background:16777215}
data merge entity @e[type=text_display,tag=limitbreak_text_display_highest_wave_reached,limit=1] {billboard:"fixed",alignment:"center",Tags:["limitbreak_text_display_highest_wave_reached"],transformation:{left_rotation:[0f,1f,0f,0f],right_rotation:[0f,0f,0f,1f],translation:[0f,0f,0f],scale:[1f,1f,1f]},text:'[{"bold":true,"color":"red","italic":false,"text":"Highest Wave Reached: "},{"bold":true,"italic":false,"score":{"name":"world","objective":"HighestWaveReached"}}]',background:16777215}
data merge entity @e[type=text_display,tag=limitbreak_text_display_total_deaths,limit=1] {billboard:"fixed",alignment:"center",Tags:["limitbreak_text_display_total_deaths"],transformation:{left_rotation:[0f,1f,0f,0f],right_rotation:[0f,0f,0f,1f],translation:[0f,0f,0f],scale:[1f,1f,1f]},text:'[{"bold":true,"color":"gray","italic":false,"text":"Total Deaths: "},{"bold":true,"color":"gray","italic":false,"score":{"name":"world","objective":"TotalDeaths"}}]',background:16777215}

execute unless score world Run_Active matches 1 run effect give @a saturation infinite 255 true
execute unless score world Run_Active matches 1 run effect give @a regeneration infinite 255 true

scoreboard players reset $temp StorageCount
execute as @a unless score @s PlayerJoined matches 1.. run function kiwi2:give_storage_score
scoreboard players set @a PlayerJoined 1

execute unless score world player_leave = world MultiplayerScaling if score world MultiplayerScaling matches 1 run tellraw @a [{"text": "Multiplayer Scaling [1 Player]: "},{"text": "+100% HP", "color": "green"}]
execute unless score world player_leave = world MultiplayerScaling if score world MultiplayerScaling matches 2 run tellraw @a [{"text": "Multiplayer Scaling [2 Player]: "},{"text": "+50% HP", "color": "green"}]
execute unless score world player_leave = world MultiplayerScaling if score world MultiplayerScaling matches 3 run tellraw @a [{"text": "Multiplayer Scaling [3 Player]: "},{"text": "+40% HP", "color": "green"}]
execute unless score world player_leave = world MultiplayerScaling if score world MultiplayerScaling matches 4 run tellraw @a [{"text": "Multiplayer Scaling [4 Player]: "},{"text": "+20% HP", "color": "green"}]
execute unless score world player_leave = world MultiplayerScaling if score world MultiplayerScaling matches 5 run tellraw @a [{"text": "Multiplayer Scaling [5 Player]: "},{"text": "No effects", "color": "gray"}]
execute unless score world player_leave = world MultiplayerScaling if score world MultiplayerScaling matches 6 run tellraw @a [{"text": "Multiplayer Scaling [6 Player]: "},{"text": "-20% HP", "color": "red"}]
execute unless score world player_leave = world MultiplayerScaling if score world MultiplayerScaling matches 7 run tellraw @a [{"text": "Multiplayer Scaling [7 Player]: "},{"text": "-40% HP", "color": "red"}]
execute unless score world player_leave = world MultiplayerScaling if score world MultiplayerScaling matches 8.. run tellraw @a [{"text": "Multiplayer Scaling [>= 8 Player]: "},{"text": "-50% HP", "color": "red"}]

execute unless score world player_leave = world MultiplayerScaling as @a run attribute @s max_health modifier remove multiplayer_scaling_health
execute store result score world player_leave run scoreboard players get world MultiplayerScaling

scoreboard players reset world MultiplayerScaling
execute as @a run scoreboard players add world MultiplayerScaling 1
scoreboard players enable @a ClassInfo

execute if score world MultiplayerScaling matches 1 as @a run attribute @s max_health modifier add multiplayer_scaling_health 1 add_multiplied_base
execute if score world MultiplayerScaling matches 2 as @a run attribute @s max_health modifier add multiplayer_scaling_health 0.5 add_multiplied_base
execute if score world MultiplayerScaling matches 3 as @a run attribute @s max_health modifier add multiplayer_scaling_health 0.4 add_multiplied_base
execute if score world MultiplayerScaling matches 4 as @a run attribute @s max_health modifier add multiplayer_scaling_health 0.2 add_multiplied_base
execute if score world MultiplayerScaling matches 6 as @a run attribute @s max_health modifier add multiplayer_scaling_health -0.2 add_multiplied_base
execute if score world MultiplayerScaling matches 7 as @a run attribute @s max_health modifier add multiplayer_scaling_health -0.4 add_multiplied_base
execute if score world MultiplayerScaling matches 8.. as @a run attribute @s max_health modifier add multiplayer_scaling_health -0.5 add_multiplied_base

scoreboard players reset world OneSecondTimer