;-------------------------
; FIX: MISSING TARGETNAME
;-------------------------
modify:
{
	match:
	{
		"classname" "trigger_multiple"
		"hammerid" "981784"
		"origin" "754 -7593 1114"
	}
	insert:
	{
		"targetname" "zm_cage_filter_set"
	}
}
;---------------------------------
; FIX: KILL ZOMBIES CAGE TRIGGER
;---------------------------------
modify:
{
	match:
	{
		"targetname" "boss_hpcounter"
		"classname" "math_counter"
		"hammerid" "159140"
	}
	insert:
	{
		"OnHitMax" "zm_cage_filter_set,Kill,,0,-1"
	}
}
;---------------------------------
; FIX: TELEPORTS ISSUES WITH ZMS
;---------------------------------
modify:
{
	match:
	{
		"origin" "449 717 689"
		"targetname" "relay_level2"
		"classname" "logic_relay"
		"hammerid" "254790"
	}
	delete:
	{
		"OnTrigger" "trigger_breakable_4,AddOutput,OnStartTouch trigger_teleport_all_1:SetRemoteDestination:teleport_destination_level2:0.00:1,0,-1"
		"OnTrigger" "trigger_breakable_4,AddOutput,OnStartTouch trigger_teleport_all_2:Enable::10.00:1,0,-1"
		"OnTrigger" "trigger_breakable_4,AddOutput,OnStartTouch trigger_teleport_all_2:SetRemoteDestination:teleport_destination_level2:0.00:1,0,-1"
		"OnTrigger" "trigger_breakable_4,AddOutput,OnStartTouch trigger_teleport_all_1:Enable::10.00:1,0,-1"
	}
}
modify:
{
	match:
	{
		"model" "*274"
		"targetname" "trigger_breakable_4"
		"origin" "226 -4192 271"
		"classname" "trigger_once"
		"hammerid" "247602"
	}
	insert:
	{
		"OnStartTouch" "trigger_teleport_all_1,AddOutput,target teleport_destination_level2,,0,1"
		"OnStartTouch" "trigger_teleport_all_2,Enable,,10,1"
		"OnStartTouch" "trigger_teleport_all_2,AddOutput,target teleport_destination_level2,,0,1"
		"OnStartTouch" "trigger_teleport_all_1,Enable,,10,1"
	}
}

;----------------------------------------------------------------------------------------
; Fixes issue with models/trigger_teleport to close to play area to trigger ending fast
;----------------------------------------------------------------------------------------
modify:
{
	match:
	{
		"targetname" "trigger_teleport_7"
		"classname" "trigger_teleport"
	}
	replace:
	{
		"origin" "-607.5 -6329 17.5"
	}
}

;------------------------------------------------------
; FIX: REPLACE PHYSICS LEVEL SYSTEM WITH PERM ENTITIES
;------------------------------------------------------
;Remove old entites
;------------------
filter:
{
	"classname" "func_brush"
	"targetname" "/level(1|1_1|2|2_1|3|3_1|4|4_1|5)_brush/"
}
filter:
{
	"classname" "func_physbox"
	"targetname" "/level(1|1_1|2|2_1|3|3_1|4|4_1|5)_box/"
}
filter:
{
	"classname" "trigger_once"
	"targetname" "/level(1|1_1|2|2_1|3|3_1|4|4_1|5)_trigger/"
}
filter:
{
	"classname" "logic_relay"
	"targetname" "level_box_break"
}

;-----------------------------
; Create the new level system
;-----------------------------
add:
{
	"classname" "info_target"
	"targetname" "Stage_CounterInit"
	"spawnflags" "0"
	"OnUser1" "Stage_CounterTemplate,ForceSpawn,,0,1"
	"OnUser1" "Stage_Counter,AddOutput,classname info_target,0.03,1"
	"OnUser1" "!self,Kill,,0.06,1"
}

add:
{
	"classname" "point_template"
	"targetname" "Stage_CounterTemplate"
	"Template01" "Stage_Counter"
	"spawnflags" "2"
}

add:
{
	"classname" "math_counter"
	"targetname" "Stage_Counter"
	"startvalue" "1"
	"StartDisabled" "0"
	"min" "1"
	"max" "9"
	"OnGetValue" "Stage_Case,InValue,,0,-1"
}

