#include "hunger/leveldead_loadsaved"
#include "beast/trigger_entity_volume"
#include "cubemath/trigger_once_mp"
#include "cubemath/trigger_multiple_mp"

const bool blAntiRushEnable = false; // change to true to enable Anti-Rush
const bool blHardModeEnable = false; // change to true to enable Hard-Mode
const bool blSurvivalModeEnable = false; // change to true to enable Survival-Mode -Mikk

void MapInit()
{
	g_EngineFuncs.CVarSetFloat( "mp_keep_globals", 1 );
	g_EngineFuncs.CVarSetFloat( "mp_hevsuit_voice", 0 );
	g_CustomEntityFuncs.RegisterCustomEntity( "trigger_multiple_mp", "trigger_multiple_mp" );
	g_CustomEntityFuncs.RegisterCustomEntity( "trigger_once_mp", "trigger_once_mp" );
	g_CustomEntityFuncs.RegisterCustomEntity( "anti_rush", "anti_rush" );
	RegisterTriggerEntityVolume();
	if( blAntiRushEnable )
	{
		ActivateAntiRush();
	}
	if( blSurvivalModeEnable )
	{
		Survival_on();
	}
	if( blHardModeEnable )
	{
		HardModeEnables();
	}
}

void HardModeEnables()
{
    CBaseEntity@ pEntity = null;
    dictionary hardmode;
    hardmode =
    {
        { "triggerstate", "1" },
        { "delay", "1"},
        { "target", "extranpc" }
    };
    @pEntity = g_EntityFuncs.CreateEntity( "trigger_auto", hardmode, true );
	g_EngineFuncs.CVarSetFloat( "mp_banana", 0 );
	g_EngineFuncs.CVarSetFloat( "mp_allowmonsterinfo", 0 );
	g_EngineFuncs.CVarSetFloat( "mp_dropweapons", 0 );
	g_EngineFuncs.CVarSetFloat( "mp_nomedkit", 1 );
	g_EngineFuncs.CVarSetFloat( "npc_dropweapons", 0 );
	g_EngineFuncs.CVarSetFloat( "mp_ammo_respawndelay", -1 );
}

void Survival_on()
{
    CBaseEntity@ pEntity = null;
    dictionary survivalple;
    survivalple =
    {
        { "triggerstate", "1" },
        { "delay", "20"},
        { "target", "survival_on" }
    };
    @pEntity = g_EntityFuncs.CreateEntity( "trigger_auto", survivalple, true );
    survivalple =
    {
        { "m_iMode", "1" },
        { "m_iszScriptFunctionName", "ActivateSurvival"},
        { "targetname", "survival_on" }
    };
    @pEntity = g_EntityFuncs.CreateEntity( "trigger_script", survivalple, true );
	g_EngineFuncs.CVarSetFloat( "mp_survival_supported", 1 );
	g_EngineFuncs.CVarSetFloat( "mp_survival_starton", 0 );
	g_EngineFuncs.CVarSetFloat( "mp_survival_startdelay", 0 );
}

void ActivateSurvival(CBaseEntity@ pActivator,CBaseEntity@ pCaller, USE_TYPE useType, float flValue)
{
	g_SurvivalMode.Activate();
}

