Score HUD

Unpaid Requests, Public Plugins
Post Reply
User avatar
Spir0x
Veteran Member
Veteran Member
Tunisia
Posts: 552
Joined: 1 Year Ago
Location: Tunisia
Has thanked: 14 times
Been thanked: 6 times
Age: 18
Contact:

Score HUD

#1

Post by Spir0x » 2 Weeks Ago

Hello can someone convert this score hud message to zombie escape and remove it from ze_core ? or add it on ze_core.

Code: Select all

#include < amxmodx >
#include < dhudmessage >
#include < zombieplague >

#define PLUGIN_NAME "[ZP] DHUD Informer"
#define PLUGIN_VERSION "0.0.0.1"
#define PLUGIN_AUTHOR "Andrei"

enum _: eTeamData
{
	WIN_NO_ONE = 0,
	WIN_ZOMBIES,
	WIN_HUMANS	

}; new g_iWin[ eTeamData ];

public plugin_init() 
{
    	register_plugin
	( 
		PLUGIN_NAME, 
		PLUGIN_VERSION, 
		PLUGIN_AUTHOR
	);

	register_dictionary( "zp_score.txt" );
	register_message( get_user_msgid( "TextMsg" ), "Message_TextMsg" );
}

public Message_TextMsg( ) 
{
	static szMessages[ 32 ];
	get_msg_arg_string( 2, szMessages, charsmax( szMessages ) );
	
	if( equal( szMessages, "#Game_will_restart_in" ) )
	{
		g_iWin[ WIN_HUMANS ] = 0;
		g_iWin[ WIN_ZOMBIES ] = 0;
		g_iWin[ WIN_NO_ONE ] = 0;
	} 
}

public zp_round_started( )
{
	set_task( 1.0, "Ctask__Update", _ ,_ ,_ , .flags = "b" );
}  

public zp_round_ended( iWinTeam )
{
	switch( iWinTeam )
	{
		case WIN_HUMANS: g_iWin[ WIN_HUMANS ]++;
		case WIN_ZOMBIES: g_iWin[ WIN_ZOMBIES ]++;
		default: g_iWin[ WIN_NO_ONE ]++;
	}

	remove_task();
}  


public Ctask__Update( )
{
	set_dhudmessage( .red = 0, .green = 255, .blue = 0, .x = -1.0, .y = 0.02, .effects = 0, .fxtime = 6.0, .holdtime = 2.0, .fadeintime = 1.0, .fadeouttime = 1.0, .reliable = false ); 
	show_dhudmessage( 0, "%L                        ", LANG_PLAYER, "SCORE_HUMANS", zp_get_human_count() );
	set_dhudmessage( .red = 100, .green = 100, .blue = 100, .x = -1.0, .y = 0.02, .effects = 0, .fxtime = 6.0, .holdtime = 2.0, .fadeintime = 1.0, .fadeouttime = 1.0, .reliable = false ); 
	show_dhudmessage( 0, "%L^n%L", LANG_PLAYER, "SCORE_ROUND", ( g_iWin[ WIN_HUMANS ] +  g_iWin[ WIN_ZOMBIES ] + g_iWin[ WIN_NO_ONE ] ), LANG_PLAYER,  "SCORE_WINS", g_iWin[ WIN_HUMANS ],  g_iWin[ WIN_ZOMBIES ] );
	set_dhudmessage( .red = 255, .green = 0, .blue = 0, .x = -1.0, .y = 0.02, .effects = 0, .fxtime = 6.0, .holdtime = 2.0, .fadeintime = 1.0, .fadeouttime = 1.0, .reliable = false ); 
	show_dhudmessage( 0, "                         %L", LANG_PLAYER, "SCORE_ZOMBIES", zp_get_zombie_count() );
}

Code: Select all

[ru] 
SCORE_HUMANS = Люди %02d
SCORE_ROUND = [ %02d ]
SCORE_WINS = %02d Победы %02d
SCORE_ZOMBIES = %02d Зомби

[en] 
SCORE_HUMANS = Humans %02d
SCORE_ROUND = [ %02d ]
SCORE_WINS = %02d Wins %02d
SCORE_ZOMBIES = %02d Zombies

User avatar
Spir0x
Veteran Member
Veteran Member
Tunisia
Posts: 552
Joined: 1 Year Ago
Location: Tunisia
Has thanked: 14 times
Been thanked: 6 times
Age: 18
Contact:

#2

Post by Spir0x » 2 Weeks Ago

Up

User avatar
Spir0x
Veteran Member
Veteran Member
Tunisia
Posts: 552
Joined: 1 Year Ago
Location: Tunisia
Has thanked: 14 times
Been thanked: 6 times
Age: 18
Contact:

#3

Post by Spir0x » 2 Weeks Ago

Up

User avatar
Jack GamePlay
Mod Developer
Mod Developer
Egypt
Posts: 512
Joined: 1 Year Ago
Location: Egypt
Has thanked: 31 times
Been thanked: 42 times
Age: 18
Contact:

#4

Post by Jack GamePlay » 1 Week Ago

Give your core code.

[ Post made via Android ]
Image

User avatar
Spir0x
Veteran Member
Veteran Member
Tunisia
Posts: 552
Joined: 1 Year Ago
Location: Tunisia
Has thanked: 14 times
Been thanked: 6 times
Age: 18
Contact:

#5

Post by Spir0x » 1 Week Ago

Code: Select all

#include <zombie_escape>
 
// Fowards
enum _:TOTAL_FORWARDS
{
    FORWARD_NONE = 0,
    FORWARD_ROUNDEND,
    FORWARD_HUMANIZED,
    FORWARD_PRE_INFECTED,
    FORWARD_INFECTED,
    FORWARD_ZOMBIE_APPEAR,
    FORWARD_ZOMBIE_RELEASE,
    FORWARD_GAME_STARTED
}
 
new g_iForwards[TOTAL_FORWARDS], g_iFwReturn, g_iTeam
 
// Tasks IDs
enum
{
    TASK_COUNTDOWN = 1100,
    TASK_COUNTDOWN2,
    TASK_SCORE_MESSAGE,
    FREEZE_ZOMBIES,
    ROUND_TIME_LEFT
}
 
// Colors (g_pCvarColors[] array indexes)
enum
{
    Red = 0,
    Green,
    Blue
}
 
// Variables
new g_iAliveHumansNum,
    g_iAliveZombiesNum,
    g_iRoundTime,
    g_iCountDown,
    g_iReleaseNotice,
    g_iMaxClients,
    g_iHumansScore,
    g_iZombiesScore,
    g_iRoundNum,
    g_iHSpeedFactor[33],
    g_iZSpeedSet[33],
    bool:g_bGameStarted,
    bool:g_bIsZombie[33],
    bool:g_bIsZombieFrozen[33],
    bool:g_bZombieFreezeTime,
    bool:g_bIsRoundEnding,
    bool:g_bHSpeedUsed[33],
    bool:g_bZSpeedUsed[33],
    bool:g_bEndCalled,
    Float:g_flReferenceTime
 
// Cvars
new g_pCvarHumanSpeedFactor,
    g_pCvarHumanGravity,
    g_pCvarHumanHealth,
    g_pCvarZombieSpeed,
    g_pCvarZombieGravity,
    g_pCvarZombieReleaseTime,
    g_pCvarFreezeTime,
    g_pCvarRoundTime,
    g_pCvarReqPlayers,
    g_pCvarZombieHealth,
    g_pCvarFirstZombiesHealth,
    g_pCvarZombieKnockback,
    g_pCvarScoreMessageType,
    g_pCvarColors[3],
    g_pCvarRoundEndDelay
 
public plugin_natives()
{
    register_native("ze_is_user_zombie", "native_ze_is_user_zombie", 1)
    register_native("ze_is_game_started", "native_ze_is_game_started", 1)
    register_native("ze_is_zombie_frozen", "native_ze_is_zombie_frozen", 1)
   
    register_native("ze_get_round_number", "native_ze_get_round_number", 1)
    register_native("ze_get_humans_number", "native_ze_get_humans_number", 1)
    register_native("ze_get_zombies_number", "native_ze_get_zombies_number", 1)
   
    register_native("ze_set_user_zombie", "native_ze_set_user_zombie", 1)
    register_native("ze_set_user_human", "native_ze_set_user_human", 1)
    register_native("ze_set_human_speed_factor", "native_ze_set_human_speed_factor", 1)
    register_native("ze_set_zombie_speed", "native_ze_set_zombie_speed", 1)
   
    register_native("ze_reset_human_speed", "native_ze_reset_human_speed", 1)
    register_native("ze_reset_zombie_speed", "native_ze_reset_zombie_speed", 1)
}
 
public plugin_init()
{
    register_plugin("[ZE] Core/Engine", ZE_VERSION, AUTHORS)
   
    // Hook Chains
    RegisterHookChain(RG_CBasePlayer_TraceAttack, "Fw_TraceAttack_Pre", 0)
    RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
    RegisterHookChain(RG_CBasePlayer_Spawn, "Fw_PlayerSpawn_Post", 1)
    RegisterHookChain(RG_CSGameRules_CheckWinConditions, "Fw_CheckMapConditions_Post", 1)
    RegisterHookChain(RG_CBasePlayer_Killed, "Fw_PlayerKilled_Post", 1)
    RegisterHookChain(RG_RoundEnd, "Event_RoundEnd_Pre", 0)
   
    // Events
    register_event("HLTV", "New_Round", "a", "1=0", "2=0")
    register_event("TextMsg", "Map_Restart", "a", "2=#Game_Commencing", "2=#Game_will_restart_in", "2=#Round_Draw")
    register_logevent("Round_Start", 2, "1=Round_Start")
    register_logevent("Round_End", 2, "1=Round_End")
   
    // Hams
    RegisterHam(Ham_Item_PreFrame, "player", "Fw_RestMaxSpeed_Post", 1)
   
    // Create Forwards (All Return Values Ignored)
    g_iForwards[FORWARD_ROUNDEND] = CreateMultiForward("ze_roundend", ET_IGNORE, FP_CELL)
    g_iForwards[FORWARD_HUMANIZED] = CreateMultiForward("ze_user_humanized", ET_IGNORE, FP_CELL)
    g_iForwards[FORWARD_PRE_INFECTED] = CreateMultiForward("ze_user_infected_pre", ET_CONTINUE, FP_CELL, FP_CELL)
    g_iForwards[FORWARD_INFECTED] = CreateMultiForward("ze_user_infected", ET_IGNORE, FP_CELL, FP_CELL)
    g_iForwards[FORWARD_ZOMBIE_APPEAR] = CreateMultiForward("ze_zombie_appear", ET_IGNORE)
    g_iForwards[FORWARD_ZOMBIE_RELEASE] = CreateMultiForward("ze_zombie_release", ET_IGNORE)
    g_iForwards[FORWARD_GAME_STARTED] = CreateMultiForward("ze_game_started", ET_IGNORE)
   
    // Hud Messages
    g_iReleaseNotice = CreateHudSyncObj()
   
    // Sequential files (.txt)
    register_dictionary("zombie_escape.txt")
   
    // Humans Cvars
    g_pCvarHumanSpeedFactor = register_cvar("ze_human_speed_factor", "20.0")
    g_pCvarHumanGravity = register_cvar("ze_human_gravity", "800")
    g_pCvarHumanHealth = register_cvar("ze_human_health", "1000")
   
    // Zombie Cvars
    g_pCvarZombieSpeed = register_cvar("ze_zombie_speed", "350.0")
    g_pCvarZombieGravity = register_cvar("ze_zombie_gravity", "640")
    g_pCvarZombieHealth = register_cvar("ze_zombie_health", "10000")
    g_pCvarFirstZombiesHealth = register_cvar("ze_first_zombies_health", "20000")
    g_pCvarZombieKnockback = register_cvar("ze_zombie_knockback", "300.0")
   
    // General Cvars
    g_pCvarZombieReleaseTime = register_cvar("ze_release_time", "15")
    g_pCvarFreezeTime = register_cvar("ze_freeze_time", "20")
    g_pCvarRoundTime = register_cvar("ze_round_time", "9.0")
    g_pCvarReqPlayers = register_cvar("ze_required_players", "2")
    g_pCvarScoreMessageType = register_cvar("ze_score_message_type", "1")
    g_pCvarColors[Red] = register_cvar("ze_score_message_red", "200")
    g_pCvarColors[Green] = register_cvar("ze_score_message_green", "100")
    g_pCvarColors[Blue] = register_cvar("ze_score_message_blue", "0")
    g_pCvarRoundEndDelay = register_cvar("ze_round_end_delay", "5")
   
    // Default Values
    g_bGameStarted = false
   
    // Static Values
    g_iMaxClients = get_member_game(m_nMaxPlayers)
   
    // Check Round Time to Terminate it
    set_task(1.0, "Check_RoundTimeleft", ROUND_TIME_LEFT, _, _, "b")
}
 
public plugin_cfg()
{
    // Get our configiration file and Execute it
    new szCfgDir[64]
    get_localinfo("amxx_configsdir", szCfgDir, charsmax(szCfgDir))
    server_cmd("exec %s/zombie_escape.cfg", szCfgDir)
   
    // Set Game Name
    new szGameName[64]
    formatex(szGameName, sizeof(szGameName), "Premuim ZE v%s", ZE_VERSION)
    set_member_game(m_GameDesc, szGameName)
   
    // Set Version
    register_cvar("ze_version", ZE_VERSION, FCVAR_SERVER|FCVAR_SPONLY)
    set_cvar_string("ze_version", ZE_VERSION)
}
 
public Fw_CheckMapConditions_Post()
{
    // Block Game Commencing
    set_member_game(m_bGameStarted, true)
   
    // Set Freeze Time
    set_member_game(m_iIntroRoundTime, get_pcvar_num(g_pCvarFreezeTime))
   
    // Set Round Time
    set_member_game(m_iRoundTime, floatround(get_pcvar_float(g_pCvarRoundTime) * 60.0))
}
 
public Fw_PlayerKilled_Post(id)
{
    g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
    g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
   
    if (g_iAliveHumansNum == 0 && g_iAliveZombiesNum == 0)
    {
        // No Winner, All Players in one team killed Or Both teams Killed
        client_print(0, print_center, "%L", LANG_PLAYER, "NO_WINNER")
    }
}
 
public Fw_RestMaxSpeed_Post(id)
{
    if (!g_bIsZombie[id])
    {
        static Float:flMaxSpeed
        get_entvar(id, var_maxspeed, flMaxSpeed)
       
        if (flMaxSpeed != 1.0 && is_user_alive(id))
        {
            if (g_bHSpeedUsed[id])
            {
                // Set New Human Speed Factor
                set_entvar(id, var_maxspeed, flMaxSpeed + float(g_iHSpeedFactor[id]))
                return HAM_IGNORED
            }
               
            // Set Human Speed Factor, native not used
            set_entvar(id, var_maxspeed, flMaxSpeed + get_pcvar_float(g_pCvarHumanSpeedFactor))
            return HAM_IGNORED
        }
    }
   
    return HAM_SUPERCEDE
}
 
public Fw_PlayerSpawn_Post(id)
{  
    if (!g_bGameStarted)
    {
        // Force All player to be Humans if Game not started yet
        rg_set_user_team(id, TEAM_CT, MODEL_UNASSIGNED)
    }
    else
    {
        if (get_member_game(m_bFreezePeriod))
        {
            // Respawn Him As human if we are in freeze time (Zombie Not Chosen yet)
            Set_User_Human(id)
            g_bIsZombieFrozen[id] = false
        }
        else
        {
            if (g_bZombieFreezeTime)
            {
                // Zombie Chosen and zombies Frozen, Spawn him as zombie and Freeze Him
                Set_User_Zombie(id)
                g_bIsZombieFrozen[id] = true
                set_entvar(id, var_maxspeed, 1.0)
            }
            else
            {
                // Respawn him as normal zombie
                Set_User_Zombie(id)
                g_bIsZombieFrozen[id] = false
            }
        }
    }
}
 