add:
{
	"classname" "logic_case"
	"targetname" "Stage_Case"
	"Case01" "1"
	"Case02" "2"
	"Case03" "3"
	"Case04" "4"
	"Case05" "5"
	"Case06" "6"
	"Case07" "7"
	"Case08" "8"
	"Case09" "9"
	"OnCase01" "relay_level1,Trigger,,0,-1"
	"OnCase02" "relay_level1_1,Trigger,,0,-1"
	"OnCase03" "relay_level2,Trigger,,0,-1"
	"OnCase04" "relay_level2_1,Trigger,,0,-1"
	"OnCase05" "relay_level3,Trigger,,0,-1"
	"OnCase06" "relay_level3_1,Trigger,,0,-1"
	"OnCase07" "relay_level4,Trigger,,0,-1"
	"OnCase08" "relay_level4_1,Trigger,,0,-1"
	"OnCase09" "relay_level5,Trigger,,0,-1"
}

modify:
{
	match:
	{
		"classname" "logic_auto"
	}
	insert:
	{
		"OnMapSpawn" "Stage_CounterInit,FireUser1,,0,1"
		"OnMapSpawn" "Stage_Counter,GetValue,,0.02,1"
		"OnMapSpawn" "bosscase,FireUser1,,0.05,1"
	}
}

;--------------------------
; Adjust adminroom buttons
;--------------------------
modify:
{
	match:
	{
		"classname" "func_button"
		"targetname" "tolevel1_button"
	}
	delete:
	{
		"OnPressed" "tolevel1_break,Break,,0,-1"
		"OnPressed" "level1_brush,Disable,,0,-1"
		"OnPressed" "level2_brush,Enable,,0,-1"
		"OnPressed" "level3_brush,Enable,,0,-1"
		"OnPressed" "level4_brush,Enable,,0,-1"
		"OnPressed" "level1_1_brush,Enable,,0,-1"
		"OnPressed" "level2_1_brush,Enable,,0,-1"
		"OnPressed" "level3_1_brush,Enable,,0,-1"
		"OnPressed" "level4_1_brush,Enable,,0,-1"
		"OnPressed" "level5_brush,Enable,,0,-1"
	}
	insert:
	{
		"OnPressed" "Stage_Counter,SetValue,1,0,-1"
	}
}

modify:
{
	match:
	{
		"classname" "func_button"
		"targetname" "tolevel1_1_button"
	}
	delete:
	{
		"OnPressed" "tolevel1_1_break,Break,,0,-1"
		"OnPressed" "level4_brush,Enable,,0,-1"
		"OnPressed" "level4_1_brush,Enable,,0,-1"
		"OnPressed" "level3_brush,Enable,,0,-1"
		"OnPressed" "level3_1_brush,Enable,,0,-1"
		"OnPressed" "level2_brush,Enable,,0,-1"
		"OnPressed" "level2_1_brush,Enable,,0,-1"
		"OnPressed" "level1_brush,Enable,,0,-1"
		"OnPressed" "level1_1_brush,Disable,,0,-1"
		"OnPressed" "level5_brush,Enable,,0,-1"
	}
	insert:
	{
		"OnPressed" "Stage_Counter,SetValue,2,0,-1"
	}
}

modify:
{
	match:
	{
		"classname" "func_button"
		"targetname" "tolevel2_button"
	}
	delete:
	{
		"OnPressed" "tolevel2_break,Break,,0,-1"
		"OnPressed" "level1_1_brush,Enable,,0,-1"
		"OnPressed" "level1_brush,Enable,,0,-1"
		"OnPressed" "level2_1_brush,Enable,,0,-1"
		"OnPressed" "level2_brush,Disable,,0,-1"
		"OnPressed" "level3_1_brush,Enable,,0,-1"
		"OnPressed" "level3_brush,Enable,,0,-1"
		"OnPressed" "level4_1_brush,Enable,,0,-1"
		"OnPressed" "level4_brush,Enable,,0,-1"
		"OnPressed" "level5_brush,Enable,,0,-1"
	}
	insert:
	{
		"OnPressed" "Stage_Counter,SetValue,3,0,-1"
	}
}