void ActivateAntiRush()
{
    if( string(g_Engine.mapname) == "pagoda_out" )
    {
		AntiRushPercent( "50", "-484 1284 139", "-638 700 28", "1" );
		AntiRushBlocker( "1", "52", "-148 -480 0" );
		MasterMBFORGOT( "block_antirushtext", "2" );
		AntiRushPercent( "50", "-460 1318 652", "-798 1084 510", "2" );
		AntiRushBlocker( "2", "6", "0 -2 0" );
		MasterMBFORGOT( "show_hiddentext", "3" );
		AntiRushPercent( "50", "-821 712 1484", "-1256 233 1372", "3" );
		AntiRushBlocker( "3", "8", "0 -4 0" );
		AntiRushPercent( "66", "-859 1251 2434", "-2148 -36 2044", "4" );
		AntiRushBlocker( "4", "82", "0 0 0" );
		AntiRushRelayInit( "52", "-1900 -32 480" );
		AntiRushRelayInit( "63", "-359 -1552 364" );
		AntiRushRelayInit( "52", "-1403 -720 1792" );
		AntiRushRelayInit( "91", "" );
		AntiRushRelayInit( "91", "0 0 53" );
		AntiRushRelayInite();
    }

    if( string(g_Engine.mapname) == "pagoda_in" )
    {
		AntiRushPercent( "50", "-1388 1127 620", "-1492 540 508", "1" );
		AntiRushBlocker( "1", "3", "0 57 0" );
		AntiRushRelayInit( "54", "-26 -172 -100" );
		AntiRushRelayInit( "28", "430 -72 39" );
		AntiRushRelayInit( "44", "0 -1 0" );
		AntiRushPercent( "50", "5 257 1059", "-756 -16 908", "2" );
		AntiRushBlocker( "2", "6", "1 0 0" );
		AntiRushPercent( "50", "-876 994 1932", "-998 644 1771", "3" );
		AntiRushBlocker( "3", "7", "0 2 0" );
		AntiRushRelayInite();
    }
}

void AntiRushBlocker( const string namese, const string model, const string origin )
{
	CBaseEntity@ pEntity = null;
	dictionary wall;

	wall =
	{
		{ "model", "*" + model },
		{ "origin", "" + origin },
		{ "rendermode", "5"},
		{ "renderamt", "0"},
		{ "targetname", "antirush_target_" + namese }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "func_wall_toggle", wall, true );
}