public New_Round()
{
    // Remove All tasks in the New Round
    remove_task(TASK_COUNTDOWN)
    remove_task(TASK_COUNTDOWN2)
    remove_task(TASK_SCORE_MESSAGE)
    remove_task(FREEZE_ZOMBIES)
   
    // Score Message Task
    set_task(10.0, "Score_Message", TASK_SCORE_MESSAGE, _, _, "b")
   
    // 2 is Hardcoded Value, It's Fix for the countdown to work correctly
    g_iCountDown = get_pcvar_num(g_pCvarFreezeTime) - 2
   
    if (!g_bGameStarted)
    {
        // No Enough Players
        ze_colored_print(0, "%L", LANG_PLAYER, "NO_ENOUGH_PLAYERS", get_pcvar_num(g_pCvarReqPlayers))
        return // Block the execution of the blew code
    }
   
    // Game Already started, Countdown now started
    set_task(1.0, "Countdown_Start", TASK_COUNTDOWN, _, _, "b")
    ze_colored_print(0, "%L", LANG_PLAYER, "READY_TO_RUN")
    ExecuteForward(g_iForwards[FORWARD_GAME_STARTED], g_iFwReturn)
   
    g_iRoundNum++
   
    // Round Starting
    g_bIsRoundEnding = false
    g_bEndCalled = false
}
 
// Score Message Task
public Score_Message(TaskID)
{
    switch(get_pcvar_num(g_pCvarScoreMessageType))
    {
        case 0: // Disabled
        {
            return
        }
        case 1: // DHUD
        {
            set_dhudmessage(0, 255, 0, 0.38, 0.01, 0, 0.0, 9.0)
            show_dhudmessage(0, "Survivors")
           
            set_dhudmessage(255, 255, 255, -1.0, 0.01, 0, 0.0, 9.0)
            show_dhudmessage(0, "[VS]")
           
            set_dhudmessage(255, 0, 0, 0.54, 0.01, 0, 0.0, 9.0)
            show_dhudmessage(0, "Zombies")
           
            set_dhudmessage(255, 255, 255, -1.0, 0.045, 0, 0.0, 9.0)
            show_dhudmessage(0, "[%i] --------- [%i]", g_iHumansScore, g_iZombiesScore)
        }
        case 2: // HUD
        {
            set_hudmessage(get_pcvar_num(g_pCvarColors[Red]), get_pcvar_num(g_pCvarColors[Green]), get_pcvar_num(g_pCvarColors[Blue]), -1.0, 0.01, 0, 0.0, 9.0)
            show_hudmessage(0, "%L", LANG_PLAYER, "SCORE_MESSAGE", g_iZombiesScore, g_iHumansScore)
        }
    }
}
 
public Countdown_Start(TaskID)
{
    // Check if the players Disconnected and there is only one player then remove all messages, and stop tasks
    if (!g_bGameStarted)
        return
   
    if (!g_iCountDown)
    {
        Choose_Zombies()
        remove_task(TASK_COUNTDOWN) // Remove the task
        return // Block the execution of the blew code
    }
   
    set_hudmessage(random(256), random(256), random(256), -1.0, 0.21, 0, 0.8, 0.8)
    show_hudmessage(0, "%L", LANG_PLAYER, "RUN_NOTICE", g_iCountDown)
 
    g_iCountDown--
}
 
public Choose_Zombies()
{
    new iZombies, id, iAliveCount
    new iReqZombies
   
    // Get total alive players and required players
    iAliveCount  = GetAllAlivePlayersNum()
    iReqZombies = RequiredZombies()
   
    // Loop till we find req players
    while(iZombies < iReqZombies)
    {
        id = GetRandomAlive(random_num(1, iAliveCount))
       
        if (!is_user_alive(id) || g_bIsZombie[id])
            continue
 
        Set_User_Zombie(id)
        set_entvar(id, var_health, get_pcvar_float(g_pCvarFirstZombiesHealth))
        g_bIsZombieFrozen[id] = true
        g_bZombieFreezeTime = true
        set_entvar(id, var_maxspeed, 1.0)
        set_task(0.1, "Freeze_Zombies", FREEZE_ZOMBIES, _, _, "b") // Better than PreThink
        ExecuteForward(g_iForwards[FORWARD_ZOMBIE_APPEAR], g_iFwReturn)
        iZombies++
       
        // Respawn Zombies to base
        rg_round_respawn(id)
    }
   
    // 2 is Hardcoded Value, It's Fix for the countdown to work correctly
    g_iCountDown = get_pcvar_num(g_pCvarZombieReleaseTime) - 2
   
    set_task(1.0, "ReleaseZombie_CountDown", TASK_COUNTDOWN2, _, _, "b")
}
 
public ReleaseZombie_CountDown(TaskID)
{
    if (!g_iCountDown)
    {
        ReleaseZombie()
        remove_task(TASK_COUNTDOWN2)
        return
    }
   
    // Release Hud Message
    set_hudmessage(255, 255, 0, -1.0, 0.21, 1, 2.0, 2.0)
    ShowSyncHudMsg(0, g_iReleaseNotice, "%L", LANG_PLAYER, "ZOMBIE_RELEASE", g_iCountDown)
   
    g_iCountDown --
}
 
public ReleaseZombie()
{
    ExecuteForward(g_iForwards[FORWARD_ZOMBIE_RELEASE], g_iFwReturn)
   
    for(new id = 1; id <= g_iMaxClients; id++)
    {
        if (is_user_alive(id) && g_bIsZombie[id])
        {
            g_bIsZombieFrozen[id] = false
            g_bZombieFreezeTime = false
        }
    }
}
 
public Freeze_Zombies(TaskID)
{
    for(new id = 1; id <= g_iMaxClients; id++)
    {
        if(!is_user_alive(id) || !g_bIsZombie[id])
            continue
       
        if (g_bIsZombieFrozen[id])
        {
            // Zombie & Frozen, then Freeze him
            set_entvar(id, var_maxspeed, 1.0)
        }
        else
        {
            if (g_bZSpeedUsed[id])
            {
                // Zombie but Not Frozen the set his speed form .cfg
                set_entvar(id, var_maxspeed, float(g_iZSpeedSet[id]))
                continue;
            }
               
            // Zombie but Not Frozen the set his speed form .cfg
            set_entvar(id, var_maxspeed, get_pcvar_float(g_pCvarZombieSpeed))
        }
    }
}
 
public Fw_TraceAttack_Pre(iVictim, iAttacker, Float:flDamage, Float:flDirection[3], iTracehandle, bitsDamageType)
{
    if (iVictim == iAttacker || !is_user_connected(iVictim) || !is_user_connected(iAttacker))
        return HC_CONTINUE
   
    // Attacker and Victim is in same teams? Skip code blew
    if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
        return HC_CONTINUE
   
    // In freeze time? Skip all other plugins (Skip the real trace attack event)
    if (g_bIsZombieFrozen[iVictim] || g_bIsZombieFrozen[iAttacker])
        return HC_SUPERCEDE
   
    g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
   
    if (g_bIsZombie[iAttacker])
    {
        // Death Message with Infection style [Added here because of delay in Forward use]
        SendDeathMsg(iAttacker, iVictim)
       
        ExecuteForward(g_iForwards[FORWARD_PRE_INFECTED], g_iFwReturn, iVictim, iAttacker)
       
        if (g_iFwReturn > 0)
        {
            return HC_CONTINUE
        }
       
        Set_User_Zombie(iVictim)
       
        ExecuteForward(g_iForwards[FORWARD_INFECTED], g_iFwReturn, iVictim, iAttacker)
       
        if (g_iAliveHumansNum == 1) // Check if this is Last Human, Because of Delay i can't check if it's 0 instead of 1
        {
            // End round event called one time
            g_bEndCalled = true
           
            // Round is Ending
            g_bIsRoundEnding = true
           
            // Zombie Win, Leave text blank so we use ours from ML
            rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
           
            // Show Our Message
            client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
           
            // This needed so forward work also to add +1 for Zombies
            g_iTeam = 1 // ZE_TEAM_ZOMBIE
            ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
        }
    }
   
    return HC_CONTINUE
}
 
public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
{
    // Not Vaild Victim or Attacker so skip the event (Important to block out bounds errors)
    if (!is_user_connected(iVictim) || !is_user_connected(iAttacker))
        return HC_CONTINUE
   
    // Set Knockback here, So if we blocked damage in TraceAttack event player won't get knockback (Fix For Madness)
    if (g_bIsZombie[iVictim] && !g_bIsZombie[iAttacker])
    {
        // Remove Shock Pain
        set_member(iVictim, m_flVelocityModifier, 1.0)
       
        // Set Knockback
        static Float:flOrigin[3]
        get_entvar(iAttacker, var_origin, flOrigin)
        Set_Knockback(iVictim, flOrigin, get_pcvar_float(g_pCvarZombieKnockback), 2)
    }
   
    return HC_CONTINUE
}
 
public Round_End()
{
    g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
   
    if (g_iAliveZombiesNum == 0 && g_bGameStarted)
    {
        g_iTeam = 2 // ZE_TEAM_HUMAN
        ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
        client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
        g_iHumansScore++
        g_bIsRoundEnding = true
        return // To block Execute the code blew
    }
   
    g_iTeam = 1 // ZE_TEAM_ZOMBIE
    g_iZombiesScore++
    g_bIsRoundEnding = true
   
    // If it's already called one time, don't call it again
    if (!g_bEndCalled)
    {
        ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
    }
   
    client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
}
 
public Event_RoundEnd_Pre(WinStatus:status, ScenarioEventEndRound:event, Float:tmDelay)
{
    // The two unhandeld cases by rg_round_end() native in our Mod
    if (event == ROUND_CTS_WIN || event == ROUND_TERRORISTS_WIN)
    {
        SetHookChainArg(3, ATYPE_FLOAT, get_pcvar_float(g_pCvarRoundEndDelay))
    }
}
 
public Round_Start()
{
    g_flReferenceTime = get_gametime()
    g_iRoundTime = get_member_game(m_iRoundTime)
}
 
public Check_RoundTimeleft()
{
    new Float:flRoundTimeLeft = (g_flReferenceTime + float(g_iRoundTime)) - get_gametime()
   
    if (floatround(flRoundTimeLeft) == 0)
    {
        // Round is Ending
        g_bIsRoundEnding = true
       
        // If Time is Out then Terminate the Round
        rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
       
        // Show our Message
        client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
    }
}
 
public client_disconnected(id)
{
    // Delay Then Check Players to Terminate The round (Delay needed)
    set_task(0.1, "Check_AlivePlayers")
   
    // Reset speed for this dropped id
    g_bHSpeedUsed[id] = false
    g_bZSpeedUsed[id] = false
}
 
// This check done when player disconnect
public Check_AlivePlayers()
{
    g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
    g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
   
    // Game Started? (There is at least 2 players Alive?)
    if (g_bGameStarted)
    {
        // We are in freeze time?
        if (get_member_game(m_bFreezePeriod))
        {
            // Humans alive number = 1 and no zombies?
            if (g_iAliveHumansNum < get_pcvar_num(g_pCvarReqPlayers))
            {
                // Game started false again
                g_bGameStarted = false
            }
        }
        else // Not freeze time?
        {
            // Variables
            new iAllZombiesNum = GetTeamPlayersNum(CsTeams:TEAM_TERRORIST),
            iAllHumansNum = GetTeamPlayersNum(CsTeams:TEAM_CT),
            iDeadZombiesNum = GetDeadPlayersNum(CsTeams:TEAM_TERRORIST),
            iDeadHumansNum = GetDeadPlayersNum(CsTeams:TEAM_CT)
   
            // Alive humans number = 1 and no zombies at all, And no dead humans?
            if (g_iAliveHumansNum < get_pcvar_num(g_pCvarReqPlayers) && iDeadHumansNum == 0 && iAllZombiesNum == 0)
            {
                // Game started is false and humans wins (Escape Success)
                g_bGameStarted = false
                rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_CTS, ROUND_CTS_WIN, "")
                client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
            }
           
            // Alive zombies number = 1 and no humans at all, And no dead zombies?
            if (g_iAliveZombiesNum < get_pcvar_num(g_pCvarReqPlayers) && iDeadZombiesNum == 0 && iAllHumansNum == 0)
            {
                // Game started is false and zombies wins (Escape Fail)
                g_bGameStarted = false
                rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
                client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
            }
           
            // Humans number more than 1 and no zombies?
            if (g_iAliveHumansNum >= get_pcvar_num(g_pCvarReqPlayers) && g_iAliveZombiesNum == 0 && !g_bIsRoundEnding)
            {
                // Then Escape success as there is no Zombies
                rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_CTS, ROUND_CTS_WIN, "")
                client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
            }
           
            // Zombies number more than 1 and no humans?
            if (g_iAliveZombiesNum >= get_pcvar_num(g_pCvarReqPlayers) && g_iAliveHumansNum == 0 && !g_bIsRoundEnding)
            {
                // Then Escape Fail as there is no humans
                rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
                client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
            }
        }
    }
}
 
public client_putinserver(id)
{
    // Add Delay and Check Conditions To start the Game (Delay needed)
    set_task(1.0, "Check_AllPlayersNumber", _, _, _, "b")
}
 
public Check_AllPlayersNumber(TaskID)
{
    if (g_bGameStarted)
    {
        // If game started remove the task and block the blew Checks
        remove_task(TaskID)
        return
    }
   
    if (GetAllAlivePlayersNum() >= get_pcvar_num(g_pCvarReqPlayers))
    {
        // Players In server == The Required so game started is true
        g_bGameStarted = true
       
        // Restart the game
        server_cmd("sv_restart 2")
       
        // Print Fake game Commencing Message
        client_print(0, print_center, "%L", LANG_PLAYER, "START_GAME")
       
        // Remove the task
        remove_task(TaskID)
    }
}
 
public Set_User_Human(id)
{
    if (!is_user_alive(id))
        return
   
    g_bIsZombie[id] = false
    set_entvar(id, var_health, get_pcvar_float(g_pCvarHumanHealth))
    set_entvar(id, var_gravity, get_pcvar_float(g_pCvarHumanGravity)/800.0)
    ExecuteForward(g_iForwards[FORWARD_HUMANIZED], g_iFwReturn, id)
   
    if (get_member(id, m_iTeam) != TEAM_CT)
        rg_set_user_team(id, TEAM_CT, MODEL_UNASSIGNED)
}
 
public Set_User_Zombie(id)
{
    if (!is_user_alive(id))
        return
   
    g_bIsZombie[id] = true
    set_entvar(id, var_health, get_pcvar_float(g_pCvarZombieHealth))
    set_entvar(id, var_gravity, get_pcvar_float(g_pCvarZombieGravity)/800.0)
    rg_remove_all_items(id)
    rg_give_item(id, "weapon_knife", GT_APPEND)
    ExecuteForward(g_iForwards[FORWARD_INFECTED], g_iFwReturn, id, 0)
   
    if (get_member(id, m_iTeam) != TEAM_TERRORIST)
        rg_set_user_team(id, TEAM_TERRORIST, MODEL_UNASSIGNED)
}
 
public Map_Restart()
{
    // Add Delay To help Rest Scores if player kill himself, and there no one else him so round draw (Delay needed)
    set_task(0.1, "Reset_Score_Message")
}
 
public Reset_Score_Message()
{
    g_iHumansScore = 0
    g_iZombiesScore = 0
    g_iRoundNum = 0
}
 
// Natives
public native_ze_is_user_zombie(id)
{
    if (!is_user_connected(id))
    {
        return -1;
    }
   
    return g_bIsZombie[id]
}
 
public native_ze_set_user_zombie(id)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    Set_User_Zombie(id)
    return true;
}
 
public native_ze_set_user_human(id)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    Set_User_Human(id)
    return true;
}
 
public native_ze_is_game_started()
{
    return g_bGameStarted
}
 
public native_ze_is_zombie_frozen(id)
{
    if (!is_user_connected(id) || !g_bIsZombie[id])
    {
        return -1;
    }
   
    return g_bIsZombieFrozen[id]
}
 