modify:
{
	match:
	{
		"classname" "func_button"
		"targetname" "tolevel2_1_button"
	}
	delete:
	{
		"OnPressed" "tolevel2_1_break,Break,,0,-1"
		"OnPressed" "level1_1_brush,Enable,,0,-1"
		"OnPressed" "level1_brush,Enable,,0,-1"
		"OnPressed" "level2_1_brush,Disable,,0,-1"
		"OnPressed" "level2_brush,Enable,,0,-1"
		"OnPressed" "level3_1_brush,Enable,,0,-1"
		"OnPressed" "level3_brush,Enable,,0,-1"
		"OnPressed" "level4_1_brush,Enable,,0,-1"
		"OnPressed" "level4_brush,Enable,,0,-1"
		"OnPressed" "level5_brush,Enable,,0,-1"
	}
	insert:
	{
		"OnPressed" "Stage_Counter,SetValue,4,0,-1"
	}
}

modify:
{
	match:
	{
		"classname" "func_button"
		"targetname" "tolevel3_button"
	}
	delete:
	{
		"OnPressed" "level4_brush,Enable,,0,-1"
		"OnPressed" "level4_1_brush,Enable,,0,-1"
		"OnPressed" "level3_brush,Disable,,0,-1"
		"OnPressed" "level3_1_brush,Enable,,0,-1"
		"OnPressed" "level2_brush,Enable,,0,-1"
		"OnPressed" "level2_1_brush,Enable,,0,-1"
		"OnPressed" "level1_brush,Enable,,0,-1"
		"OnPressed" "level1_1_brush,Enable,,0,-1"
		"OnPressed" "tolevel3_break,Break,,0,-1"
		"OnPressed" "level5_brush,Enable,,0,-1"
	}
	insert:
	{
		"OnPressed" "Stage_Counter,SetValue,5,0,-1"
	}
}

modify:
{
	match:
	{
		"classname" "func_button"
		"targetname" "tolevel3_1_button"
	}
	delete:
	{
		"OnPressed" "tolevel3_1_break,Break,,0,-1"
		"OnPressed" "level1_1_brush,Enable,,0,-1"
		"OnPressed" "level1_brush,Enable,,0,-1"
		"OnPressed" "level2_1_brush,Enable,,0,-1"
		"OnPressed" "level2_brush,Enable,,0,-1"
		"OnPressed" "level3_1_brush,Disable,,0,-1"
		"OnPressed" "level3_brush,Enable,,0,-1"
		"OnPressed" "level4_1_brush,Enable,,0,-1"
		"OnPressed" "level4_brush,Enable,,0,-1"
		"OnPressed" "level5_brush,Enable,,0,-1"
	}
	insert:
	{
		"OnPressed" "Stage_Counter,SetValue,6,0,-1"
	}
}

modify:
{
	match:
	{
		"classname" "func_button"
		"targetname" "tolevel4_button"
	}
	delete:
	{
		"OnPressed" "tolevel4_break,Break,,0,-1"
		"OnPressed" "level1_1_brush,Enable,,0,-1"
		"OnPressed" "level1_brush,Enable,,0,-1"
		"OnPressed" "level2_1_brush,Enable,,0,-1"
		"OnPressed" "level2_brush,Enable,,0,-1"
		"OnPressed" "level3_1_brush,Enable,,0,-1"
		"OnPressed" "level3_brush,Enable,,0,-1"
		"OnPressed" "level4_1_brush,Enable,,0,-1"
		"OnPressed" "level4_brush,Disable,,0,-1"
		"OnPressed" "level5_brush,Enable,,0,-1"
	}
	insert:
	{
		"OnPressed" "Stage_Counter,SetValue,7,0,-1"
	}
}

modify:
{
	match:
	{
		"classname" "func_button"
		"targetname" "tolevel4_1_button"
	}
	delete:
	{
		"OnPressed" "tolevel4_1_break,Break,,0,-1"
		"OnPressed" "level1_1_brush,Enable,,0,-1"
		"OnPressed" "level1_brush,Enable,,0,-1"
		"OnPressed" "level2_1_brush,Enable,,0,-1"
		"OnPressed" "level2_brush,Enable,,0,-1"
		"OnPressed" "level3_1_brush,Enable,,0,-1"
		"OnPressed" "level3_brush,Enable,,0,-1"
		"OnPressed" "level4_1_brush,Disable,,0,-1"
		"OnPressed" "level4_brush,Enable,,0,-1"
		"OnPressed" "level5_brush,Enable,,0,-1"
	}
	insert:
	{
		"OnPressed" "Stage_Counter,SetValue,8,0,-1"
	}
}