void AntiRushPercent( const string percent, const string maxh, const string minh, const string namese )
{
	CBaseEntity@ pEntity = null;
	dictionary antirush;

	antirush =
	{
		{ "percentage", "" + percent },
		{ "zonecornermin", "" + minh },
		{ "zonecornermax", "" + maxh },
		{ "master", "antirush_master_" + namese },
		{ "target", "antirush_target_" + namese },
		{ "killtarget", "antirush_vol_" + namese }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "anti_rush", antirush, true );

	antirush =
	{
		{ "percentage", "01"},
		{ "zonecornermin", "" + minh },
		{ "zonecornermax", "" + maxh },
		{ "master", "antirush_master_" + namese },
		{ "target", "antirush_vol_" + namese },
		{ "wait", "1"}
	};
	@pEntity = g_EntityFuncs.CreateEntity( "anti_rush", antirush, true );

	antirush =
	{
		{ "intarget", "antirush_text_" + namese },
		{ "zonecornermin", "" + minh },
		{ "zonecornermax", "" + maxh },
		{ "incount", "1"},
		{ "spawnflags", "1"},
		{ "targetname", "antirush_vol_" + namese }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "trigger_entity_volume", antirush, true );

	antirush =
	{
		{ "effect", "2" },
		{ "spawnflags", "2"},
		{ "y", "0.67"},
		{ "x", "-1"},
		{ "color", "100 100 100"},
		{ "color2", "240 110 0"},
		{ "fadein", "0.0"},
		{ "fadeout", "1"},
		{ "holdtime", "5"},
		{ "fxtime", "0.0"},
		{ "channel", "1"},
		{ "message", "ANTI-RUSH: "+ percent +" percent of players needed" },
		{ "targetname", "antirush_text_" + namese }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", antirush, true );
}

void MasterMBFORGOT( const string namese, const string targetse )
{
	CBaseEntity@ pEntity = null;
	dictionary mstant;

	mstant =
	{
		{ "targetname", "" + namese },
		{ "target", "antirush_master_" + targetse }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "anti_rush", mstant, true );
}

void AntiRushRelayInit( const string model, const string origin )
{
	CBaseEntity@ pEntity = null;
	dictionary relayinit1;

	relayinit1 =
	{
		{ "model", "*" + model },
		{ "origin", "" + origin },
		{ "rendermode", "5"},
		{ "renderamt", "0"},
		{ "targetname", "antirush_initwall" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "func_wall_toggle", relayinit1, true );
}

void AntiRushRelayInite()
{
	CBaseEntity@ pEntity = null;
	dictionary relayinit;
	
	relayinit =
    {
        { "triggerstate", "1" },
        { "delay", "1"},
        { "target", "relay_init_map_20" }
    };
    @pEntity = g_EntityFuncs.CreateEntity( "trigger_auto", relayinit, true );
	
	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 20 seconds.." },
		{ "targetname", "msg_countdown_11" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 19 seconds.." },
		{ "targetname", "msg_countdown_12" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 18 seconds.." },
		{ "targetname", "msg_countdown_13" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 17 seconds.." },
		{ "targetname", "msg_countdown_14" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 16 seconds.." },
		{ "targetname", "msg_countdown_13" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 15 seconds.." },
		{ "targetname", "msg_countdown_14" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 14 seconds.." },
		{ "targetname", "msg_countdown_15" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 13 seconds.." },
		{ "targetname", "msg_countdown_16" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 12 seconds.." },
		{ "targetname", "msg_countdown_17" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 16 seconds.." },
		{ "targetname", "msg_countdown_18" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 15 seconds.." },
		{ "targetname", "msg_countdown_19" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 14 seconds.." },
		{ "targetname", "msg_countdown_20" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 13 seconds.." },
		{ "targetname", "msg_countdown_21" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 12 seconds.." },
		{ "targetname", "msg_countdown_22" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 11 seconds.." },
		{ "targetname", "msg_countdown_23" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 10 seconds.." },
		{ "targetname", "msg_countdown_24" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 9 seconds.." },
		{ "targetname", "msg_countdown_25" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 8 seconds.." },
		{ "targetname", "msg_countdown_26" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 7 seconds.." },
		{ "targetname", "msg_countdown_27" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 6 seconds.." },
		{ "targetname", "msg_countdown_28" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 5 seconds.." },
		{ "targetname", "msg_countdown_29" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 4 seconds.." },
		{ "targetname", "msg_countdown_30" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 3 seconds.." },
		{ "targetname", "msg_countdown_31" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 2 seconds.." },
		{ "targetname", "msg_countdown_32" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "spawnflags", "3"},
		{ "y", "-.25"},
		{ "x", "-1"},
		{ "color", "255 255 255"},
		{ "color2", "255 255 255"},
		{ "fadein", "1"},
		{ "fadeout", "0.5"},
		{ "holdtime", "2"},
		{ "fxtime", "0.25"},
		{ "channel", "4"},
		{ "message", "Game will begin in 1 seconds.." },
		{ "targetname", "msg_countdown_33" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "game_text", relayinit, true );

	relayinit =
	{
		{ "msg_countdown_11", "1.5"},
		{ "msg_countdown_12", "2.5"},
		{ "msg_countdown_13", "3.5"},
		{ "msg_countdown_14", "4.5"},
		{ "msg_countdown_15", "5.5"},
		{ "msg_countdown_16", "6.5"},
		{ "msg_countdown_17", "7.5"},
		{ "msg_countdown_18", "8.5"},
		{ "msg_countdown_19", "9.5"},
		{ "msg_countdown_20", "10.5"},
		{ "msg_countdown_21", "11.5"},
		{ "msg_countdown_22", "12.5"},
		{ "msg_countdown_23", "13.5"},
		{ "msg_countdown_24", "14.5"},
		{ "msg_countdown_25", "15.5"},
		{ "msg_countdown_26", "16.5"},
		{ "msg_countdown_27", "17.5"},
		{ "msg_countdown_28", "18.5"},
		{ "msg_countdown_29", "19.5"},
		{ "msg_countdown_30", "20.5"},
		{ "msg_countdown_31", "21.5"},
		{ "msg_countdown_32", "22.5"},
		{ "msg_countdown_33", "23.5"},
		{ "antirush_initwall", "23.5"},
		{ "targetname", "relay_init_map_20" }
	};
	@pEntity = g_EntityFuncs.CreateEntity( "multi_manager", relayinit, true );
}

/*
*
*	Next code taked from Outerbeast's Anti-Rush entity
*	https://github.com/Outerbeast/anti_rush
*
*/
class anti_rush : ScriptBaseEntity
{
    private EHandle hAntiRushLock;
    private string strPercentTriggerType    = "trigger_once_mp";
    private string strMasterName, strKillTarget;
    private Vector vZoneCornerMin, vZoneCornerMax;
    private float flPercentRequired, flTargetDelay, flTriggerWait;
    bool KeyValue(const string& in szKey, const string& in szValue)
    {
        if( szKey == "master" ) 
        {
            strMasterName = szValue;
            return true;
        }
        else if( szKey == "killtarget" ) 
        {
            strKillTarget = szValue;
            return true;
        }
        else if( szKey == "zonecornermin" ) 
        {
            g_Utility.StringToVector( vZoneCornerMin, szValue );
            return true;
        }
        else if( szKey == "zonecornermax" ) 
        {
            g_Utility.StringToVector( vZoneCornerMax, szValue );
            return true;
        }
        else if( szKey == "percentage" ) 
        {
            flPercentRequired = atof( szValue );
            return true;
        }
        else if( szKey == "wait" )
        {
            flTriggerWait = atof( szValue );
            return true;
        }
        else if( szKey == "delay" )
        {
            flTargetDelay = atof( szValue );
            return true;
        }
        else
            return BaseClass.KeyValue( szKey, szValue );
    }
    void Spawn()
    {
        self.Precache();
        self.pev.movetype 	= MOVETYPE_NONE;
        self.pev.solid 		= SOLID_NOT;
        g_EntityFuncs.SetOrigin( self, self.pev.origin );
        if( self.GetTargetname() == "" )
            self.pev.targetname = "" + self.GetClassname() + "_ent" + self.entindex();

        if( flTriggerWait > 0.0f )
            strPercentTriggerType = "trigger_multiple_mp";
        else
            strPercentTriggerType = "trigger_once_mp";

        if( flPercentRequired > 0.01f )
        {   
            if( vZoneCornerMin != g_vecZero && vZoneCornerMax != g_vecZero )
            {
                if( vZoneCornerMin != vZoneCornerMax )
                    CreatePercentPlayerTrigger();
            }
        }

        if( self.pev.target != "" || self.pev.target != self.GetTargetname() )
            CreateLock();
    }
    void CreatePercentPlayerTrigger()
    {
        dictionary trgr;
        trgr ["minhullsize"]        = "" + vZoneCornerMin.ToString();
        trgr ["maxhullsize"]        = "" + vZoneCornerMax.ToString();
        trgr ["m_flPercentage"]     = "" + flPercentRequired/100;
        trgr ["target"]             = "" + self.GetTargetname();
        if( strMasterName != "" || strMasterName != "" + self.GetTargetname() ) trgr ["master"] = "" + strMasterName;
        if( strPercentTriggerType == "trigger_multiple_mp" ) trgr ["m_flDelay"] = "" + flTriggerWait;
        CBaseEntity@ pPercentPlayerTrigger = g_EntityFuncs.CreateEntity( "" + strPercentTriggerType, trgr, true );
    }
    void CreateLock()
    {
        dictionary ms = { { "targetname", "" + self.pev.target } };
        hAntiRushLock = EHandle( g_EntityFuncs.CreateEntity( "multisource", ms, true ) );
    }
    void Use(CBaseEntity@ pActivator, CBaseEntity@ pCaller, USE_TYPE useType, float value)
    {
        g_Scheduler.SetTimeout( this, "TargetFuncs", flTargetDelay );
    }
    void TargetFuncs()
    {
        self.SUB_UseTargets( @self, USE_TOGGLE, 0 );
        CBaseEntity@ pKillTargetEnt;
        if( strKillTarget != "" || strKillTarget != self.GetTargetname() )
        {
            while( ( @pKillTargetEnt = g_EntityFuncs.FindEntityByTargetname( pKillTargetEnt, "" + strKillTarget ) ) !is null )
                g_EntityFuncs.Remove( pKillTargetEnt );
        }
    }
    void UpdateOnRemove()
    {
        if( hAntiRushLock )
            g_EntityFuncs.Remove( hAntiRushLock.GetEntity() );
    }
}