public native_ze_get_round_number()
{
    if (!g_bGameStarted)
    {
        return -1;
    }
   
    return g_iRoundNum
}
 
public native_ze_get_humans_number()
{
    return GetAlivePlayersNum(CsTeams:TEAM_CT)
}
 
public native_ze_get_zombies_number()
{
    return GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
}
 
public native_ze_set_human_speed_factor(id, iFactor)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    g_bHSpeedUsed[id] = true
    g_iHSpeedFactor[id] = iFactor
    ExecuteHamB(Ham_Item_PreFrame, id)
    return true;
}
 
public native_ze_reset_human_speed(id)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    g_bHSpeedUsed[id] = false
    ExecuteHamB(Ham_Item_PreFrame, id)
    return true;
}
 
public native_ze_set_zombie_speed(id, iSpeed)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    g_bZSpeedUsed[id] = true
    g_iZSpeedSet[id] = iSpeed
    return true;
}
 
public native_ze_reset_zombie_speed(id)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    g_bZSpeedUsed[id] = false
    return true;
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ ansicpg1252\\ deff0\\ deflang1036{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ f0\\ fs16 \n\\ par }
*/

User avatar
Jack GamePlay
Mod Developer
Mod Developer
Egypt
Posts: 512
Joined: 1 Year Ago
Location: Egypt
Has thanked: 31 times
Been thanked: 42 times
Age: 18
Contact:

#6

Post by Jack GamePlay » 1 Week Ago

Code: Select all

#include <zombie_escape>
 
// Fowards
enum _:TOTAL_FORWARDS
{
    FORWARD_NONE = 0,
    FORWARD_ROUNDEND,
    FORWARD_HUMANIZED,
    FORWARD_PRE_INFECTED,
    FORWARD_INFECTED,
    FORWARD_ZOMBIE_APPEAR,
    FORWARD_ZOMBIE_RELEASE,
    FORWARD_GAME_STARTED
}
 
new g_iForwards[TOTAL_FORWARDS], g_iFwReturn, g_iTeam
 
// Tasks IDs
enum
{
    TASK_COUNTDOWN = 1100,
    TASK_COUNTDOWN2,
    TASK_SCORE_MESSAGE,
    FREEZE_ZOMBIES,
    ROUND_TIME_LEFT
}
 
// Colors (g_pCvarColors[] array indexes)
enum
{
    Red = 0,
    Green,
    Blue
}
 
// Variables
new g_iAliveHumansNum,
    g_iAliveZombiesNum,
    g_iRoundTime,
    g_iCountDown,
    g_iReleaseNotice,
    g_iMaxClients,
    g_iHumansScore,
    g_iZombiesScore,
    g_iRoundNum,
    g_iHSpeedFactor[33],
    g_iZSpeedSet[33],
    bool:g_bGameStarted,
    bool:g_bIsZombie[33],
    bool:g_bIsZombieFrozen[33],
    bool:g_bZombieFreezeTime,
    bool:g_bIsRoundEnding,
    bool:g_bHSpeedUsed[33],
    bool:g_bZSpeedUsed[33],
    bool:g_bEndCalled,
    Float:g_flReferenceTime
 
// Cvars
new g_pCvarHumanSpeedFactor,
    g_pCvarHumanGravity,
    g_pCvarHumanHealth,
    g_pCvarZombieSpeed,
    g_pCvarZombieGravity,
    g_pCvarZombieReleaseTime,
    g_pCvarFreezeTime,
    g_pCvarRoundTime,
    g_pCvarReqPlayers,
    g_pCvarZombieHealth,
    g_pCvarFirstZombiesHealth,
    g_pCvarZombieKnockback,
    g_pCvarScoreMessageType,
    g_pCvarColors[3],
    g_pCvarRoundEndDelay
 
public plugin_natives()
{
    register_native("ze_is_user_zombie", "native_ze_is_user_zombie", 1)
    register_native("ze_is_game_started", "native_ze_is_game_started", 1)
    register_native("ze_is_zombie_frozen", "native_ze_is_zombie_frozen", 1)
   
    register_native("ze_get_round_number", "native_ze_get_round_number", 1)
    register_native("ze_get_humans_number", "native_ze_get_humans_number", 1)
    register_native("ze_get_zombies_number", "native_ze_get_zombies_number", 1)
   
    register_native("ze_set_user_zombie", "native_ze_set_user_zombie", 1)
    register_native("ze_set_user_human", "native_ze_set_user_human", 1)
    register_native("ze_set_human_speed_factor", "native_ze_set_human_speed_factor", 1)
    register_native("ze_set_zombie_speed", "native_ze_set_zombie_speed", 1)
   
    register_native("ze_reset_human_speed", "native_ze_reset_human_speed", 1)
    register_native("ze_reset_zombie_speed", "native_ze_reset_zombie_speed", 1)
}
 
public plugin_init()
{
    register_plugin("[ZE] Core/Engine", ZE_VERSION, AUTHORS)
   
    // Hook Chains
    RegisterHookChain(RG_CBasePlayer_TraceAttack, "Fw_TraceAttack_Pre", 0)
    RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
    RegisterHookChain(RG_CBasePlayer_Spawn, "Fw_PlayerSpawn_Post", 1)
    RegisterHookChain(RG_CSGameRules_CheckWinConditions, "Fw_CheckMapConditions_Post", 1)
    RegisterHookChain(RG_CBasePlayer_Killed, "Fw_PlayerKilled_Post", 1)
    RegisterHookChain(RG_RoundEnd, "Event_RoundEnd_Pre", 0)
   
    // Events
    register_event("HLTV", "New_Round", "a", "1=0", "2=0")
    register_event("TextMsg", "Map_Restart", "a", "2=#Game_Commencing", "2=#Game_will_restart_in", "2=#Round_Draw")
    register_logevent("Round_Start", 2, "1=Round_Start")
    register_logevent("Round_End", 2, "1=Round_End")
   
    // Hams
    RegisterHam(Ham_Item_PreFrame, "player", "Fw_RestMaxSpeed_Post", 1)
   
    // Create Forwards (All Return Values Ignored)
    g_iForwards[FORWARD_ROUNDEND] = CreateMultiForward("ze_roundend", ET_IGNORE, FP_CELL)
    g_iForwards[FORWARD_HUMANIZED] = CreateMultiForward("ze_user_humanized", ET_IGNORE, FP_CELL)
    g_iForwards[FORWARD_PRE_INFECTED] = CreateMultiForward("ze_user_infected_pre", ET_CONTINUE, FP_CELL, FP_CELL)
    g_iForwards[FORWARD_INFECTED] = CreateMultiForward("ze_user_infected", ET_IGNORE, FP_CELL, FP_CELL)
    g_iForwards[FORWARD_ZOMBIE_APPEAR] = CreateMultiForward("ze_zombie_appear", ET_IGNORE)
    g_iForwards[FORWARD_ZOMBIE_RELEASE] = CreateMultiForward("ze_zombie_release", ET_IGNORE)
    g_iForwards[FORWARD_GAME_STARTED] = CreateMultiForward("ze_game_started", ET_IGNORE)
   
    // Hud Messages
    g_iReleaseNotice = CreateHudSyncObj()
   
    // Sequential files (.txt)
    register_dictionary("zombie_escape.txt")
    register_dictionary( "zp_score.txt" )
   
    // Humans Cvars
    g_pCvarHumanSpeedFactor = register_cvar("ze_human_speed_factor", "20.0")
    g_pCvarHumanGravity = register_cvar("ze_human_gravity", "800")
    g_pCvarHumanHealth = register_cvar("ze_human_health", "1000")
   
    // Zombie Cvars
    g_pCvarZombieSpeed = register_cvar("ze_zombie_speed", "350.0")
    g_pCvarZombieGravity = register_cvar("ze_zombie_gravity", "640")
    g_pCvarZombieHealth = register_cvar("ze_zombie_health", "10000")
    g_pCvarFirstZombiesHealth = register_cvar("ze_first_zombies_health", "20000")
    g_pCvarZombieKnockback = register_cvar("ze_zombie_knockback", "300.0")
   
    // General Cvars
    g_pCvarZombieReleaseTime = register_cvar("ze_release_time", "15")
    g_pCvarFreezeTime = register_cvar("ze_freeze_time", "20")
    g_pCvarRoundTime = register_cvar("ze_round_time", "9.0")
    g_pCvarReqPlayers = register_cvar("ze_required_players", "2")
    g_pCvarScoreMessageType = register_cvar("ze_score_message_type", "1")
    g_pCvarColors[Red] = register_cvar("ze_score_message_red", "200")
    g_pCvarColors[Green] = register_cvar("ze_score_message_green", "100")
    g_pCvarColors[Blue] = register_cvar("ze_score_message_blue", "0")
    g_pCvarRoundEndDelay = register_cvar("ze_round_end_delay", "5")
   
    // Default Values
    g_bGameStarted = false
   
    // Static Values
    g_iMaxClients = get_member_game(m_nMaxPlayers)
   
    // Check Round Time to Terminate it
    set_task(1.0, "Check_RoundTimeleft", ROUND_TIME_LEFT, _, _, "b")
}
 
public plugin_cfg()
{
    // Get our configiration file and Execute it
    new szCfgDir[64]
    get_localinfo("amxx_configsdir", szCfgDir, charsmax(szCfgDir))
    server_cmd("exec %s/zombie_escape.cfg", szCfgDir)
   
    // Set Game Name
    new szGameName[64]
    formatex(szGameName, sizeof(szGameName), "Premuim ZE v%s", ZE_VERSION)
    set_member_game(m_GameDesc, szGameName)
   
    // Set Version
    register_cvar("ze_version", ZE_VERSION, FCVAR_SERVER|FCVAR_SPONLY)
    set_cvar_string("ze_version", ZE_VERSION)
}
 
public Fw_CheckMapConditions_Post()
{
    // Block Game Commencing
    set_member_game(m_bGameStarted, true)
   
    // Set Freeze Time
    set_member_game(m_iIntroRoundTime, get_pcvar_num(g_pCvarFreezeTime))
   
    // Set Round Time
    set_member_game(m_iRoundTime, floatround(get_pcvar_float(g_pCvarRoundTime) * 60.0))
}
 
public Fw_PlayerKilled_Post(id)
{
    g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
    g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
   
    if (g_iAliveHumansNum == 0 && g_iAliveZombiesNum == 0)
    {
        // No Winner, All Players in one team killed Or Both teams Killed
        client_print(0, print_center, "%L", LANG_PLAYER, "NO_WINNER")
    }
}
 
public Fw_RestMaxSpeed_Post(id)
{
    if (!g_bIsZombie[id])
    {
        static Float:flMaxSpeed
        get_entvar(id, var_maxspeed, flMaxSpeed)
       
        if (flMaxSpeed != 1.0 && is_user_alive(id))
        {
            if (g_bHSpeedUsed[id])
            {
                // Set New Human Speed Factor
                set_entvar(id, var_maxspeed, flMaxSpeed + float(g_iHSpeedFactor[id]))
                return HAM_IGNORED
            }
               
            // Set Human Speed Factor, native not used
            set_entvar(id, var_maxspeed, flMaxSpeed + get_pcvar_float(g_pCvarHumanSpeedFactor))
            return HAM_IGNORED
        }
    }
   
    return HAM_SUPERCEDE
}
 
public Fw_PlayerSpawn_Post(id)
{  
    if (!g_bGameStarted)
    {
        // Force All player to be Humans if Game not started yet
        rg_set_user_team(id, TEAM_CT, MODEL_UNASSIGNED)
    }
    else
    {
        if (get_member_game(m_bFreezePeriod))
        {
            // Respawn Him As human if we are in freeze time (Zombie Not Chosen yet)
            Set_User_Human(id)
            g_bIsZombieFrozen[id] = false
        }
        else
        {
            if (g_bZombieFreezeTime)
            {
                // Zombie Chosen and zombies Frozen, Spawn him as zombie and Freeze Him
                Set_User_Zombie(id)
                g_bIsZombieFrozen[id] = true
                set_entvar(id, var_maxspeed, 1.0)
            }
            else
            {
                // Respawn him as normal zombie
                Set_User_Zombie(id)
                g_bIsZombieFrozen[id] = false
            }
        }
    }
}
 
public New_Round()
{
    // Remove All tasks in the New Round
    remove_task(TASK_COUNTDOWN)
    remove_task(TASK_COUNTDOWN2)
    remove_task(TASK_SCORE_MESSAGE)
    remove_task(FREEZE_ZOMBIES)
   
    // Score Message Task
    set_task(10.0, "Score_Message", TASK_SCORE_MESSAGE, _, _, "b")
   
    // 2 is Hardcoded Value, It's Fix for the countdown to work correctly
    g_iCountDown = get_pcvar_num(g_pCvarFreezeTime) - 2
   
    if (!g_bGameStarted)
    {
        // No Enough Players
        ze_colored_print(0, "%L", LANG_PLAYER, "NO_ENOUGH_PLAYERS", get_pcvar_num(g_pCvarReqPlayers))
        return // Block the execution of the blew code
    }
   
    // Game Already started, Countdown now started
    set_task(1.0, "Countdown_Start", TASK_COUNTDOWN, _, _, "b")
    ze_colored_print(0, "%L", LANG_PLAYER, "READY_TO_RUN")
    ExecuteForward(g_iForwards[FORWARD_GAME_STARTED], g_iFwReturn)
   
    g_iRoundNum++
   
    // Round Starting
    g_bIsRoundEnding = false
    g_bEndCalled = false
}
 
// Score Message Task
public Score_Message(TaskID)
{
    switch(get_pcvar_num(g_pCvarScoreMessageType))
    {
        case 0: // Disabled
        {
            return
        }
        case 1: // DHUD
        {
            set_dhudmessage(0, 255, 0, 0.38, 0.01, 0, 0.0, 9.0)
            show_dhudmessage(0, "Survivors")
           
            set_dhudmessage(255, 255, 255, -1.0, 0.01, 0, 0.0, 9.0)
            show_dhudmessage(0, "[VS]")
           
            set_dhudmessage(255, 0, 0, 0.54, 0.01, 0, 0.0, 9.0)
            show_dhudmessage(0, "Zombies")
           
            set_dhudmessage(255, 255, 255, -1.0, 0.045, 0, 0.0, 9.0)
            show_dhudmessage(0, "[%i] --------- [%i]", g_iHumansScore, g_iZombiesScore)

            set_dhudmessage( .red = 0, .green = 255, .blue = 0, .x = -1.0, .y = 0.02, .effects = 0, .fxtime = 6.0, .holdtime = 2.0, .fadeintime = 1.0, .fadeouttime = 1.0, .reliable = false ); 
			show_dhudmessage( 0, "%L                        ", LANG_PLAYER, "SCORE_HUMANS", native_ze_get_humans_number() );
			set_dhudmessage( .red = 100, .green = 100, .blue = 100, .x = -1.0, .y = 0.02, .effects = 0, .fxtime = 6.0, .holdtime = 2.0, .fadeintime = 1.0, .fadeouttime = 1.0, .reliable = false ); 
			show_dhudmessage( 0, "%L^n%L", LANG_PLAYER, "SCORE_ROUND", g_iRoundNum, LANG_PLAYER,  "SCORE_WINS", g_iHumansScore,  g_iZombiesScore );
			set_dhudmessage( .red = 255, .green = 0, .blue = 0, .x = -1.0, .y = 0.02, .effects = 0, .fxtime = 6.0, .holdtime = 2.0, .fadeintime = 1.0, .fadeouttime = 1.0, .reliable = false ); 
			show_dhudmessage( 0, "                         %L", LANG_PLAYER, "SCORE_ZOMBIES", native_ze_get_zombies_number() );
        }
        case 2: // HUD
        {
            set_hudmessage(get_pcvar_num(g_pCvarColors[Red]), get_pcvar_num(g_pCvarColors[Green]), get_pcvar_num(g_pCvarColors[Blue]), -1.0, 0.01, 0, 0.0, 9.0)
            show_hudmessage(0, "%L", LANG_PLAYER, "SCORE_MESSAGE", g_iZombiesScore, g_iHumansScore)
        }
    }
}
 