modify:
{
	match:
	{
		"classname" "func_button"
		"targetname" "tolevel5_button"
	}
	delete:
	{
		"OnPressed" "tolevel5_break,Break,,0,-1"
		"OnPressed" "level1_1_brush,Enable,,0,-1"
		"OnPressed" "level1_brush,Enable,,0,-1"
		"OnPressed" "level2_1_brush,Enable,,0,-1"
		"OnPressed" "level2_brush,Enable,,0,-1"
		"OnPressed" "level3_1_brush,Enable,,0,-1"
		"OnPressed" "level3_brush,Enable,,0,-1"
		"OnPressed" "level4_1_brush,Enable,,0,-1"
		"OnPressed" "level4_brush,Enable,,0,-1"
		"OnPressed" "level5_brush,Disable,,0,-1"
	}
	insert:
	{
		"OnPressed" "Stage_Counter,SetValue,9,0,-1"
	}
}

;------------------------------------------------
; Redirecting triggers inputs to existing relays
; Init level with the new system
; Handle all stages level changes in case of win
;------------------------------------------------
; Stage 1
modify:
{
	match:
	{
		"targetname" "relay_level1"
		"classname" "logic_relay"
	}
	delete:
	{
		"OnTrigger" "score_trigger,AddOutput,OnStartTouch level1_brush:Enable::0.00:1,0,-1"
		"OnTrigger" "score_trigger,AddOutput,OnStartTouch level1_1_brush:Disable::0.00:1,0,-1"
		"OnTrigger" "script,RunScriptCode,initRound(),0,-1"
	}
	insert:
	{
		"OnTrigger" "score_trigger,AddOutput,OnStartTouch Stage_Counter:SetValue:2:0.00:1,0,-1"
		"OnTrigger" "breakable_1_level4,Break,,0,-1"
		"OnTrigger" "movelinear,Kill,,0,-1"
		"OnTrigger" "wall_level1,Toggle,,0,-1"
		"OnTrigger" "heal_hurt,AddOutput,OnHurtPlayer !activator:AddOutput:health 100:0.00:0,1,-1"
		"OnTrigger" "heal2_hurt,AddOutput,OnHurtPlayer !activator:AddOutput:health 100:0.00:0,1,-1"
	}
}

; Stage 1 - Extra
modify:
{
	match:
	{
		"classname" "logic_relay"
		"targetname" "relay_level1_1"
	}
	insert:
	{
		"OnTrigger" "extra1_score,AddOutput,OnStartTouch Stage_Counter:SetValue:3:0.01:1,0,-1"
	}
}

; Stage 2
modify:
{
	match:
	{
		"targetname" "relay_level2"
		"classname" "logic_relay"
	}
	delete:
	{
		"OnTrigger" "score_trigger,AddOutput,OnStartTouch level2_brush:Enable::0.00:1,0,-1"
		"OnTrigger" "score_trigger,AddOutput,OnStartTouch level2_1_brush:Disable::0.00:1,0,-1"
	}
	insert:
	{
		"OnTrigger" "score_trigger,AddOutput,OnStartTouch Stage_Counter:SetValue:4:0.00:1,0,-1"
		"OnTrigger" "trigger_teleport_3,Disable,,0,-1"
		"OnTrigger" "wall4_level2,Toggle,,0,-1"
		"OnTrigger" "wall5_level2,Toggle,,0,-1"
		"OnTrigger" "trigger_breakable_2,Disable,,0,-1"
		"OnTrigger" "wall7_level2,Toggle,,0,-1"
		"OnTrigger" "trigger_teleport_4,Disable,,0,-1"
		"OnTrigger" "wall8_level2,Toggle,,0,-1"
		"OnTrigger" "breakable_1_level4,Break,,0,-1"
		"OnTrigger" "movelinear,Kill,,0,-1"
		"OnTrigger" "trigger_level2_1,Enable,,0,-1"
		"OnTrigger" "wall_level1,Toggle,,0,-1"
		"OnTrigger" "counter_bosshp,SetValue,300,0,-1"
		"OnTrigger" "wall22,Toggle,,0,-1"
		"OnTrigger" "heal_hurt,AddOutput,OnHurtPlayer !activator:AddOutput:health 150:0.00:0,1,-1"
		"OnTrigger" "speed_relay_level24,Trigger,,0,-1"
		"OnTrigger" "heal2_hurt,AddOutput,OnHurtPlayer !activator:AddOutput:health 150:0.00:0,1,-1"
	}
}