public Countdown_Start(TaskID)
{
    // Check if the players Disconnected and there is only one player then remove all messages, and stop tasks
    if (!g_bGameStarted)
        return
   
    if (!g_iCountDown)
    {
        Choose_Zombies()
        remove_task(TASK_COUNTDOWN) // Remove the task
        return // Block the execution of the blew code
    }
   
    set_hudmessage(random(256), random(256), random(256), -1.0, 0.21, 0, 0.8, 0.8)
    show_hudmessage(0, "%L", LANG_PLAYER, "RUN_NOTICE", g_iCountDown)
 
    g_iCountDown--
}
 
public Choose_Zombies()
{
    new iZombies, id, iAliveCount
    new iReqZombies
   
    // Get total alive players and required players
    iAliveCount  = GetAllAlivePlayersNum()
    iReqZombies = RequiredZombies()
   
    // Loop till we find req players
    while(iZombies < iReqZombies)
    {
        id = GetRandomAlive(random_num(1, iAliveCount))
       
        if (!is_user_alive(id) || g_bIsZombie[id])
            continue
 
        Set_User_Zombie(id)
        set_entvar(id, var_health, get_pcvar_float(g_pCvarFirstZombiesHealth))
        g_bIsZombieFrozen[id] = true
        g_bZombieFreezeTime = true
        set_entvar(id, var_maxspeed, 1.0)
        set_task(0.1, "Freeze_Zombies", FREEZE_ZOMBIES, _, _, "b") // Better than PreThink
        ExecuteForward(g_iForwards[FORWARD_ZOMBIE_APPEAR], g_iFwReturn)
        iZombies++
       
        // Respawn Zombies to base
        rg_round_respawn(id)
    }
   
    // 2 is Hardcoded Value, It's Fix for the countdown to work correctly
    g_iCountDown = get_pcvar_num(g_pCvarZombieReleaseTime) - 2
   
    set_task(1.0, "ReleaseZombie_CountDown", TASK_COUNTDOWN2, _, _, "b")
}
 
public ReleaseZombie_CountDown(TaskID)
{
    if (!g_iCountDown)
    {
        ReleaseZombie()
        remove_task(TASK_COUNTDOWN2)
        return
    }
   
    // Release Hud Message
    set_hudmessage(255, 255, 0, -1.0, 0.21, 1, 2.0, 2.0)
    ShowSyncHudMsg(0, g_iReleaseNotice, "%L", LANG_PLAYER, "ZOMBIE_RELEASE", g_iCountDown)
   
    g_iCountDown --
}
 
public ReleaseZombie()
{
    ExecuteForward(g_iForwards[FORWARD_ZOMBIE_RELEASE], g_iFwReturn)
   
    for(new id = 1; id <= g_iMaxClients; id++)
    {
        if (is_user_alive(id) && g_bIsZombie[id])
        {
            g_bIsZombieFrozen[id] = false
            g_bZombieFreezeTime = false
        }
    }
}
 
public Freeze_Zombies(TaskID)
{
    for(new id = 1; id <= g_iMaxClients; id++)
    {
        if(!is_user_alive(id) || !g_bIsZombie[id])
            continue
       
        if (g_bIsZombieFrozen[id])
        {
            // Zombie & Frozen, then Freeze him
            set_entvar(id, var_maxspeed, 1.0)
        }
        else
        {
            if (g_bZSpeedUsed[id])
            {
                // Zombie but Not Frozen the set his speed form .cfg
                set_entvar(id, var_maxspeed, float(g_iZSpeedSet[id]))
                continue;
            }
               
            // Zombie but Not Frozen the set his speed form .cfg
            set_entvar(id, var_maxspeed, get_pcvar_float(g_pCvarZombieSpeed))
        }
    }
}
 
public Fw_TraceAttack_Pre(iVictim, iAttacker, Float:flDamage, Float:flDirection[3], iTracehandle, bitsDamageType)
{
    if (iVictim == iAttacker || !is_user_connected(iVictim) || !is_user_connected(iAttacker))
        return HC_CONTINUE
   
    // Attacker and Victim is in same teams? Skip code blew
    if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
        return HC_CONTINUE
   
    // In freeze time? Skip all other plugins (Skip the real trace attack event)
    if (g_bIsZombieFrozen[iVictim] || g_bIsZombieFrozen[iAttacker])
        return HC_SUPERCEDE
   
    g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
   
    if (g_bIsZombie[iAttacker])
    {
        // Death Message with Infection style [Added here because of delay in Forward use]
        SendDeathMsg(iAttacker, iVictim)
       
        ExecuteForward(g_iForwards[FORWARD_PRE_INFECTED], g_iFwReturn, iVictim, iAttacker)
       
        if (g_iFwReturn > 0)
        {
            return HC_CONTINUE
        }
       
        Set_User_Zombie(iVictim)
       
        ExecuteForward(g_iForwards[FORWARD_INFECTED], g_iFwReturn, iVictim, iAttacker)
       
        if (g_iAliveHumansNum == 1) // Check if this is Last Human, Because of Delay i can't check if it's 0 instead of 1
        {
            // End round event called one time
            g_bEndCalled = true
           
            // Round is Ending
            g_bIsRoundEnding = true
           
            // Zombie Win, Leave text blank so we use ours from ML
            rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
           
            // Show Our Message
            client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
           
            // This needed so forward work also to add +1 for Zombies
            g_iTeam = 1 // ZE_TEAM_ZOMBIE
            ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
        }
    }
   
    return HC_CONTINUE
}
 
public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
{
    // Not Vaild Victim or Attacker so skip the event (Important to block out bounds errors)
    if (!is_user_connected(iVictim) || !is_user_connected(iAttacker))
        return HC_CONTINUE
   
    // Set Knockback here, So if we blocked damage in TraceAttack event player won't get knockback (Fix For Madness)
    if (g_bIsZombie[iVictim] && !g_bIsZombie[iAttacker])
    {
        // Remove Shock Pain
        set_member(iVictim, m_flVelocityModifier, 1.0)
       
        // Set Knockback
        static Float:flOrigin[3]
        get_entvar(iAttacker, var_origin, flOrigin)
        Set_Knockback(iVictim, flOrigin, get_pcvar_float(g_pCvarZombieKnockback), 2)
    }
   
    return HC_CONTINUE
}
 
public Round_End()
{
    g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
   
    if (g_iAliveZombiesNum == 0 && g_bGameStarted)
    {
        g_iTeam = 2 // ZE_TEAM_HUMAN
        ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
        client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
        g_iHumansScore++
        g_bIsRoundEnding = true
        return // To block Execute the code blew
    }
   
    g_iTeam = 1 // ZE_TEAM_ZOMBIE
    g_iZombiesScore++
    g_bIsRoundEnding = true
   
    // If it's already called one time, don't call it again
    if (!g_bEndCalled)
    {
        ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
    }
   
    client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
}
 
public Event_RoundEnd_Pre(WinStatus:status, ScenarioEventEndRound:event, Float:tmDelay)
{
    // The two unhandeld cases by rg_round_end() native in our Mod
    if (event == ROUND_CTS_WIN || event == ROUND_TERRORISTS_WIN)
    {
        SetHookChainArg(3, ATYPE_FLOAT, get_pcvar_float(g_pCvarRoundEndDelay))
    }
}
 
public Round_Start()
{
    g_flReferenceTime = get_gametime()
    g_iRoundTime = get_member_game(m_iRoundTime)
}
 
public Check_RoundTimeleft()
{
    new Float:flRoundTimeLeft = (g_flReferenceTime + float(g_iRoundTime)) - get_gametime()
   
    if (floatround(flRoundTimeLeft) == 0)
    {
        // Round is Ending
        g_bIsRoundEnding = true
       
        // If Time is Out then Terminate the Round
        rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
       
        // Show our Message
        client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
    }
}
 
public client_disconnected(id)
{
    // Delay Then Check Players to Terminate The round (Delay needed)
    set_task(0.1, "Check_AlivePlayers")
   
    // Reset speed for this dropped id
    g_bHSpeedUsed[id] = false
    g_bZSpeedUsed[id] = false
}
 
// This check done when player disconnect
public Check_AlivePlayers()
{
    g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
    g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
   
    // Game Started? (There is at least 2 players Alive?)
    if (g_bGameStarted)
    {
        // We are in freeze time?
        if (get_member_game(m_bFreezePeriod))
        {
            // Humans alive number = 1 and no zombies?
            if (g_iAliveHumansNum < get_pcvar_num(g_pCvarReqPlayers))
            {
                // Game started false again
                g_bGameStarted = false
            }
        }
        else // Not freeze time?
        {
            // Variables
            new iAllZombiesNum = GetTeamPlayersNum(CsTeams:TEAM_TERRORIST),
            iAllHumansNum = GetTeamPlayersNum(CsTeams:TEAM_CT),
            iDeadZombiesNum = GetDeadPlayersNum(CsTeams:TEAM_TERRORIST),
            iDeadHumansNum = GetDeadPlayersNum(CsTeams:TEAM_CT)
   
            // Alive humans number = 1 and no zombies at all, And no dead humans?
            if (g_iAliveHumansNum < get_pcvar_num(g_pCvarReqPlayers) && iDeadHumansNum == 0 && iAllZombiesNum == 0)
            {
                // Game started is false and humans wins (Escape Success)
                g_bGameStarted = false
                rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_CTS, ROUND_CTS_WIN, "")
                client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
            }
           
            // Alive zombies number = 1 and no humans at all, And no dead zombies?
            if (g_iAliveZombiesNum < get_pcvar_num(g_pCvarReqPlayers) && iDeadZombiesNum == 0 && iAllHumansNum == 0)
            {
                // Game started is false and zombies wins (Escape Fail)
                g_bGameStarted = false
                rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
                client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
            }
           
            // Humans number more than 1 and no zombies?
            if (g_iAliveHumansNum >= get_pcvar_num(g_pCvarReqPlayers) && g_iAliveZombiesNum == 0 && !g_bIsRoundEnding)
            {
                // Then Escape success as there is no Zombies
                rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_CTS, ROUND_CTS_WIN, "")
                client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
            }
           
            // Zombies number more than 1 and no humans?
            if (g_iAliveZombiesNum >= get_pcvar_num(g_pCvarReqPlayers) && g_iAliveHumansNum == 0 && !g_bIsRoundEnding)
            {
                // Then Escape Fail as there is no humans
                rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
                client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
            }
        }
    }
}
 
public client_putinserver(id)
{
    // Add Delay and Check Conditions To start the Game (Delay needed)
    set_task(1.0, "Check_AllPlayersNumber", _, _, _, "b")
}
 
public Check_AllPlayersNumber(TaskID)
{
    if (g_bGameStarted)
    {
        // If game started remove the task and block the blew Checks
        remove_task(TaskID)
        return
    }
   
    if (GetAllAlivePlayersNum() >= get_pcvar_num(g_pCvarReqPlayers))
    {
        // Players In server == The Required so game started is true
        g_bGameStarted = true
       
        // Restart the game
        server_cmd("sv_restart 2")
       
        // Print Fake game Commencing Message
        client_print(0, print_center, "%L", LANG_PLAYER, "START_GAME")
       
        // Remove the task
        remove_task(TaskID)
    }
}
 
public Set_User_Human(id)
{
    if (!is_user_alive(id))
        return
   
    g_bIsZombie[id] = false
    set_entvar(id, var_health, get_pcvar_float(g_pCvarHumanHealth))
    set_entvar(id, var_gravity, get_pcvar_float(g_pCvarHumanGravity)/800.0)
    ExecuteForward(g_iForwards[FORWARD_HUMANIZED], g_iFwReturn, id)
   
    if (get_member(id, m_iTeam) != TEAM_CT)
        rg_set_user_team(id, TEAM_CT, MODEL_UNASSIGNED)
}
 
public Set_User_Zombie(id)
{
    if (!is_user_alive(id))
        return
   
    g_bIsZombie[id] = true
    set_entvar(id, var_health, get_pcvar_float(g_pCvarZombieHealth))
    set_entvar(id, var_gravity, get_pcvar_float(g_pCvarZombieGravity)/800.0)
    rg_remove_all_items(id)
    rg_give_item(id, "weapon_knife", GT_APPEND)
    ExecuteForward(g_iForwards[FORWARD_INFECTED], g_iFwReturn, id, 0)
   
    if (get_member(id, m_iTeam) != TEAM_TERRORIST)
        rg_set_user_team(id, TEAM_TERRORIST, MODEL_UNASSIGNED)
}
 
public Map_Restart()
{
    // Add Delay To help Rest Scores if player kill himself, and there no one else him so round draw (Delay needed)
    set_task(0.1, "Reset_Score_Message")
}
 
public Reset_Score_Message()
{
    g_iHumansScore = 0
    g_iZombiesScore = 0
    g_iRoundNum = 0
}
 
// Natives
public native_ze_is_user_zombie(id)
{
    if (!is_user_connected(id))
    {
        return -1;
    }
   
    return g_bIsZombie[id]
}
 
public native_ze_set_user_zombie(id)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    Set_User_Zombie(id)
    return true;
}
 
public native_ze_set_user_human(id)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    Set_User_Human(id)
    return true;
}
 
public native_ze_is_game_started()
{
    return g_bGameStarted
}
 
public native_ze_is_zombie_frozen(id)
{
    if (!is_user_connected(id) || !g_bIsZombie[id])
    {
        return -1;
    }
   
    return g_bIsZombieFrozen[id]
}
 
public native_ze_get_round_number()
{
    if (!g_bGameStarted)
    {
        return -1;
    }
   
    return g_iRoundNum
}
 
public native_ze_get_humans_number()
{
    return GetAlivePlayersNum(CsTeams:TEAM_CT)
}
 
public native_ze_get_zombies_number()
{
    return GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
}
 
public native_ze_set_human_speed_factor(id, iFactor)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    g_bHSpeedUsed[id] = true
    g_iHSpeedFactor[id] = iFactor
    ExecuteHamB(Ham_Item_PreFrame, id)
    return true;
}
 
public native_ze_reset_human_speed(id)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    g_bHSpeedUsed[id] = false
    ExecuteHamB(Ham_Item_PreFrame, id)
    return true;
}
 
public native_ze_set_zombie_speed(id, iSpeed)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    g_bZSpeedUsed[id] = true
    g_iZSpeedSet[id] = iSpeed
    return true;
}
 
public native_ze_reset_zombie_speed(id)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    g_bZSpeedUsed[id] = false
    return true;
}
Image

User avatar
Spir0x
Veteran Member
Veteran Member
Tunisia
Posts: 552
Joined: 1 Year Ago
Location: Tunisia
Has thanked: 14 times
Been thanked: 6 times
Age: 18
Contact:

#7

Post by Spir0x » 1 Week Ago

this won't compile it shows 4 errors.

Code: Select all

#include <zombie_escape>
 
// Fowards
enum _:TOTAL_FORWARDS
{
    FORWARD_NONE = 0,
    FORWARD_ROUNDEND,
    FORWARD_HUMANIZED,
    FORWARD_PRE_INFECTED,
    FORWARD_INFECTED,
    FORWARD_ZOMBIE_APPEAR,
    FORWARD_ZOMBIE_RELEASE,
    FORWARD_GAME_STARTED
}
 
new g_iForwards[TOTAL_FORWARDS], g_iFwReturn, g_iTeam
 
// Tasks IDs
enum
{
    TASK_COUNTDOWN = 1100,
    TASK_COUNTDOWN2,
    TASK_SCORE_MESSAGE,
    FREEZE_ZOMBIES,
    ROUND_TIME_LEFT
}
 
// Colors (g_pCvarColors[] array indexes)
enum
{
    Red = 0,
    Green,
    Blue
}
 