; Stage 2 - Extra
modify:
{
	match:
	{
		"classname" "logic_relay"
		"targetname" "relay_level2_1"
	}
	insert:
	{
		"OnTrigger" "extra2_win_filter,AddOutput,OnPass Stage_Counter:SetValue:5:0.01:1,0,-1"
	}
}

; Stage 3
modify:
{
	match:
	{
		"targetname" "relay_level3"
		"classname" "logic_relay"
	}
	delete:
	{
		"OnTrigger" "score_trigger,AddOutput,OnStartTouch level3_brush:Enable::0.00:1,0,-1"
		"OnTrigger" "score_trigger,AddOutput,OnStartTouch level3_1_brush:Disable::0.00:1,0,-1"
	}
	insert:
	{
		"OnTrigger" "score_trigger,AddOutput,OnStartTouch Stage_Counter:SetValue:6:0.00:1,0,-1"
		"OnTrigger" "speed_template,ForceSpawn,,0.1,-1"
		"OnTrigger" "prop_dynamic_6,Kill,,0,-1"
		"OnTrigger" "wall2_level3,Toggle,,0,-1"
		"OnTrigger" "trigger_breakable_2_level3,Enable,,0,-1"
		"OnTrigger" "wall4_level3,Toggle,,0,-1"
		"OnTrigger" "breakable_1_level4,Break,,0,-1"
		"OnTrigger" "wall5_level3,Toggle,,0,-1"
		"OnTrigger" "trigger_breakable_1_level3,Enable,,0,1"
		"OnTrigger" "fireball_template_weapon,ForceSpawn,,0.1,-1"
		"OnTrigger" "movelinear,Kill,,0,-1"
		"OnTrigger" "laser_trigger1_level3,Enable,,0,-1"
		"OnTrigger" "wall_level,Toggle,,0,-1"
		"OnTrigger" "counter_bosshp,SetValue,450,0,-1"
		"OnTrigger" "prop_dynamic_20,Kill,,0,-1"
		"OnTrigger" "prop_dynamic_12,Kill,,0,-1"
		"OnTrigger" "heal_hurt,AddOutput,OnHurtPlayer !activator:AddOutput:health 200:0.00:0,1,-1"
		"OnTrigger" "fireball_template_weapon,AddOutput,origin -629 -1529 421,0,-1"
		"OnTrigger" "speed_template,AddOutput,origin -170 -1807 412,0,-1"
		"OnTrigger" "speed_template,AddOutput,origin -116 -4326 104,0.2,-1"
		"OnTrigger" "speed_template,ForceSpawn,,0.3,-1"
		"OnTrigger" "speed_template,ForceSpawn,,0.5,-1"
		"OnTrigger" "speed_template,AddOutput,origin 682 -1326 500,0.4,-1"
		"OnTrigger" "boss_fire_template,AddOutput,OnEntitySpawned boss_fire_hurt:SetDamage:12:0.00:0,0,-1"
		"OnTrigger" "boss_ele_template,AddOutput,OnEntitySpawned boss_ele_hurt:SetDamage:50:0.00:0,0,-1"
		"OnTrigger" "boss_water_template,AddOutput,OnEntitySpawned boss_water_hurt:SetDamage:25:0.00:0,0,-1"
		"OnTrigger" "heal2_hurt,AddOutput,OnHurtPlayer !activator:AddOutput:health 200:0.00:0,1,-1"
		"OnTrigger" "boss_laser1,Enable,,0,-1"
	}
}

; Stage 3 - Extra
modify:
{
	match:
	{
		"classname" "logic_relay"
		"targetname" "relay_level3_1"
	}
	insert:
	{
		"OnTrigger" "extra3_score,AddOutput,OnStartTouch Stage_Counter:SetValue:7:0.01:1,0,-1"
	}
}

; Stage 4
modify:
{
	match:
	{
		"targetname" "relay_level4"
		"classname" "logic_relay"
	}
	delete:
	{
		"OnTrigger" "score_trigger,AddOutput,OnStartTouch level4_brush:Enable::0.00:1,0,-1"
		"OnTrigger" "score_trigger,AddOutput,OnStartTouch level4_1_brush:Disable::0.00:1,0,-1"
	}
	insert:
	{
		"OnTrigger" "score_trigger,AddOutput,OnStartTouch Stage_Counter:SetValue:8:0.00:1,0,-1"
		"OnTrigger" "trigger_teleport_3,Disable,,0,-1"
		"OnTrigger" "wall4_level2,Toggle,,0,-1"
		"OnTrigger" "wall5_level2,Toggle,,0,-1"
		"OnTrigger" "trigger_breakable_2,Disable,,0,-1"
		"OnTrigger" "wall7_level2,Toggle,,0,-1"
		"OnTrigger" "trigger_teleport_4,Disable,,0,-1"
		"OnTrigger" "wall8_level2,Toggle,,0,-1"
		"OnTrigger" "prop_dynamic_11,Kill,,0,-1"
		"OnTrigger" "wall3_level3,Toggle,,0,-1"
		"OnTrigger" "wall1_level4,Toggle,,0,-1"
		"OnTrigger" "trigger_teleport_6_1,Disable,,0,-1"
		"OnTrigger" "wall2_level4,Toggle,,0,-1"
		"OnTrigger" "trigger_teleport_6_3,Disable,,0,-1"
		"OnTrigger" "trigger_breakable_1_level4,Enable,,0,-1"
		"OnTrigger" "trigger_teleport_6_2,Disable,,0,-1"
		"OnTrigger" "wall5_level3,Toggle,,0,-1"
		"OnTrigger" "fireball_template_weapon,ForceSpawn,,0.1,-1"
		"OnTrigger" "trigger_level2_1,Enable,,0,-1"
		"OnTrigger" "wall_level,Toggle,,0,-1"
		"OnTrigger" "counter_bosshp,SetValue,600,0,-1"
		"OnTrigger" "prop_dynamic_20,Kill,,0,-1"
		"OnTrigger" "skyfire_trigger1,Enable,,0,-1"
		"OnTrigger" "prop_dynamic_12,Kill,,0,-1"
		"OnTrigger" "wall22,Toggle,,0,-1"
		"OnTrigger" "heal_hurt,AddOutput,OnHurtPlayer !activator:AddOutput:health 250:0.00:0,1,-1"
		"OnTrigger" "fireball_template_weapon,AddOutput,origin -631 -1593 68,0,-1"
		"OnTrigger" "fireball_template_weapon,AddOutput,origin 621 -3919 68,0.2,-1"
		"OnTrigger" "fireball_template_weapon,ForceSpawn,,0.3,-1"
		"OnTrigger" "speed_relay_level24,Trigger,,0,-1"
		"OnTrigger" "boss_fire_template,AddOutput,OnEntitySpawned boss_fire_hurt:SetDamage:14:0.00:0,0,-1"
		"OnTrigger" "boss_ele_template,AddOutput,OnEntitySpawned boss_ele_hurt:SetDamage:50:0.00:0,0,-1"
		"OnTrigger" "boss_movefire_temp,AddOutput,OnEntitySpawned boss_movefire_hurt:SetDamage:35:0.00:0,0,-1"
		"OnTrigger" "boss_movefire_temp1,AddOutput,OnEntitySpawned boss_movefire_hurt1:SetDamage:35:0.00:0,0,-1"
		"OnTrigger" "boss_water_template,AddOutput,OnEntitySpawned boss_water_hurt:SetDamage:30:0.00:0,0,-1"
		"OnTrigger" "skyfire_trigger2,Enable,,0,-1"
		"OnTrigger" "heal2_hurt,AddOutput,OnHurtPlayer !activator:AddOutput:health 250:0.00:0,1,-1"
	}
}

; Stage 4 - Extra
modify:
{
	match:
	{
		"classname" "logic_relay"
		"targetname" "relay_level4_1"
	}
	insert:
	{
		"OnTrigger" "score_relay,AddOutput,OnTrigger extra4_score:Disable::0.50:1,0,-1"
		"OnTrigger" "score_relay,AddOutput,OnTrigger extra4_score:Enable::0.00:1,0,-1"
		"OnTrigger" "extra4_filter,AddOutput,OnPass Stage_Counter:SetValue:9:0.01:1,0,-1"
	}
}

; Stage 5
modify:
{
	match:
	{
		"classname" "logic_relay"
		"targetname" "relay_level5"
	}
	insert:
	{
		"OnTrigger" "Stage_Counter,SetValue,1,155.1,-1"
		"OnTrigger" "servercommand,Command,say ***Adventure has ended. Thank you for playing***,155.1,-1"
		"OnTrigger" "servercommand,Command,say ***Returning to the beginning of the adventure..***,155.3,-1"
	}
}