// Variables
new g_iAliveHumansNum,
    g_iAliveZombiesNum,
    g_iRoundTime,
    g_iCountDown,
    g_iReleaseNotice,
    g_iMaxClients,
    g_iHumansScore,
    g_iZombiesScore,
    g_iRoundNum,
    g_iHSpeedFactor[33],
    g_iZSpeedSet[33],
    bool:g_bGameStarted,
    bool:g_bIsZombie[33],
    bool:g_bIsZombieFrozen[33],
    bool:g_bZombieFreezeTime,
    bool:g_bIsRoundEnding,
    bool:g_bHSpeedUsed[33],
    bool:g_bZSpeedUsed[33],
    bool:g_bEndCalled,
    Float:g_flReferenceTime
 
// Cvars
new g_pCvarHumanSpeedFactor,
    g_pCvarHumanGravity,
    g_pCvarHumanHealth,
    g_pCvarZombieSpeed,
    g_pCvarZombieGravity,
    g_pCvarZombieReleaseTime,
    g_pCvarFreezeTime,
    g_pCvarRoundTime,
    g_pCvarReqPlayers,
    g_pCvarZombieHealth,
    g_pCvarFirstZombiesHealth,
    g_pCvarZombieKnockback,
    g_pCvarScoreMessageType,
    g_pCvarColors[3],
    g_pCvarRoundEndDelay
 
public plugin_natives()
{
    register_native("ze_is_user_zombie", "native_ze_is_user_zombie", 1)
    register_native("ze_is_game_started", "native_ze_is_game_started", 1)
    register_native("ze_is_zombie_frozen", "native_ze_is_zombie_frozen", 1)
   
    register_native("ze_get_round_number", "native_ze_get_round_number", 1)
    register_native("ze_get_humans_number", "native_ze_get_humans_number", 1)
    register_native("ze_get_zombies_number", "native_ze_get_zombies_number", 1)
   
    register_native("ze_set_user_zombie", "native_ze_set_user_zombie", 1)
    register_native("ze_set_user_human", "native_ze_set_user_human", 1)
    register_native("ze_set_human_speed_factor", "native_ze_set_human_speed_factor", 1)
    register_native("ze_set_zombie_speed", "native_ze_set_zombie_speed", 1)
   
    register_native("ze_reset_human_speed", "native_ze_reset_human_speed", 1)
    register_native("ze_reset_zombie_speed", "native_ze_reset_zombie_speed", 1)
}
 
public plugin_init()
{
    register_plugin("[ZE] Core/Engine", ZE_VERSION, AUTHORS)
   
    // Hook Chains
    RegisterHookChain(RG_CBasePlayer_TraceAttack, "Fw_TraceAttack_Pre", 0)
    RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
    RegisterHookChain(RG_CBasePlayer_Spawn, "Fw_PlayerSpawn_Post", 1)
    RegisterHookChain(RG_CSGameRules_CheckWinConditions, "Fw_CheckMapConditions_Post", 1)
    RegisterHookChain(RG_CBasePlayer_Killed, "Fw_PlayerKilled_Post", 1)
    RegisterHookChain(RG_RoundEnd, "Event_RoundEnd_Pre", 0)
   
    // Events
    register_event("HLTV", "New_Round", "a", "1=0", "2=0")
    register_event("TextMsg", "Map_Restart", "a", "2=#Game_Commencing", "2=#Game_will_restart_in", "2=#Round_Draw")
    register_logevent("Round_Start", 2, "1=Round_Start")
    register_logevent("Round_End", 2, "1=Round_End")
   
    // Hams
    RegisterHam(Ham_Item_PreFrame, "player", "Fw_RestMaxSpeed_Post", 1)
   
    // Create Forwards (All Return Values Ignored)
    g_iForwards[FORWARD_ROUNDEND] = CreateMultiForward("ze_roundend", ET_IGNORE, FP_CELL)
    g_iForwards[FORWARD_HUMANIZED] = CreateMultiForward("ze_user_humanized", ET_IGNORE, FP_CELL)
    g_iForwards[FORWARD_PRE_INFECTED] = CreateMultiForward("ze_user_infected_pre", ET_CONTINUE, FP_CELL, FP_CELL)
    g_iForwards[FORWARD_INFECTED] = CreateMultiForward("ze_user_infected", ET_IGNORE, FP_CELL, FP_CELL)
    g_iForwards[FORWARD_ZOMBIE_APPEAR] = CreateMultiForward("ze_zombie_appear", ET_IGNORE)
    g_iForwards[FORWARD_ZOMBIE_RELEASE] = CreateMultiForward("ze_zombie_release", ET_IGNORE)
    g_iForwards[FORWARD_GAME_STARTED] = CreateMultiForward("ze_game_started", ET_IGNORE)
   
    // Hud Messages
    g_iReleaseNotice = CreateHudSyncObj()
   
    // Sequential files (.txt)
    register_dictionary("zombie_escape.txt")
   
    // Humans Cvars
    g_pCvarHumanSpeedFactor = register_cvar("ze_human_speed_factor", "20.0")
    g_pCvarHumanGravity = register_cvar("ze_human_gravity", "800")
    g_pCvarHumanHealth = register_cvar("ze_human_health", "1000")
   
    // Zombie Cvars
    g_pCvarZombieSpeed = register_cvar("ze_zombie_speed", "350.0")
    g_pCvarZombieGravity = register_cvar("ze_zombie_gravity", "640")
    g_pCvarZombieHealth = register_cvar("ze_zombie_health", "10000")
    g_pCvarFirstZombiesHealth = register_cvar("ze_first_zombies_health", "20000")
    g_pCvarZombieKnockback = register_cvar("ze_zombie_knockback", "300.0")
   
    // General Cvars
    g_pCvarZombieReleaseTime = register_cvar("ze_release_time", "15")
    g_pCvarFreezeTime = register_cvar("ze_freeze_time", "20")
    g_pCvarRoundTime = register_cvar("ze_round_time", "9.0")
    g_pCvarReqPlayers = register_cvar("ze_required_players", "2")
    g_pCvarScoreMessageType = register_cvar("ze_score_message_type", "1")
    g_pCvarColors[Red] = register_cvar("ze_score_message_red", "200")
    g_pCvarColors[Green] = register_cvar("ze_score_message_green", "100")
    g_pCvarColors[Blue] = register_cvar("ze_score_message_blue", "0")
    g_pCvarRoundEndDelay = register_cvar("ze_round_end_delay", "5")
   
    // Default Values
    g_bGameStarted = false
   
    // Static Values
    g_iMaxClients = get_member_game(m_nMaxPlayers)
   
    // Check Round Time to Terminate it
    set_task(1.0, "Check_RoundTimeleft", ROUND_TIME_LEFT, _, _, "b")
}
 
public plugin_cfg()
{
    // Get our configiration file and Execute it
    new szCfgDir[64]
    get_localinfo("amxx_configsdir", szCfgDir, charsmax(szCfgDir))
    server_cmd("exec %s/zombie_escape.cfg", szCfgDir)
   
    // Set Game Name
    new szGameName[64]
    formatex(szGameName, sizeof(szGameName), "Premuim ZE v%s", ZE_VERSION)
    set_member_game(m_GameDesc, szGameName)
   
    // Set Version
    register_cvar("ze_version", ZE_VERSION, FCVAR_SERVER|FCVAR_SPONLY)
    set_cvar_string("ze_version", ZE_VERSION)
}
 
public Fw_CheckMapConditions_Post()
{
    // Block Game Commencing
    set_member_game(m_bGameStarted, true)
   
    // Set Freeze Time
    set_member_game(m_iIntroRoundTime, get_pcvar_num(g_pCvarFreezeTime))
   
    // Set Round Time
    set_member_game(m_iRoundTime, floatround(get_pcvar_float(g_pCvarRoundTime) * 60.0))
}
 
public Fw_PlayerKilled_Post(id)
{
    g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
    g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
   
    if (g_iAliveHumansNum == 0 && g_iAliveZombiesNum == 0)
    {
        // No Winner, All Players in one team killed Or Both teams Killed
        client_print(0, print_center, "%L", LANG_PLAYER, "NO_WINNER")
    }
}
 
public Fw_RestMaxSpeed_Post(id)
{
    if (!g_bIsZombie[id])
    {
        static Float:flMaxSpeed
        get_entvar(id, var_maxspeed, flMaxSpeed)
       
        if (flMaxSpeed != 1.0 && is_user_alive(id))
        {
            if (g_bHSpeedUsed[id])
            {
                // Set New Human Speed Factor
                set_entvar(id, var_maxspeed, flMaxSpeed + float(g_iHSpeedFactor[id]))
                return HAM_IGNORED
            }
               
            // Set Human Speed Factor, native not used
            set_entvar(id, var_maxspeed, flMaxSpeed + get_pcvar_float(g_pCvarHumanSpeedFactor))
            return HAM_IGNORED
        }
    }
   
    return HAM_SUPERCEDE
}
 
public Fw_PlayerSpawn_Post(id)
{  
    if (!g_bGameStarted)
    {
        // Force All player to be Humans if Game not started yet
        rg_set_user_team(id, TEAM_CT, MODEL_UNASSIGNED)
    }
    else
    {
        if (get_member_game(m_bFreezePeriod))
        {
            // Respawn Him As human if we are in freeze time (Zombie Not Chosen yet)
            Set_User_Human(id)
            g_bIsZombieFrozen[id] = false
        }
        else
        {
            if (g_bZombieFreezeTime)
            {
                // Zombie Chosen and zombies Frozen, Spawn him as zombie and Freeze Him
                Set_User_Zombie(id)
                g_bIsZombieFrozen[id] = true
                set_entvar(id, var_maxspeed, 1.0)
            }
            else
            {
                // Respawn him as normal zombie
                Set_User_Zombie(id)
                g_bIsZombieFrozen[id] = false
            }
        }
    }
}
 
public New_Round()
{
    // Remove All tasks in the New Round
    remove_task(TASK_COUNTDOWN)
    remove_task(TASK_COUNTDOWN2)
    remove_task(TASK_SCORE_MESSAGE)
    remove_task(FREEZE_ZOMBIES)
   
    // Score Message Task
    set_task(10.0, "Score_Message", TASK_SCORE_MESSAGE, _, _, "b")
   
    // 2 is Hardcoded Value, It's Fix for the countdown to work correctly
    g_iCountDown = get_pcvar_num(g_pCvarFreezeTime) - 2
   
    if (!g_bGameStarted)
    {
        // No Enough Players
        ze_colored_print(0, "%L", LANG_PLAYER, "NO_ENOUGH_PLAYERS", get_pcvar_num(g_pCvarReqPlayers))
        return // Block the execution of the blew code
    }
   
    // Game Already started, Countdown now started
    set_task(1.0, "Countdown_Start", TASK_COUNTDOWN, _, _, "b")
    ze_colored_print(0, "%L", LANG_PLAYER, "READY_TO_RUN")
    ExecuteForward(g_iForwards[FORWARD_GAME_STARTED], g_iFwReturn)
   
    g_iRoundNum++
   
    // Round Starting
    g_bIsRoundEnding = false
    g_bEndCalled = false
}
 
// Score Message Task
public Score_Message(TaskID)
{
    switch(get_pcvar_num(g_pCvarScoreMessageType))
    {
        case 0: // Disabled
        {
            return
        }
        case 1: // DHUD
        {
            set_dhudmessage(0, 255, 0, 0.38, 0.01, 0, 0.0, 9.0)
            show_dhudmessage(0, "Survivors")
           
            set_dhudmessage(255, 255, 255, -1.0, 0.01, 0, 0.0, 9.0)
            show_dhudmessage(0, "[VS]")
           
            set_dhudmessage(255, 0, 0, 0.54, 0.01, 0, 0.0, 9.0)
            show_dhudmessage(0, "Zombies")
           
            set_dhudmessage(255, 255, 255, -1.0, 0.045, 0, 0.0, 9.0)
            show_dhudmessage(0, "[%i] --------- [%i]", g_iHumansScore, g_iZombiesScore)

            set_dhudmessage( .red = 0, .green = 255, .blue = 0, .x = -1.0, .y = 0.02, .effects = 0, .fxtime = 6.0, .holdtime = 2.0, .fadeintime = 1.0, .fadeouttime = 1.0, .reliable = false ); 
            show_dhudmessage( 0, "%L                        ", LANG_PLAYER, "SCORE_HUMANS", native_ze_get_humans_number() );
            set_dhudmessage( .red = 100, .green = 100, .blue = 100, .x = -1.0, .y = 0.02, .effects = 0, .fxtime = 6.0, .holdtime = 2.0, .fadeintime = 1.0, .fadeouttime = 1.0, .reliable = false ); 
            show_dhudmessage( 0, "%L^n%L", LANG_PLAYER, "SCORE_ROUND", g_iRoundNum, LANG_PLAYER,  "SCORE_WINS", g_iHumansScore,  g_iZombiesScore );
            set_dhudmessage( .red = 255, .green = 0, .blue = 0, .x = -1.0, .y = 0.02, .effects = 0, .fxtime = 6.0, .holdtime = 2.0, .fadeintime = 1.0, .fadeouttime = 1.0, .reliable = false ); 
            show_dhudmessage( 0, "                         %L", LANG_PLAYER, "SCORE_ZOMBIES", native_ze_get_zombies_number() );
        }
        case 2: // HUD
        {
            set_hudmessage(get_pcvar_num(g_pCvarColors[Red]), get_pcvar_num(g_pCvarColors[Green]), get_pcvar_num(g_pCvarColors[Blue]), -1.0, 0.01, 0, 0.0, 9.0)
            show_hudmessage(0, "%L", LANG_PLAYER, "SCORE_MESSAGE", g_iZombiesScore, g_iHumansScore)
        }
    }
}
 
public Countdown_Start(TaskID)
{
    // Check if the players Disconnected and there is only one player then remove all messages, and stop tasks
    if (!g_bGameStarted)
        return
   
    if (!g_iCountDown)
    {
        Choose_Zombies()
        remove_task(TASK_COUNTDOWN) // Remove the task
        return // Block the execution of the blew code
    }
   
    set_hudmessage(random(256), random(256), random(256), -1.0, 0.21, 0, 0.8, 0.8)
    show_hudmessage(0, "%L", LANG_PLAYER, "RUN_NOTICE", g_iCountDown)
 
    g_iCountDown--
}
 
public Choose_Zombies()
{
    new iZombies, id, iAliveCount
    new iReqZombies
   
    // Get total alive players and required players
    iAliveCount  = GetAllAlivePlayersNum()
    iReqZombies = RequiredZombies()
   
    // Loop till we find req players
    while(iZombies < iReqZombies)
    {
        id = GetRandomAlive(random_num(1, iAliveCount))
       
        if (!is_user_alive(id) || g_bIsZombie[id])
            continue
 
        Set_User_Zombie(id)
        set_entvar(id, var_health, get_pcvar_float(g_pCvarFirstZombiesHealth))
        g_bIsZombieFrozen[id] = true
        g_bZombieFreezeTime = true
        set_entvar(id, var_maxspeed, 1.0)
        set_task(0.1, "Freeze_Zombies", FREEZE_ZOMBIES, _, _, "b") // Better than PreThink
        ExecuteForward(g_iForwards[FORWARD_ZOMBIE_APPEAR], g_iFwReturn)
        iZombies++
       
        // Respawn Zombies to base
        rg_round_respawn(id)
    }
   
    // 2 is Hardcoded Value, It's Fix for the countdown to work correctly
    g_iCountDown = get_pcvar_num(g_pCvarZombieReleaseTime) - 2
   
    set_task(1.0, "ReleaseZombie_CountDown", TASK_COUNTDOWN2, _, _, "b")
}
 
public ReleaseZombie_CountDown(TaskID)
{
    if (!g_iCountDown)
    {
        ReleaseZombie()
        remove_task(TASK_COUNTDOWN2)
        return
    }
   
    // Release Hud Message
    set_hudmessage(255, 255, 0, -1.0, 0.21, 1, 2.0, 2.0)
    ShowSyncHudMsg(0, g_iReleaseNotice, "%L", LANG_PLAYER, "ZOMBIE_RELEASE", g_iCountDown)
   
    g_iCountDown --
}
 
public ReleaseZombie()
{
    ExecuteForward(g_iForwards[FORWARD_ZOMBIE_RELEASE], g_iFwReturn)
   
    for(new id = 1; id <= g_iMaxClients; id++)
    {
        if (is_user_alive(id) && g_bIsZombie[id])
        {
            g_bIsZombieFrozen[id] = false
            g_bZombieFreezeTime = false
        }
    }
}
 
public Freeze_Zombies(TaskID)
{
    for(new id = 1; id <= g_iMaxClients; id++)
    {
        if(!is_user_alive(id) || !g_bIsZombie[id])
            continue
       
        if (g_bIsZombieFrozen[id])
        {
            // Zombie & Frozen, then Freeze him
            set_entvar(id, var_maxspeed, 1.0)
        }
        else
        {
            if (g_bZSpeedUsed[id])
            {
                // Zombie but Not Frozen the set his speed form .cfg
                set_entvar(id, var_maxspeed, float(g_iZSpeedSet[id]))
                continue;
            }
               
            // Zombie but Not Frozen the set his speed form .cfg
            set_entvar(id, var_maxspeed, get_pcvar_float(g_pCvarZombieSpeed))
        }
    }
}
 
public Fw_TraceAttack_Pre(iVictim, iAttacker, Float:flDamage, Float:flDirection[3], iTracehandle, bitsDamageType)
{
    if (iVictim == iAttacker || !is_user_connected(iVictim) || !is_user_connected(iAttacker))
        return HC_CONTINUE
   
    // Attacker and Victim is in same teams? Skip code blew
    if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
        return HC_CONTINUE
   
    // In freeze time? Skip all other plugins (Skip the real trace attack event)
    if (g_bIsZombieFrozen[iVictim] || g_bIsZombieFrozen[iAttacker])
        return HC_SUPERCEDE
   
    g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
   
    if (g_bIsZombie[iAttacker])
    {
        // Death Message with Infection style [Added here because of delay in Forward use]
        SendDeathMsg(iAttacker, iVictim)
       
        ExecuteForward(g_iForwards[FORWARD_PRE_INFECTED], g_iFwReturn, iVictim, iAttacker)
       
        if (g_iFwReturn > 0)
        {
            return HC_CONTINUE
        }
       
        Set_User_Zombie(iVictim)
       
        ExecuteForward(g_iForwards[FORWARD_INFECTED], g_iFwReturn, iVictim, iAttacker)
       
        if (g_iAliveHumansNum == 1) // Check if this is Last Human, Because of Delay i can't check if it's 0 instead of 1
        {
            // End round event called one time
            g_bEndCalled = true
           
            // Round is Ending
            g_bIsRoundEnding = true
           
            // Zombie Win, Leave text blank so we use ours from ML
            rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
           
            // Show Our Message
            client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
           
            // This needed so forward work also to add +1 for Zombies
            g_iTeam = 1 // ZE_TEAM_ZOMBIE
            ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
        }
    }
   
    return HC_CONTINUE
}
 
public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
{
    // Not Vaild Victim or Attacker so skip the event (Important to block out bounds errors)
    if (!is_user_connected(iVictim) || !is_user_connected(iAttacker))
        return HC_CONTINUE
   
    // Set Knockback here, So if we blocked damage in TraceAttack event player won't get knockback (Fix For Madness)
    if (g_bIsZombie[iVictim] && !g_bIsZombie[iAttacker])
    {
        // Remove Shock Pain
        set_member(iVictim, m_flVelocityModifier, 1.0)
       
        // Set Knockback
        static Float:flOrigin[3]
        get_entvar(iAttacker, var_origin, flOrigin)
        Set_Knockback(iVictim, flOrigin, get_pcvar_float(g_pCvarZombieKnockback), 2)
    }
   
    return HC_CONTINUE
}
 
public Round_End()
{
    g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
   
    if (g_iAliveZombiesNum == 0 && g_bGameStarted)
    {
        g_iTeam = 2 // ZE_TEAM_HUMAN
        ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
        client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
        g_iHumansScore++
        g_bIsRoundEnding = true
        return // To block Execute the code blew
    }
   
    g_iTeam = 1 // ZE_TEAM_ZOMBIE
    g_iZombiesScore++
    g_bIsRoundEnding = true
   
    // If it's already called one time, don't call it again
    if (!g_bEndCalled)
    {
        ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
    }
   
    client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
}
 
public Event_RoundEnd_Pre(WinStatus:status, ScenarioEventEndRound:event, Float:tmDelay)
{
    // The two unhandeld cases by rg_round_end() native in our Mod
    if (event == ROUND_CTS_WIN || event == ROUND_TERRORISTS_WIN)
    {
        SetHookChainArg(3, ATYPE_FLOAT, get_pcvar_float(g_pCvarRoundEndDelay))
    }
}
 
public Round_Start()
{
    g_flReferenceTime = get_gametime()
    g_iRoundTime = get_member_game(m_iRoundTime)
}
 
public Check_RoundTimeleft()
{
    new Float:flRoundTimeLeft = (g_flReferenceTime + float(g_iRoundTime)) - get_gametime()
   
    if (floatround(flRoundTimeLeft) == 0)
    {
        // Round is Ending
        g_bIsRoundEnding = true
       
        // If Time is Out then Terminate the Round
        rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
       
        // Show our Message
        client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
    }
}
 
public client_disconnected(id)
{
    // Delay Then Check Players to Terminate The round (Delay needed)
    set_task(0.1, "Check_AlivePlayers")
   
    // Reset speed for this dropped id
    g_bHSpeedUsed[id] = false
    g_bZSpeedUsed[id] = false
}
 
// This check done when player disconnect
public Check_AlivePlayers()
{
    g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
    g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
   
    // Game Started? (There is at least 2 players Alive?)
    if (g_bGameStarted)
    {
        // We are in freeze time?
        if (get_member_game(m_bFreezePeriod))
        {
            // Humans alive number = 1 and no zombies?
            if (g_iAliveHumansNum < get_pcvar_num(g_pCvarReqPlayers))
            {
                // Game started false again
                g_bGameStarted = false
            }
        }
        else // Not freeze time?
        {
            // Variables
            new iAllZombiesNum = GetTeamPlayersNum(CsTeams:TEAM_TERRORIST),
            iAllHumansNum = GetTeamPlayersNum(CsTeams:TEAM_CT),
            iDeadZombiesNum = GetDeadPlayersNum(CsTeams:TEAM_TERRORIST),
            iDeadHumansNum = GetDeadPlayersNum(CsTeams:TEAM_CT)
   
            // Alive humans number = 1 and no zombies at all, And no dead humans?
            if (g_iAliveHumansNum < get_pcvar_num(g_pCvarReqPlayers) && iDeadHumansNum == 0 && iAllZombiesNum == 0)
            {
                // Game started is false and humans wins (Escape Success)
                g_bGameStarted = false
                rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_CTS, ROUND_CTS_WIN, "")
                client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
            }
           
            // Alive zombies number = 1 and no humans at all, And no dead zombies?
            if (g_iAliveZombiesNum < get_pcvar_num(g_pCvarReqPlayers) && iDeadZombiesNum == 0 && iAllHumansNum == 0)
            {
                // Game started is false and zombies wins (Escape Fail)
                g_bGameStarted = false
                rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
                client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
            }
           
            // Humans number more than 1 and no zombies?
            if (g_iAliveHumansNum >= get_pcvar_num(g_pCvarReqPlayers) && g_iAliveZombiesNum == 0 && !g_bIsRoundEnding)
            {
                // Then Escape success as there is no Zombies
                rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_CTS, ROUND_CTS_WIN, "")
                client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
            }
           
            // Zombies number more than 1 and no humans?
            if (g_iAliveZombiesNum >= get_pcvar_num(g_pCvarReqPlayers) && g_iAliveHumansNum == 0 && !g_bIsRoundEnding)
            {
                // Then Escape Fail as there is no humans
                rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
                client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
            }
        }
    }
}
 
public client_putinserver(id)
{
    // Add Delay and Check Conditions To start the Game (Delay needed)
    set_task(1.0, "Check_AllPlayersNumber", _, _, _, "b")
}
 
public Check_AllPlayersNumber(TaskID)
{
    if (g_bGameStarted)
    {
        // If game started remove the task and block the blew Checks
        remove_task(TaskID)
        return
    }
   
    if (GetAllAlivePlayersNum() >= get_pcvar_num(g_pCvarReqPlayers))
    {
        // Players In server == The Required so game started is true
        g_bGameStarted = true
       
        // Restart the game
        server_cmd("sv_restart 2")
       
        // Print Fake game Commencing Message
        client_print(0, print_center, "%L", LANG_PLAYER, "START_GAME")
       
        // Remove the task
        remove_task(TaskID)
    }
}
 
public Set_User_Human(id)
{
    if (!is_user_alive(id))
        return
   
    g_bIsZombie[id] = false
    set_entvar(id, var_health, get_pcvar_float(g_pCvarHumanHealth))
    set_entvar(id, var_gravity, get_pcvar_float(g_pCvarHumanGravity)/800.0)
    ExecuteForward(g_iForwards[FORWARD_HUMANIZED], g_iFwReturn, id)
   
    if (get_member(id, m_iTeam) != TEAM_CT)
        rg_set_user_team(id, TEAM_CT, MODEL_UNASSIGNED)
}
 
public Set_User_Zombie(id)
{
    if (!is_user_alive(id))
        return
   
    g_bIsZombie[id] = true
    set_entvar(id, var_health, get_pcvar_float(g_pCvarZombieHealth))
    set_entvar(id, var_gravity, get_pcvar_float(g_pCvarZombieGravity)/800.0)
    rg_remove_all_items(id)
    rg_give_item(id, "weapon_knife", GT_APPEND)
    ExecuteForward(g_iForwards[FORWARD_INFECTED], g_iFwReturn, id, 0)
   
    if (get_member(id, m_iTeam) != TEAM_TERRORIST)
        rg_set_user_team(id, TEAM_TERRORIST, MODEL_UNASSIGNED)
}
 
public Map_Restart()
{
    // Add Delay To help Rest Scores if player kill himself, and there no one else him so round draw (Delay needed)
    set_task(0.1, "Reset_Score_Message")
}
 
public Reset_Score_Message()
{
    g_iHumansScore = 0
    g_iZombiesScore = 0
    g_iRoundNum = 0
}
 
// Natives
public native_ze_is_user_zombie(id)
{
    if (!is_user_connected(id))
    {
        return -1;
    }
   
    return g_bIsZombie[id]
}
 
public native_ze_set_user_zombie(id)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    Set_User_Zombie(id)
    return true;
}
 
public native_ze_set_user_human(id)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    Set_User_Human(id)
    return true;
}
 
public native_ze_is_game_started()
{
    return g_bGameStarted
}
 
public native_ze_is_zombie_frozen(id)
{
    if (!is_user_connected(id) || !g_bIsZombie[id])
    {
        return -1;
    }
   
    return g_bIsZombieFrozen[id]
}
 
public native_ze_get_round_number()
{
    if (!g_bGameStarted)
    {
        return -1;
    }
   
    return g_iRoundNum
}
 
public native_ze_get_humans_number()
{
    return GetAlivePlayersNum(CsTeams:TEAM_CT)
}
 
public native_ze_get_zombies_number()
{
    return GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
}
 
public native_ze_set_human_speed_factor(id, iFactor)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    g_bHSpeedUsed[id] = true
    g_iHSpeedFactor[id] = iFactor
    ExecuteHamB(Ham_Item_PreFrame, id)
    return true;
}
 
public native_ze_reset_human_speed(id)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    g_bHSpeedUsed[id] = false
    ExecuteHamB(Ham_Item_PreFrame, id)
    return true;
}
 
public native_ze_set_zombie_speed(id, iSpeed)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    g_bZSpeedUsed[id] = true
    g_iZSpeedSet[id] = iSpeed
    return true;
}
 
public native_ze_reset_zombie_speed(id)
{
    if (!is_user_connected(id))
    {
        log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
        return false;
    }
   
    g_bZSpeedUsed[id] = false
    return true;
}

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1717
Joined: 1 Year Ago
Location: Egypt
Has thanked: 28 times
Been thanked: 78 times
Age: 21
Contact:

#8