;-----------------------------------------------------
; FIX: ONLY APPLY SCORE IF HUMANS COMPLETED THE LEVEL
;-----------------------------------------------------
; Level 2 & 4
modify:
{
	match:
	{
		"classname" "trigger_multiple"
		"targetname" "/extra(2|4)_score/"
	}
	delete:
	{
		"OnStartTouch" "score,ApplyScore,,0,-1"
	}
}
modify:
{
	match:
	{
		"classname" "filter_multi"
		"targetname" "/extra(2|4)_win_filter/"
	}
	insert:
	{
		"OnPass" "score,ApplyScore,,0,-1"
	}
}

;-----------------------------------------------------
; FIX: REPLACE BOSSHP OVERLAY SYSTEM WITH VGUI_SCREEN
;----------------------------------------------------
; You may ask why? It conflict with plugins overlay
filter:
{
	"targetname" "bosshp_screen"
}

modify:
{
	match:
	{
		"classname" "math_counter"
		"targetname" "counter_bosshp"
	}
	delete:
	{
		"OnHitMin" "boss_hpcounter,GetValue,,0.1,-1"
	}
	insert:
	{
		"OnHitMin" "counter_ovelayswitch,Add,1,0,-1"
	}
}

modify:
{
	match:
	{
		"classname" "math_counter"
		"targetname" "boss_hpcounter"
	}
	insert:
	{
		"OnHitMax" "vguiscreen*,SetInactive,,0,-1"
	}
}

add:
{
	"classname" "math_counter"
	"max" "7"
	"min" "1"
	"StartDisabled" "0"
	"startvalue" "1"
	"targetname" "counter_ovelayswitch"
	"OutValue" "bosscase,InValue,,0,-1"
	"OnHitMax" "!self,Disable,,0,1"
	"OnHitMax" "counter_bosshp,Disable,,0,1"
	"OnHitMax" "bosscase,FireUser1,,0,1"
	"OnHitMax" "boss,TurnOff,,0,1"
	"OnHitMax" "boss,DisableCollision,,0.1,1"
	"OnHitMax" "vguiscreen*,Kill,,0.1,1"
	"OnHitMax" "vguiscreen*,SetInactive,,0.05,1"
}

add:
{
	"classname" "logic_case"
	"Case01" "1"
	"Case02" "2"
	"Case03" "3"
	"Case04" "4"
	"Case05" "5"
	"Case06" "6"
	"Case07" "7"
	"targetname" "bosscase"
	"OnCase01" "vguiscreen10,SetActive,,0.05,1"
	"OnCase02" "vguiscreen8,SetActive,,0.05,1"
	"OnCase03" "vguiscreen6,SetActive,,0.05,1"
	"OnCase04" "vguiscreen4,SetActive,,0.05,1"
	"OnCase05" "vguiscreen2,SetActive,,0.05,1"
	"OnCase06" "vguiscreen0,SetActive,,0.05,1"
	"OnCase02" "!self,FireUser1,,0,1"
	"OnCase03" "!self,FireUser1,,0,1"
	"OnCase04" "!self,FireUser1,,0,1"
	"OnCase05" "!self,FireUser1,,0,1"
	"OnCase06" "!self,FireUser1,,0,1"
	"OnCase01" "!self,FireUser1,,0,1"
	"OnUser1" "vguiscreen*,SetInactive,,0,-1"
}

add:
{
	"classname" "vgui_screen"
	"angles" "0 0 0"
	"height" "1024"
	"overlaymaterial" "maps/ze_roof_adventure/bosshp0"
	"targetname" "vguiscreen0"
	"width" "1024"
	"origin" "-804 -8044 468"
}

add:
{
	"classname" "vgui_screen"
	"angles" "0 0 0"
	"height" "1024"
	"overlaymaterial" "maps/ze_roof_adventure/bosshp2"
	"targetname" "vguiscreen2"
	"width" "1024"
	"origin" "-804 -8044 468"
}

add:
{
	"classname" "vgui_screen"
	"angles" "0 0 0"
	"height" "1024"
	"overlaymaterial" "maps/ze_roof_adventure/bosshp4"
	"targetname" "vguiscreen4"
	"width" "1024"
	"origin" "-804 -8044 468"
}

add:
{
	"classname" "vgui_screen"
	"angles" "0 0 0"
	"height" "1024"
	"overlaymaterial" "maps/ze_roof_adventure/bosshp6"
	"targetname" "vguiscreen6"
	"width" "1024"
	"origin" "-804 -8044 468"
}

add:
{
	"classname" "vgui_screen"
	"angles" "0 0 0"
	"height" "1024"
	"overlaymaterial" "maps/ze_roof_adventure/bosshp8"
	"targetname" "vguiscreen8"
	"width" "1024"
	"origin" "-804 -8044 468"
}

add:
{
	"classname" "vgui_screen"
	"angles" "0 0 0"
	"height" "1024"
	"overlaymaterial" "maps/ze_roof_adventure/bosshp10"
	"targetname" "vguiscreen10"
	"width" "1024"
	"origin" "-804 -8044 468"
}

modify:
{
	match:
	{
		"classname" "func_movelinear"
		"targetname" "boss_move"
	}
	insert:
	{
		"OnFullyOpen" "vguiscreen10,SetActive,,0,1"
	}
}

;------------------------
; REMOVE ORPHANS OUTPUTS
;------------------------
modify:
{
	match:
	{
		"classname" "trigger_multiple"
		"targetname" "extra1_score"
	}
	delete:
	{
		"OnStartTouch" "level1_1_brush,Enable,,0,1"
		"OnStartTouch" "level2_brush,Disable,,0,1"
	}
}

modify:
{
	match:
	{
		"classname" "filter_multi"
		"targetname" "extra2_win_filter"
	}
	delete:
	{
		"OnPass" "level2_1_brush,Enable,,0,-1"
		"OnPass" "level3_brush,Disable,,0,-1"
	}
}

modify:
{
	match:
	{
		"classname" "trigger_multiple"
		"targetname" "extra3_score"
	}
	delete:
	{
		"OnStartTouch" "level4_brush,Disable,,0,1"
		"OnStartTouch" "level3_1_brush,Enable,,0,1"
	}
}

modify:
{
	match:
	{
		"classname" "filter_multi"
		"targetname" "extra4_filter"
	}
	delete:
	{
		"OnPass" "level4_1_brush,Enable,,0,1"
		"OnPass" "level5_brush,Disable,,0,1"
	}
}




;; _

;; extra1 - teleport items out of spawn

modify:
{
	match:
	{
		"targetname" "parkourmode_car_knife"
		"classname" "weapon_knife"
	}
	insert:
	{
		"OnPlayerPickup" "!activator,AddOutput,origin 4664 -7296 2545,0,1"
	}
}
modify:
{
	match:
	{
		"targetname" "parkourmode_trailer_knife"
		"classname" "weapon_knife"
	}
	insert:
	{
		"OnPlayerPickup" "!activator,AddOutput,origin 4664 -7296 2545,0,1"
	}
}
modify:
{
	match:
	{
		"targetname" "parkourmode_bicycle_knife"
		"classname" "weapon_knife"
	}
	insert:
	{
		"OnPlayerPickup" "!activator,AddOutput,origin 4664 -7296 2545,0,1"
	}
}
modify:
{
	match:
	{
		"targetname" ""targetname" "parkourmode_kart_knife""
		"classname" "weapon_knife"
	}
	insert:
	{
		"OnPlayerPickup" "!activator,AddOutput,origin 3896 -7552 2225,0,1"
	}
}

;; fix modelindex

modify:
{
	match:
	{
		"classname" "weapon_knife"
		"OnPlayerPickup" "!activator,AddOutput,modelindex 498,0,1"
	}
	delete:
	{
		"OnPlayerPickup" "!activator,AddOutput,modelindex 498,0,1"
	}
}

;; unstuck players

add:
{
	"model" "*151"
	"targetname" "ladder_unstuck"
	"StartDisabled" "1"
	"spawnflags" "1"
	"origin" "235 -7555 534"
	"classname" "trigger_once"
	"OnStartTouch" "!activator,AddOutput,origin 297 -7556 544,0,-1"
}
modify:
{
	match:
	{
		"targetname" "boss_trigger"
		"origin" "287 -7555 534"
		"classname" "trigger_once"
	}
	insert:
	{
		"OnStartTouch" "ladder_unstuck,Enable,,30,1"
		"OnStartTouch" "ladder_unstuck,Kill,,30.05,1"
	}
}