Post by Raheem » 1 Week Ago

  1. #include <zombie_escape>
  2.  
  3. // Fowards
  4. enum _:TOTAL_FORWARDS
  5. {
  6.     FORWARD_NONE = 0,
  7.     FORWARD_ROUNDEND,
  8.     FORWARD_HUMANIZED,
  9.     FORWARD_PRE_INFECTED,
  10.     FORWARD_INFECTED,
  11.     FORWARD_ZOMBIE_APPEAR,
  12.     FORWARD_ZOMBIE_RELEASE,
  13.     FORWARD_GAME_STARTED
  14. }
  15.  
  16. new g_iForwards[TOTAL_FORWARDS], g_iFwReturn, g_iTeam
  17.  
  18. // Tasks IDs
  19. enum
  20. {
  21.     TASK_COUNTDOWN = 1100,
  22.     TASK_COUNTDOWN2,
  23.     TASK_SCORE_MESSAGE,
  24.     FREEZE_ZOMBIES,
  25.     ROUND_TIME_LEFT
  26. }
  27.  
  28. // Colors (g_pCvarColors[] array indexes)
  29. enum
  30. {
  31.     Red = 0,
  32.     Green,
  33.     Blue
  34. }
  35.  
  36. // Variables
  37. new g_iAliveHumansNum,
  38.     g_iAliveZombiesNum,
  39.     g_iRoundTime,
  40.     g_iCountDown,
  41.     g_iReleaseNotice,
  42.     g_iMaxClients,
  43.     g_iHumansScore,
  44.     g_iZombiesScore,
  45.     g_iRoundNum,
  46.     g_iHSpeedFactor[33],
  47.     g_iZSpeedSet[33],
  48.     bool:g_bGameStarted,
  49.     bool:g_bIsZombie[33],
  50.     bool:g_bIsZombieFrozen[33],
  51.     bool:g_bZombieFreezeTime,
  52.     bool:g_bIsRoundEnding,
  53.     bool:g_bHSpeedUsed[33],
  54.     bool:g_bZSpeedUsed[33],
  55.     bool:g_bEndCalled,
  56.     Float:g_flReferenceTime
  57.  
  58. // Cvars
  59. new g_pCvarHumanSpeedFactor,
  60.     g_pCvarHumanGravity,
  61.     g_pCvarHumanHealth,
  62.     g_pCvarZombieSpeed,
  63.     g_pCvarZombieGravity,
  64.     g_pCvarZombieReleaseTime,
  65.     g_pCvarFreezeTime,
  66.     g_pCvarRoundTime,
  67.     g_pCvarReqPlayers,
  68.     g_pCvarZombieHealth,
  69.     g_pCvarFirstZombiesHealth,
  70.     g_pCvarZombieKnockback,
  71.     g_pCvarScoreMessageType,
  72.     g_pCvarColors[3],
  73.     g_pCvarRoundEndDelay
  74.  
  75. public plugin_natives()
  76. {
  77.     register_native("ze_is_user_zombie", "native_ze_is_user_zombie", 1)
  78.     register_native("ze_is_game_started", "native_ze_is_game_started", 1)
  79.     register_native("ze_is_zombie_frozen", "native_ze_is_zombie_frozen", 1)
  80.    
  81.     register_native("ze_get_round_number", "native_ze_get_round_number", 1)
  82.     register_native("ze_get_humans_number", "native_ze_get_humans_number", 1)
  83.     register_native("ze_get_zombies_number", "native_ze_get_zombies_number", 1)
  84.    
  85.     register_native("ze_set_user_zombie", "native_ze_set_user_zombie", 1)
  86.     register_native("ze_set_user_human", "native_ze_set_user_human", 1)
  87.     register_native("ze_set_human_speed_factor", "native_ze_set_human_speed_factor", 1)
  88.     register_native("ze_set_zombie_speed", "native_ze_set_zombie_speed", 1)
  89.    
  90.     register_native("ze_reset_human_speed", "native_ze_reset_human_speed", 1)
  91.     register_native("ze_reset_zombie_speed", "native_ze_reset_zombie_speed", 1)
  92. }
  93.  
  94. public plugin_init()
  95. {
  96.     register_plugin("[ZE] Core/Engine", ZE_VERSION, AUTHORS)
  97.    
  98.     // Hook Chains
  99.     RegisterHookChain(RG_CBasePlayer_TraceAttack, "Fw_TraceAttack_Pre", 0)
  100.     RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
  101.     RegisterHookChain(RG_CBasePlayer_Spawn, "Fw_PlayerSpawn_Post", 1)
  102.     RegisterHookChain(RG_CSGameRules_CheckWinConditions, "Fw_CheckMapConditions_Post", 1)
  103.     RegisterHookChain(RG_CBasePlayer_Killed, "Fw_PlayerKilled_Post", 1)
  104.     RegisterHookChain(RG_RoundEnd, "Event_RoundEnd_Pre", 0)
  105.    
  106.     // Events
  107.     register_event("HLTV", "New_Round", "a", "1=0", "2=0")
  108.     register_event("TextMsg", "Map_Restart", "a", "2=#Game_Commencing", "2=#Game_will_restart_in", "2=#Round_Draw")
  109.     register_logevent("Round_Start", 2, "1=Round_Start")
  110.     register_logevent("Round_End", 2, "1=Round_End")
  111.    
  112.     // Hams
  113.     RegisterHam(Ham_Item_PreFrame, "player", "Fw_RestMaxSpeed_Post", 1)
  114.    
  115.     // Create Forwards (All Return Values Ignored)
  116.     g_iForwards[FORWARD_ROUNDEND] = CreateMultiForward("ze_roundend", ET_IGNORE, FP_CELL)
  117.     g_iForwards[FORWARD_HUMANIZED] = CreateMultiForward("ze_user_humanized", ET_IGNORE, FP_CELL)
  118.     g_iForwards[FORWARD_PRE_INFECTED] = CreateMultiForward("ze_user_infected_pre", ET_CONTINUE, FP_CELL, FP_CELL)
  119.     g_iForwards[FORWARD_INFECTED] = CreateMultiForward("ze_user_infected", ET_IGNORE, FP_CELL, FP_CELL)
  120.     g_iForwards[FORWARD_ZOMBIE_APPEAR] = CreateMultiForward("ze_zombie_appear", ET_IGNORE)
  121.     g_iForwards[FORWARD_ZOMBIE_RELEASE] = CreateMultiForward("ze_zombie_release", ET_IGNORE)
  122.     g_iForwards[FORWARD_GAME_STARTED] = CreateMultiForward("ze_game_started", ET_IGNORE)
  123.    
  124.     // Hud Messages
  125.     g_iReleaseNotice = CreateHudSyncObj()
  126.    
  127.     // Sequential files (.txt)
  128.     register_dictionary("zombie_escape.txt")
  129.    
  130.     // Humans Cvars
  131.     g_pCvarHumanSpeedFactor = register_cvar("ze_human_speed_factor", "20.0")
  132.     g_pCvarHumanGravity = register_cvar("ze_human_gravity", "800")
  133.     g_pCvarHumanHealth = register_cvar("ze_human_health", "1000")
  134.    
  135.     // Zombie Cvars
  136.     g_pCvarZombieSpeed = register_cvar("ze_zombie_speed", "350.0")
  137.     g_pCvarZombieGravity = register_cvar("ze_zombie_gravity", "640")
  138.     g_pCvarZombieHealth = register_cvar("ze_zombie_health", "10000")
  139.     g_pCvarFirstZombiesHealth = register_cvar("ze_first_zombies_health", "20000")
  140.     g_pCvarZombieKnockback = register_cvar("ze_zombie_knockback", "300.0")
  141.    
  142.     // General Cvars
  143.     g_pCvarZombieReleaseTime = register_cvar("ze_release_time", "15")
  144.     g_pCvarFreezeTime = register_cvar("ze_freeze_time", "20")
  145.     g_pCvarRoundTime = register_cvar("ze_round_time", "9.0")
  146.     g_pCvarReqPlayers = register_cvar("ze_required_players", "2")
  147.     g_pCvarScoreMessageType = register_cvar("ze_score_message_type", "1")
  148.     g_pCvarColors[Red] = register_cvar("ze_score_message_red", "200")
  149.     g_pCvarColors[Green] = register_cvar("ze_score_message_green", "100")
  150.     g_pCvarColors[Blue] = register_cvar("ze_score_message_blue", "0")
  151.     g_pCvarRoundEndDelay = register_cvar("ze_round_end_delay", "5")
  152.    
  153.     // Default Values
  154.     g_bGameStarted = false
  155.    
  156.     // Static Values
  157.     g_iMaxClients = get_member_game(m_nMaxPlayers)
  158.    
  159.     // Check Round Time to Terminate it
  160.     set_task(1.0, "Check_RoundTimeleft", ROUND_TIME_LEFT, _, _, "b")
  161. }
  162.  
  163. public plugin_cfg()
  164. {
  165.     // Get our configiration file and Execute it
  166.     new szCfgDir[64]
  167.     get_localinfo("amxx_configsdir", szCfgDir, charsmax(szCfgDir))
  168.     server_cmd("exec %s/zombie_escape.cfg", szCfgDir)
  169.    
  170.     // Set Game Name
  171.     new szGameName[64]
  172.     formatex(szGameName, sizeof(szGameName), "Premuim ZE v%s", ZE_VERSION)
  173.     set_member_game(m_GameDesc, szGameName)
  174.    
  175.     // Set Version
  176.     register_cvar("ze_version", ZE_VERSION, FCVAR_SERVER|FCVAR_SPONLY)
  177.     set_cvar_string("ze_version", ZE_VERSION)
  178. }
  179.  
  180. public Fw_CheckMapConditions_Post()
  181. {
  182.     // Block Game Commencing
  183.     set_member_game(m_bGameStarted, true)
  184.    
  185.     // Set Freeze Time
  186.     set_member_game(m_iIntroRoundTime, get_pcvar_num(g_pCvarFreezeTime))
  187.    
  188.     // Set Round Time
  189.     set_member_game(m_iRoundTime, floatround(get_pcvar_float(g_pCvarRoundTime) * 60.0))
  190. }
  191.  
  192. public Fw_PlayerKilled_Post(id)
  193. {
  194.     g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
  195.     g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
  196.    
  197.     if (g_iAliveHumansNum == 0 && g_iAliveZombiesNum == 0)
  198.     {
  199.         // No Winner, All Players in one team killed Or Both teams Killed
  200.         client_print(0, print_center, "%L", LANG_PLAYER, "NO_WINNER")
  201.     }
  202. }
  203.  
  204. public Fw_RestMaxSpeed_Post(id)
  205. {
  206.     if (!g_bIsZombie[id])
  207.     {
  208.         static Float:flMaxSpeed
  209.         get_entvar(id, var_maxspeed, flMaxSpeed)
  210.        
  211.         if (flMaxSpeed != 1.0 && is_user_alive(id))
  212.         {
  213.             if (g_bHSpeedUsed[id])
  214.             {
  215.                 // Set New Human Speed Factor
  216.                 set_entvar(id, var_maxspeed, flMaxSpeed + float(g_iHSpeedFactor[id]))
  217.                 return HAM_IGNORED
  218.             }
  219.                
  220.             // Set Human Speed Factor, native not used
  221.             set_entvar(id, var_maxspeed, flMaxSpeed + get_pcvar_float(g_pCvarHumanSpeedFactor))
  222.             return HAM_IGNORED
  223.         }
  224.     }
  225.    
  226.     return HAM_SUPERCEDE
  227. }
  228.  
  229. public Fw_PlayerSpawn_Post(id)
  230. {  
  231.     if (!g_bGameStarted)
  232.     {
  233.         // Force All player to be Humans if Game not started yet
  234.         rg_set_user_team(id, TEAM_CT, MODEL_UNASSIGNED)
  235.     }
  236.     else
  237.     {
  238.         if (get_member_game(m_bFreezePeriod))
  239.         {
  240.             // Respawn Him As human if we are in freeze time (Zombie Not Chosen yet)
  241.             Set_User_Human(id)
  242.             g_bIsZombieFrozen[id] = false
  243.         }
  244.         else
  245.         {
  246.             if (g_bZombieFreezeTime)
  247.             {
  248.                 // Zombie Chosen and zombies Frozen, Spawn him as zombie and Freeze Him
  249.                 Set_User_Zombie(id)
  250.                 g_bIsZombieFrozen[id] = true
  251.                 set_entvar(id, var_maxspeed, 1.0)
  252.             }
  253.             else
  254.             {
  255.                 // Respawn him as normal zombie
  256.                 Set_User_Zombie(id)
  257.                 g_bIsZombieFrozen[id] = false
  258.             }
  259.         }
  260.     }
  261. }
  262.  
  263. public New_Round()
  264. {
  265.     // Remove All tasks in the New Round
  266.     remove_task(TASK_COUNTDOWN)
  267.     remove_task(TASK_COUNTDOWN2)
  268.     remove_task(TASK_SCORE_MESSAGE)
  269.     remove_task(FREEZE_ZOMBIES)
  270.    
  271.     // Score Message Task
  272.     set_task(10.0, "Score_Message", TASK_SCORE_MESSAGE, _, _, "b")
  273.    
  274.     // 2 is Hardcoded Value, It's Fix for the countdown to work correctly
  275.     g_iCountDown = get_pcvar_num(g_pCvarFreezeTime) - 2
  276.    
  277.     if (!g_bGameStarted)
  278.     {
  279.         // No Enough Players
  280.         ze_colored_print(0, "%L", LANG_PLAYER, "NO_ENOUGH_PLAYERS", get_pcvar_num(g_pCvarReqPlayers))
  281.         return // Block the execution of the blew code
  282.     }
  283.    
  284.     // Game Already started, Countdown now started
  285.     set_task(1.0, "Countdown_Start", TASK_COUNTDOWN, _, _, "b")
  286.     ze_colored_print(0, "%L", LANG_PLAYER, "READY_TO_RUN")
  287.     ExecuteForward(g_iForwards[FORWARD_GAME_STARTED], g_iFwReturn)
  288.    
  289.     g_iRoundNum++
  290.    
  291.     // Round Starting
  292.     g_bIsRoundEnding = false
  293.     g_bEndCalled = false
  294. }
  295.  
  296. // Score Message Task
  297. public Score_Message(TaskID)
  298. {
  299.     switch(get_pcvar_num(g_pCvarScoreMessageType))
  300.     {
  301.         case 0: // Disabled
  302.         {
  303.             return
  304.         }
  305.         case 1: // DHUD
  306.         {
  307.             set_dhudmessage(0, 255, 0, 0.38, 0.01, 0, 0.0, 9.0)
  308.             show_dhudmessage(0, "Survivors")
  309.            
  310.             set_dhudmessage(255, 255, 255, -1.0, 0.01, 0, 0.0, 9.0)
  311.             show_dhudmessage(0, "[VS]")
  312.            
  313.             set_dhudmessage(255, 0, 0, 0.54, 0.01, 0, 0.0, 9.0)
  314.             show_dhudmessage(0, "Zombies")
  315.            
  316.             set_dhudmessage(255, 255, 255, -1.0, 0.045, 0, 0.0, 9.0)
  317.             show_dhudmessage(0, "[%i] --------- [%i]", g_iHumansScore, g_iZombiesScore)
  318.  
  319.             set_dhudmessage( .red = 0, .green = 255, .blue = 0, .x = -1.0, .y = 0.02, .effects = 0, .fxtime = 6.0, .holdtime = 2.0, .fadeintime = 1.0, .fadeouttime = 1.0);
  320.             show_dhudmessage( 0, "%L                        ", LANG_PLAYER, "SCORE_HUMANS", native_ze_get_humans_number() );
  321.             set_dhudmessage( .red = 100, .green = 100, .blue = 100, .x = -1.0, .y = 0.02, .effects = 0, .fxtime = 6.0, .holdtime = 2.0, .fadeintime = 1.0, .fadeouttime = 1.0);
  322.             show_dhudmessage( 0, "%L^n%L", LANG_PLAYER, "SCORE_ROUND", g_iRoundNum, LANG_PLAYER,  "SCORE_WINS", g_iHumansScore,  g_iZombiesScore );
  323.             set_dhudmessage( .red = 255, .green = 0, .blue = 0, .x = -1.0, .y = 0.02, .effects = 0, .fxtime = 6.0, .holdtime = 2.0, .fadeintime = 1.0, .fadeouttime = 1.0);
  324.             show_dhudmessage( 0, "                         %L", LANG_PLAYER, "SCORE_ZOMBIES", native_ze_get_zombies_number() );
  325.         }
  326.         case 2: // HUD
  327.         {
  328.             set_hudmessage(get_pcvar_num(g_pCvarColors[Red]), get_pcvar_num(g_pCvarColors[Green]), get_pcvar_num(g_pCvarColors[Blue]), -1.0, 0.01, 0, 0.0, 9.0)
  329.             show_hudmessage(0, "%L", LANG_PLAYER, "SCORE_MESSAGE", g_iZombiesScore, g_iHumansScore)
  330.         }
  331.     }
  332. }
  333.  
  334. public Countdown_Start(TaskID)
  335. {
  336.     // Check if the players Disconnected and there is only one player then remove all messages, and stop tasks
  337.     if (!g_bGameStarted)
  338.         return
  339.    
  340.     if (!g_iCountDown)
  341.     {
  342.         Choose_Zombies()
  343.         remove_task(TASK_COUNTDOWN) // Remove the task
  344.         return // Block the execution of the blew code
  345.     }
  346.    
  347.     set_hudmessage(random(256), random(256), random(256), -1.0, 0.21, 0, 0.8, 0.8)
  348.     show_hudmessage(0, "%L", LANG_PLAYER, "RUN_NOTICE", g_iCountDown)
  349.  
  350.     g_iCountDown--
  351. }
  352.  
  353. public Choose_Zombies()
  354. {
  355.     new iZombies, id, iAliveCount
  356.     new iReqZombies
  357.    
  358.     // Get total alive players and required players
  359.     iAliveCount  = GetAllAlivePlayersNum()
  360.     iReqZombies = RequiredZombies()
  361.    
  362.     // Loop till we find req players
  363.     while(iZombies < iReqZombies)
  364.     {
  365.         id = GetRandomAlive(random_num(1, iAliveCount))
  366.        
  367.         if (!is_user_alive(id) || g_bIsZombie[id])
  368.             continue
  369.  
  370.         Set_User_Zombie(id)
  371.         set_entvar(id, var_health, get_pcvar_float(g_pCvarFirstZombiesHealth))
  372.         g_bIsZombieFrozen[id] = true
  373.         g_bZombieFreezeTime = true
  374.         set_entvar(id, var_maxspeed, 1.0)
  375.         set_task(0.1, "Freeze_Zombies", FREEZE_ZOMBIES, _, _, "b") // Better than PreThink
  376.         ExecuteForward(g_iForwards[FORWARD_ZOMBIE_APPEAR], g_iFwReturn)
  377.         iZombies++
  378.        
  379.         // Respawn Zombies to base
  380.         rg_round_respawn(id)
  381.     }
  382.    
  383.     // 2 is Hardcoded Value, It's Fix for the countdown to work correctly
  384.     g_iCountDown = get_pcvar_num(g_pCvarZombieReleaseTime) - 2
  385.    
  386.     set_task(1.0, "ReleaseZombie_CountDown", TASK_COUNTDOWN2, _, _, "b")
  387. }
  388.  
  389. public ReleaseZombie_CountDown(TaskID)
  390. {
  391.     if (!g_iCountDown)
  392.     {
  393.         ReleaseZombie()
  394.         remove_task(TASK_COUNTDOWN2)
  395.         return
  396.     }
  397.    
  398.     // Release Hud Message
  399.     set_hudmessage(255, 255, 0, -1.0, 0.21, 1, 2.0, 2.0)
  400.     ShowSyncHudMsg(0, g_iReleaseNotice, "%L", LANG_PLAYER, "ZOMBIE_RELEASE", g_iCountDown)
  401.    
  402.     g_iCountDown --
  403. }
  404.  
  405. public ReleaseZombie()
  406. {
  407.     ExecuteForward(g_iForwards[FORWARD_ZOMBIE_RELEASE], g_iFwReturn)
  408.    
  409.     for(new id = 1; id <= g_iMaxClients; id++)
  410.     {
  411.         if (is_user_alive(id) && g_bIsZombie[id])
  412.         {
  413.             g_bIsZombieFrozen[id] = false
  414.             g_bZombieFreezeTime = false
  415.         }
  416.     }
  417. }
  418.  
  419. public Freeze_Zombies(TaskID)
  420. {
  421.     for(new id = 1; id <= g_iMaxClients; id++)
  422.     {
  423.         if(!is_user_alive(id) || !g_bIsZombie[id])
  424.             continue
  425.        
  426.         if (g_bIsZombieFrozen[id])
  427.         {
  428.             // Zombie & Frozen, then Freeze him
  429.             set_entvar(id, var_maxspeed, 1.0)
  430.         }
  431.         else
  432.         {
  433.             if (g_bZSpeedUsed[id])
  434.             {
  435.                 // Zombie but Not Frozen the set his speed form .cfg
  436.                 set_entvar(id, var_maxspeed, float(g_iZSpeedSet[id]))
  437.                 continue;
  438.             }
  439.                
  440.             // Zombie but Not Frozen the set his speed form .cfg
  441.             set_entvar(id, var_maxspeed, get_pcvar_float(g_pCvarZombieSpeed))
  442.         }
  443.     }
  444. }
  445.  
  446. public Fw_TraceAttack_Pre(iVictim, iAttacker, Float:flDamage, Float:flDirection[3], iTracehandle, bitsDamageType)
  447. {
  448.     if (iVictim == iAttacker || !is_user_connected(iVictim) || !is_user_connected(iAttacker))
  449.         return HC_CONTINUE
  450.    
  451.     // Attacker and Victim is in same teams? Skip code blew
  452.     if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
  453.         return HC_CONTINUE
  454.    
  455.     // In freeze time? Skip all other plugins (Skip the real trace attack event)
  456.     if (g_bIsZombieFrozen[iVictim] || g_bIsZombieFrozen[iAttacker])
  457.         return HC_SUPERCEDE
  458.    
  459.     g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
  460.    
  461.     if (g_bIsZombie[iAttacker])
  462.     {
  463.         // Death Message with Infection style [Added here because of delay in Forward use]
  464.         SendDeathMsg(iAttacker, iVictim)
  465.        
  466.         ExecuteForward(g_iForwards[FORWARD_PRE_INFECTED], g_iFwReturn, iVictim, iAttacker)
  467.        
  468.         if (g_iFwReturn > 0)
  469.         {
  470.             return HC_CONTINUE
  471.         }
  472.        
  473.         Set_User_Zombie(iVictim)
  474.        
  475.         ExecuteForward(g_iForwards[FORWARD_INFECTED], g_iFwReturn, iVictim, iAttacker)
  476.        
  477.         if (g_iAliveHumansNum == 1) // Check if this is Last Human, Because of Delay i can't check if it's 0 instead of 1
  478.         {
  479.             // End round event called one time
  480.             g_bEndCalled = true
  481.            
  482.             // Round is Ending
  483.             g_bIsRoundEnding = true
  484.            
  485.             // Zombie Win, Leave text blank so we use ours from ML
  486.             rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
  487.            
  488.             // Show Our Message
  489.             client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
  490.            
  491.             // This needed so forward work also to add +1 for Zombies
  492.             g_iTeam = 1 // ZE_TEAM_ZOMBIE
  493.             ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
  494.         }
  495.     }
  496.    
  497.     return HC_CONTINUE
  498. }
  499.  
  500. public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
  501. {
  502.     // Not Vaild Victim or Attacker so skip the event (Important to block out bounds errors)
  503.     if (!is_user_connected(iVictim) || !is_user_connected(iAttacker))
  504.         return HC_CONTINUE
  505.    
  506.     // Set Knockback here, So if we blocked damage in TraceAttack event player won't get knockback (Fix For Madness)
  507.     if (g_bIsZombie[iVictim] && !g_bIsZombie[iAttacker])
  508.     {
  509.         // Remove Shock Pain
  510.         set_member(iVictim, m_flVelocityModifier, 1.0)
  511.        
  512.         // Set Knockback
  513.         static Float:flOrigin[3]
  514.         get_entvar(iAttacker, var_origin, flOrigin)
  515.         Set_Knockback(iVictim, flOrigin, get_pcvar_float(g_pCvarZombieKnockback), 2)
  516.     }
  517.    
  518.     return HC_CONTINUE
  519. }
  520.  
  521. public Round_End()
  522. {
  523.     g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
  524.    
  525.     if (g_iAliveZombiesNum == 0 && g_bGameStarted)
  526.     {
  527.         g_iTeam = 2 // ZE_TEAM_HUMAN
  528.         ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
  529.         client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
  530.         g_iHumansScore++
  531.         g_bIsRoundEnding = true
  532.         return // To block Execute the code blew
  533.     }
  534.    
  535.     g_iTeam = 1 // ZE_TEAM_ZOMBIE
  536.     g_iZombiesScore++
  537.     g_bIsRoundEnding = true
  538.    
  539.     // If it's already called one time, don't call it again
  540.     if (!g_bEndCalled)
  541.     {
  542.         ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
  543.     }
  544.    
  545.     client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
  546. }
  547.  
  548. public Event_RoundEnd_Pre(WinStatus:status, ScenarioEventEndRound:event, Float:tmDelay)
  549. {
  550.     // The two unhandeld cases by rg_round_end() native in our Mod
  551.     if (event == ROUND_CTS_WIN || event == ROUND_TERRORISTS_WIN)
  552.     {
  553.         SetHookChainArg(3, ATYPE_FLOAT, get_pcvar_float(g_pCvarRoundEndDelay))
  554.     }
  555. }
  556.  
  557. public Round_Start()
  558. {
  559.     g_flReferenceTime = get_gametime()
  560.     g_iRoundTime = get_member_game(m_iRoundTime)
  561. }
  562.  
  563. public Check_RoundTimeleft()
  564. {
  565.     new Float:flRoundTimeLeft = (g_flReferenceTime + float(g_iRoundTime)) - get_gametime()
  566.    
  567.     if (floatround(flRoundTimeLeft) == 0)
  568.     {
  569.         // Round is Ending
  570.         g_bIsRoundEnding = true
  571.        
  572.         // If Time is Out then Terminate the Round
  573.         rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
  574.        
  575.         // Show our Message
  576.         client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
  577.     }
  578. }
  579.  
  580. public client_disconnected(id)
  581. {
  582.     // Delay Then Check Players to Terminate The round (Delay needed)
  583.     set_task(0.1, "Check_AlivePlayers")
  584.    
  585.     // Reset speed for this dropped id
  586.     g_bHSpeedUsed[id] = false
  587.     g_bZSpeedUsed[id] = false
  588. }
  589.  
  590. // This check done when player disconnect
  591. public Check_AlivePlayers()
  592. {
  593.     g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
  594.     g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
  595.    
  596.     // Game Started? (There is at least 2 players Alive?)
  597.     if (g_bGameStarted)
  598.     {
  599.         // We are in freeze time?
  600.         if (get_member_game(m_bFreezePeriod))
  601.         {
  602.             // Humans alive number = 1 and no zombies?
  603.             if (g_iAliveHumansNum < get_pcvar_num(g_pCvarReqPlayers))
  604.             {
  605.                 // Game started false again
  606.                 g_bGameStarted = false
  607.             }
  608.         }
  609.         else // Not freeze time?
  610.         {
  611.             // Variables
  612.             new iAllZombiesNum = GetTeamPlayersNum(CsTeams:TEAM_TERRORIST),
  613.             iAllHumansNum = GetTeamPlayersNum(CsTeams:TEAM_CT),
  614.             iDeadZombiesNum = GetDeadPlayersNum(CsTeams:TEAM_TERRORIST),
  615.             iDeadHumansNum = GetDeadPlayersNum(CsTeams:TEAM_CT)
  616.    
  617.             // Alive humans number = 1 and no zombies at all, And no dead humans?
  618.             if (g_iAliveHumansNum < get_pcvar_num(g_pCvarReqPlayers) && iDeadHumansNum == 0 && iAllZombiesNum == 0)
  619.             {
  620.                 // Game started is false and humans wins (Escape Success)
  621.                 g_bGameStarted = false
  622.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_CTS, ROUND_CTS_WIN, "")
  623.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
  624.             }
  625.            
  626.             // Alive zombies number = 1 and no humans at all, And no dead zombies?
  627.             if (g_iAliveZombiesNum < get_pcvar_num(g_pCvarReqPlayers) && iDeadZombiesNum == 0 && iAllHumansNum == 0)
  628.             {
  629.                 // Game started is false and zombies wins (Escape Fail)
  630.                 g_bGameStarted = false
  631.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
  632.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
  633.             }
  634.            
  635.             // Humans number more than 1 and no zombies?
  636.             if (g_iAliveHumansNum >= get_pcvar_num(g_pCvarReqPlayers) && g_iAliveZombiesNum == 0 && !g_bIsRoundEnding)
  637.             {
  638.                 // Then Escape success as there is no Zombies
  639.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_CTS, ROUND_CTS_WIN, "")
  640.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
  641.             }
  642.            
  643.             // Zombies number more than 1 and no humans?
  644.             if (g_iAliveZombiesNum >= get_pcvar_num(g_pCvarReqPlayers) && g_iAliveHumansNum == 0 && !g_bIsRoundEnding)
  645.             {
  646.                 // Then Escape Fail as there is no humans
  647.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
  648.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
  649.             }
  650.         }
  651.     }
  652. }
  653.  
  654. public client_putinserver(id)
  655. {
  656.     // Add Delay and Check Conditions To start the Game (Delay needed)
  657.     set_task(1.0, "Check_AllPlayersNumber", _, _, _, "b")
  658. }
  659.  
  660. public Check_AllPlayersNumber(TaskID)
  661. {
  662.     if (g_bGameStarted)
  663.     {
  664.         // If game started remove the task and block the blew Checks
  665.         remove_task(TaskID)
  666.         return
  667.     }
  668.    
  669.     if (GetAllAlivePlayersNum() >= get_pcvar_num(g_pCvarReqPlayers))
  670.     {
  671.         // Players In server == The Required so game started is true
  672.         g_bGameStarted = true
  673.        
  674.         // Restart the game
  675.         server_cmd("sv_restart 2")
  676.        
  677.         // Print Fake game Commencing Message
  678.         client_print(0, print_center, "%L", LANG_PLAYER, "START_GAME")
  679.        
  680.         // Remove the task
  681.         remove_task(TaskID)
  682.     }
  683. }
  684.  
  685. public Set_User_Human(id)
  686. {
  687.     if (!is_user_alive(id))
  688.         return
  689.    
  690.     g_bIsZombie[id] = false
  691.     set_entvar(id, var_health, get_pcvar_float(g_pCvarHumanHealth))
  692.     set_entvar(id, var_gravity, get_pcvar_float(g_pCvarHumanGravity)/800.0)
  693.     ExecuteForward(g_iForwards[FORWARD_HUMANIZED], g_iFwReturn, id)
  694.    
  695.     if (get_member(id, m_iTeam) != TEAM_CT)
  696.         rg_set_user_team(id, TEAM_CT, MODEL_UNASSIGNED)
  697. }
  698.  
  699. public Set_User_Zombie(id)
  700. {
  701.     if (!is_user_alive(id))
  702.         return
  703.    
  704.     g_bIsZombie[id] = true
  705.     set_entvar(id, var_health, get_pcvar_float(g_pCvarZombieHealth))
  706.     set_entvar(id, var_gravity, get_pcvar_float(g_pCvarZombieGravity)/800.0)
  707.     rg_remove_all_items(id)
  708.     rg_give_item(id, "weapon_knife", GT_APPEND)
  709.     ExecuteForward(g_iForwards[FORWARD_INFECTED], g_iFwReturn, id, 0)
  710.    
  711.     if (get_member(id, m_iTeam) != TEAM_TERRORIST)
  712.         rg_set_user_team(id, TEAM_TERRORIST, MODEL_UNASSIGNED)
  713. }
  714.  
  715. public Map_Restart()
  716. {
  717.     // Add Delay To help Rest Scores if player kill himself, and there no one else him so round draw (Delay needed)
  718.     set_task(0.1, "Reset_Score_Message")
  719. }
  720.  
  721. public Reset_Score_Message()
  722. {
  723.     g_iHumansScore = 0
  724.     g_iZombiesScore = 0
  725.     g_iRoundNum = 0
  726. }
  727.  
  728. // Natives
  729. public native_ze_is_user_zombie(id)
  730. {
  731.     if (!is_user_connected(id))
  732.     {
  733.         return -1;
  734.     }
  735.    
  736.     return g_bIsZombie[id]
  737. }
  738.  
  739. public native_ze_set_user_zombie(id)
  740. {
  741.     if (!is_user_connected(id))
  742.     {
  743.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  744.         return false;
  745.     }
  746.    
  747.     Set_User_Zombie(id)
  748.     return true;
  749. }
  750.  
  751. public native_ze_set_user_human(id)
  752. {
  753.     if (!is_user_connected(id))
  754.     {
  755.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  756.         return false;
  757.     }
  758.    
  759.     Set_User_Human(id)
  760.     return true;
  761. }
  762.  
  763. public native_ze_is_game_started()
  764. {
  765.     return g_bGameStarted
  766. }
  767.  
  768. public native_ze_is_zombie_frozen(id)
  769. {
  770.     if (!is_user_connected(id) || !g_bIsZombie[id])
  771.     {
  772.         return -1;
  773.     }
  774.    
  775.     return g_bIsZombieFrozen[id]
  776. }
  777.  
  778. public native_ze_get_round_number()
  779. {
  780.     if (!g_bGameStarted)
  781.     {
  782.         return -1;
  783.     }
  784.    
  785.     return g_iRoundNum
  786. }
  787.  
  788. public native_ze_get_humans_number()
  789. {
  790.     return GetAlivePlayersNum(CsTeams:TEAM_CT)
  791. }
  792.  
  793. public native_ze_get_zombies_number()
  794. {
  795.     return GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
  796. }
  797.  
  798. public native_ze_set_human_speed_factor(id, iFactor)
  799. {
  800.     if (!is_user_connected(id))
  801.     {
  802.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  803.         return false;
  804.     }
  805.    
  806.     g_bHSpeedUsed[id] = true
  807.     g_iHSpeedFactor[id] = iFactor
  808.     ExecuteHamB(Ham_Item_PreFrame, id)
  809.     return true;
  810. }
  811.  
  812. public native_ze_reset_human_speed(id)
  813. {
  814.     if (!is_user_connected(id))
  815.     {
  816.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  817.         return false;
  818.     }
  819.    
  820.     g_bHSpeedUsed[id] = false
  821.     ExecuteHamB(Ham_Item_PreFrame, id)
  822.     return true;
  823. }
  824.  
  825. public native_ze_set_zombie_speed(id, iSpeed)
  826. {
  827.     if (!is_user_connected(id))
  828.     {
  829.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  830.         return false;
  831.     }
  832.    
  833.     g_bZSpeedUsed[id] = true
  834.     g_iZSpeedSet[id] = iSpeed
  835.     return true;
  836. }
  837.  
  838. public native_ze_reset_zombie_speed(id)
  839. {
  840.     if (!is_user_connected(id))
  841.     {
  842.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
  843.         return false;
  844.     }
  845.    
  846.     g_bZSpeedUsed[id] = false
  847.     return true;
  848. }
You don't know? Learn and you will know.

User avatar
Spir0x
Veteran Member
Veteran Member
Tunisia
Posts: 552
Joined: 1 Year Ago
Location: Tunisia
Has thanked: 14 times
Been thanked: 6 times
Age: 18
Contact:

#9

Post by Spir0x » 1 Week Ago

Thanks solved.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest