ZE Special Core

Unpaid Requests, Public Plugins
Post Reply
User avatar
Spir0x
Veteran Member
Veteran Member
Tunisia
Posts: 641
Joined: 7 years ago
Location: Tunisia
Contact:

ZE Special Core

#1

Post by Spir0x » 5 years ago

Bro please help me. did you remember old code you gave me ? for ze_core with special feature when round starts all humans run and after countdown zombies respawn on base. now i need it with on new core update v1.3.

My old core v1.2 code with this feature (i mean all humans run when round starts and after cd zombie chosen respawn on base)

Code:

Code: Select all

#include <zombie_escape>

// Fowards
enum _:TOTAL_FORWARDS
{
	FORWARD_NONE = 0,
	FORWARD_ROUNDEND,
	FORWARD_HUMANIZED,
	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
}

// Variables
new g_iAliveCTNum, g_iAliveTNum, g_iRoundTime, g_iCountDown, g_iReleaseNotice, g_iMaxClients, g_iHumansScore, g_iZombiesScore,
bool:g_bGameStarted, bool:g_bIsZombie[33], bool:g_bIsZombieFrozen[33], bool:g_bZombieFrozenTime, bool:g_bIsRoundEnding,
Float:g_fReferenceTime

// Cvars
new Cvar_Human_fSpeedFactor, Cvar_Human_fGravity, Cvar_Human_iHealth, Cvar_Zombie_fSpeed, Cvar_Zombie_fGravity,
Cvar_Zombie_iReleaseTime, Cvar_iFreezeTime, Cvar_fRoundTime, Cvar_iReqPlayers, Cvar_Zombie_iHealth, Cvar_FirstZombies_iHealth,
Cvar_Zombie_fKnockback, Cvar_ScoreMessage_iType, Cvar_ScoreMessage_iRed, Cvar_ScoreMessage_iGreen, Cvar_ScoreMessage_iBlue

public plugin_natives()
{
	register_native("ze_is_user_zombie", "native_ze_is_user_zombie", 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)
}

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)
	
	// 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_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
	Cvar_Human_fSpeedFactor = register_cvar("ze_human_speed_factor", "20.0")
	Cvar_Human_fGravity = register_cvar("ze_human_gravity", "800")
	Cvar_Human_iHealth = register_cvar("ze_human_health", "1000")
	
	// Zombie Cvars
	Cvar_Zombie_fSpeed = register_cvar("ze_zombie_speed", "350.0")
	Cvar_Zombie_fGravity = register_cvar("ze_zombie_gravity", "640")
	Cvar_Zombie_iHealth = register_cvar("ze_zombie_health", "10000")
	Cvar_FirstZombies_iHealth = register_cvar("ze_first_zombies_health", "20000")
	Cvar_Zombie_fKnockback = register_cvar("ze_zombie_knockback", "300.0")
	
	// General Cvars
	Cvar_Zombie_iReleaseTime = register_cvar("ze_release_time", "15")
	Cvar_iFreezeTime = register_cvar("ze_freeze_time", "20")
	Cvar_fRoundTime = register_cvar("ze_round_time", "9.0")
	Cvar_iReqPlayers = register_cvar("ze_required_players", "2")
	Cvar_ScoreMessage_iType = register_cvar("ze_score_message_type", "1")
	Cvar_ScoreMessage_iRed = register_cvar("ze_score_message_red", "200")
	Cvar_ScoreMessage_iGreen = register_cvar("ze_score_message_green", "100")
	Cvar_ScoreMessage_iBlue = register_cvar("ze_score_message_blue", "0")
	
	// 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(Cvar_iFreezeTime))
	
	// Set Round Time
	set_member_game(m_iRoundTime, floatround(get_pcvar_float(Cvar_fRoundTime) * 60.0))
}

public Fw_PlayerKilled_Post(id)
{
	new iCTNum; iCTNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
	new iTNum; iTNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
	
	if (iCTNum == 0 && iTNum == 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:fMaxSpeed
		get_entvar(id, var_maxspeed, fMaxSpeed)
		
		if(fMaxSpeed != 1.0 && is_user_alive(id))
		{
			// Set Human Speed Factor
			set_entvar(id, var_maxspeed, fMaxSpeed + get_pcvar_float(Cvar_Human_fSpeedFactor))
			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_bZombieFrozenTime)
			{
				// 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(Cvar_iFreezeTime) - 2
	
	if (!g_bGameStarted)
	{
		// No Enough Players
		ze_colored_print(0, "%L", LANG_PLAYER, "NO_ENOUGH_PLAYERS", get_pcvar_num(Cvar_iReqPlayers))
		return // Block the execution of the blew code 
	}
	
	if (g_bGameStarted)
	{
		// 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)
		
		// Round Starting
		g_bIsRoundEnding = false
	}
}

// Score Message Task
public Score_Message(TaskID)
{
	if (get_pcvar_num(Cvar_ScoreMessage_iType) == 0)
		return
	
	if (get_pcvar_num(Cvar_ScoreMessage_iType) == 1)
	{
		set_dhudmessage(get_pcvar_num(Cvar_ScoreMessage_iRed), get_pcvar_num(Cvar_ScoreMessage_iGreen), get_pcvar_num(Cvar_ScoreMessage_iBlue), -1.0, 0.01, 0, 0.0, 9.0)
		show_dhudmessage(0, "%L", LANG_PLAYER, "SCORE_MESSAGE", g_iZombiesScore, g_iHumansScore)
	}
	else if (get_pcvar_num(Cvar_ScoreMessage_iType) == 2)
	{
		set_hudmessage(get_pcvar_num(Cvar_ScoreMessage_iRed), get_pcvar_num(Cvar_ScoreMessage_iGreen), get_pcvar_num(Cvar_ScoreMessage_iBlue), -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) // When it reach 0 the !0 will be 1 So it's True
	{
		Choose_Zombies()
		remove_task(TaskID) // 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 -- // Means: g_iCountDown = g_iCountDown -1
}

public Choose_Zombies()
{
	new iZombies, id, AliveCount; AliveCount  = GetAllAlivePlayersNum()
	new iReqZombies; iReqZombies = RequiredZombies()
	
	while (iZombies < iReqZombies)
	{
		id = GetRandomAlive(random_num(1, AliveCount))
		
		if (!is_user_alive(id) || g_bIsZombie[id])
			continue

		Set_User_Zombie(id)
		set_entvar(id, var_health, get_pcvar_float(Cvar_FirstZombies_iHealth))
		g_bIsZombieFrozen[id] = true
		g_bZombieFrozenTime = 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(Cvar_Zombie_iReleaseTime) - 2
	
	set_task(1.0, "ReleaseZombie_CountDown", TASK_COUNTDOWN2, _, _, "b")
}

public ReleaseZombie_CountDown(TaskID)
{
	if(!g_iCountDown)
	{
		ReleaseZombie()
		remove_task(TaskID)
		
		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 i = 1; i <= g_iMaxClients; i++)
	{
		if(is_user_alive(i) && g_bIsZombie[i])
		{
			g_bIsZombieFrozen[i] = false
			g_bZombieFrozenTime = false
		}
	}
}

public Freeze_Zombies(TaskID)
{
	for(new i = 1; i <= g_iMaxClients; i++)
	{
		if(!is_user_alive(i))
			continue
		
		if (g_bIsZombieFrozen[i] && g_bIsZombie[i])
		{
			// Zombie & Frozen, then Freeze him
			set_entvar(i, var_maxspeed, 1.0)
		}
		
		if (!g_bIsZombieFrozen[i] && g_bIsZombie[i])
		{
			// Zombie but Not Frozen the set his speed form .cfg
			set_entvar(i, var_maxspeed, get_pcvar_float(Cvar_Zombie_fSpeed))
		}
	}
}

public Fw_TraceAttack_Pre(iVictim, iAttacker, Float:damage, Float:direction[3], tracehandle, damagebits)
{
	if (iVictim == iAttacker || !is_user_connected(iVictim) || !is_user_connected(iAttacker))
		return HC_CONTINUE
	
	// Attacker and Victim is in same teams? Skip here only
	if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
		return HC_CONTINUE
	
	// In freeze time? Skip all other plugins
	if (g_bIsZombieFrozen[iVictim] || g_bIsZombieFrozen[iAttacker])
		return HC_SUPERCEDE
	
	g_iAliveCTNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
	
	if (get_member(iAttacker, m_iTeam) == TEAM_TERRORIST)
	{
		// Death Message with Infection style [Added here because of delay in Forward use]
		SendDeathMsg(iAttacker, iVictim)
		
		Set_User_Zombie(iVictim)
		ExecuteForward(g_iForwards[FORWARD_INFECTED], g_iFwReturn, iVictim, iAttacker)
		
		if (g_iAliveCTNum == 1) // Check if this is Last Human, Because of Delay i can't check if it's 0 instead of 1
		{
			// Zombie Win, Leave text blank so we use ours from ML
			rg_round_end(3.0, 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)
			
			// Round is Ending
			g_bIsRoundEnding = true
		}
	}
	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:fOrigin[3]
		get_entvar(iAttacker, var_origin, fOrigin)
		Set_Knockback(iVictim, fOrigin, get_pcvar_float(Cvar_Zombie_fKnockback), 2)
	}
	return HC_CONTINUE
}

public Round_End()
{
	g_iAliveTNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
	g_iAliveCTNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
	
	if (g_iAliveTNum == 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
	ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
	client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
}

public Round_Start()
{
    g_fReferenceTime = get_gametime()
    g_iRoundTime = get_member_game(m_iRoundTime)
}

public Check_RoundTimeleft()
{
	new Float:fRoundTimeLeft; fRoundTimeLeft = (g_fReferenceTime + float(g_iRoundTime)) - get_gametime()
	
	if (floatround(fRoundTimeLeft) == 0)
	{
		// If Time is Out then Terminate the Round
		rg_round_end(14.0, WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
		
		// Show our Message
		client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
		
		// Round is Ending
		g_bIsRoundEnding = true
	}
}

public client_disconnected(id)
{
	// Delay Then Check Players to Terminate The round (Delay needed)
	set_task(0.1, "Check_AlivePlayers", _, _, _, "a", 1)
}

// This check done when player disconnect
public Check_AlivePlayers()
{
	g_iAliveTNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
	g_iAliveCTNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
	
	new iAllTNum = GetTeamPlayersNum(CsTeams:TEAM_TERRORIST),
	iAllCTNum = GetTeamPlayersNum(CsTeams:TEAM_CT),
	iDeadTNum = GetDeadPlayersNum(CsTeams:TEAM_TERRORIST),
	iDeadCTNum = GetDeadPlayersNum(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_iAliveCTNum < get_pcvar_num(Cvar_iReqPlayers))
			{
				// Game started false again
				g_bGameStarted = false
			}
		}
		else // Not freeze time?
		{
			// Alive humans number = 1 and no zombies at all, And no dead humans?
			if (g_iAliveCTNum < get_pcvar_num(Cvar_iReqPlayers) && iDeadCTNum == 0 && iAllTNum == 0)
			{
				// Game started is false and humans wins (Escape Success)
				g_bGameStarted = false
				rg_round_end(3.0, 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_iAliveTNum < get_pcvar_num(Cvar_iReqPlayers) && iDeadTNum == 0 && iAllCTNum == 0)
			{
				// Game started is false and humans wins (Escape Success)
				g_bGameStarted = false
				rg_round_end(3.0, WINSTATUS_CTS, ROUND_CTS_WIN, "")
				client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
			}
			
			// Humans number more than 1 and no zombies?
			if (g_iAliveCTNum >= get_pcvar_num(Cvar_iReqPlayers) && g_iAliveTNum == 0 && !g_bIsRoundEnding)
			{
				// Then Escape success as there is no Zombies
				rg_round_end(3.0, 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_iAliveTNum >= get_pcvar_num(Cvar_iReqPlayers) && g_iAliveCTNum == 0 && !g_bIsRoundEnding)
			{
				// Then Escape Fail as there is no humans
				rg_round_end(3.0, 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(Cvar_iReqPlayers))
		return
	
	if (GetAllAlivePlayersNum() == get_pcvar_num(Cvar_iReqPlayers))
	{
		// 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)
	}
	
	// Simple Fix for bots, If many of them connect fast then the == 2 won't be detected so this to detect it
	if (GetAllAlivePlayersNum() > get_pcvar_num(Cvar_iReqPlayers) && !g_bGameStarted)
	{
		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(Cvar_Human_iHealth))
	set_entvar(id, var_gravity, get_pcvar_float(Cvar_Human_fGravity)/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(Cvar_Zombie_iHealth))
	set_entvar(id, var_gravity, get_pcvar_float(Cvar_Zombie_fGravity)/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, "Rest_Score_Message", _, _, _, "a", 1)
}

public Rest_Score_Message()
{
	g_iHumansScore = 0
	g_iZombiesScore = 0
}

// Natives
public native_ze_is_user_zombie(id)
{
	return g_bIsZombie[id]
}

public native_ze_set_user_zombie(id)
{
	Set_User_Zombie(id)
}

public native_ze_set_user_human(id)
{
	Set_User_Human(id)
}
You new core v1.3 i just want to set the feature i said to the new core.

Code:

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_member_game(m_iIntroRoundTime) - 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(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_dhudmessage(0, "%L", LANG_PLAYER, "SCORE_MESSAGE", g_iZombiesScore, g_iHumansScore)
		}
		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++
	}
	
	// 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\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1036\\ f0\\ fs16 \n\\ par }
*/

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2214
Joined: 7 years ago
Contact:

#2

Post by Raheem » 5 years ago

I think there was add for this:
  • Code: Select all

    // Respawn Zombies to base
    rg_round_respawn(id)
And edit for one line to:
  • Code: Select all

    // 2 is Hardcoded Value, It's Fix for the countdown to work correctly
    g_iCountDown = get_pcvar_num(g_pCvarFreezeTime) - 2
And you set mp_freezetime to zero and ze_freeze_time to what ever you want. You can remember the right CVARs as i don't remember them.

Full code on ZE v1.3:
    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(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)
    308.             show_dhudmessage(0, "%L", LANG_PLAYER, "SCORE_MESSAGE", g_iZombiesScore, g_iHumansScore)
    309.         }
    310.         case 2: // HUD
    311.         {
    312.             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)
    313.             show_hudmessage(0, "%L", LANG_PLAYER, "SCORE_MESSAGE", g_iZombiesScore, g_iHumansScore)
    314.         }
    315.     }
    316. }
    317.  
    318. public Countdown_Start(TaskID)
    319. {
    320.     // Check if the players Disconnected and there is only one player then remove all messages, and stop tasks
    321.     if (!g_bGameStarted)
    322.         return
    323.    
    324.     if (!g_iCountDown)
    325.     {
    326.         Choose_Zombies()
    327.         remove_task(TASK_COUNTDOWN) // Remove the task
    328.         return // Block the execution of the blew code
    329.     }
    330.    
    331.     set_hudmessage(random(256), random(256), random(256), -1.0, 0.21, 0, 0.8, 0.8)
    332.     show_hudmessage(0, "%L", LANG_PLAYER, "RUN_NOTICE", g_iCountDown)
    333.  
    334.     g_iCountDown--
    335. }
    336.  
    337. public Choose_Zombies()
    338. {
    339.     new iZombies, id, iAliveCount
    340.     new iReqZombies
    341.    
    342.     // Get total alive players and required players
    343.     iAliveCount  = GetAllAlivePlayersNum()
    344.     iReqZombies = RequiredZombies()
    345.    
    346.     // Loop till we find req players
    347.     while(iZombies < iReqZombies)
    348.     {
    349.         id = GetRandomAlive(random_num(1, iAliveCount))
    350.        
    351.         if (!is_user_alive(id) || g_bIsZombie[id])
    352.             continue
    353.  
    354.         Set_User_Zombie(id)
    355.         set_entvar(id, var_health, get_pcvar_float(g_pCvarFirstZombiesHealth))
    356.         g_bIsZombieFrozen[id] = true
    357.         g_bZombieFreezeTime = true
    358.         set_entvar(id, var_maxspeed, 1.0)
    359.         set_task(0.1, "Freeze_Zombies", FREEZE_ZOMBIES, _, _, "b") // Better than PreThink
    360.         ExecuteForward(g_iForwards[FORWARD_ZOMBIE_APPEAR], g_iFwReturn)
    361.         iZombies++
    362.        
    363.         // Respawn Zombies to base
    364.         rg_round_respawn(id)
    365.     }
    366.    
    367.     // 2 is Hardcoded Value, It's Fix for the countdown to work correctly
    368.     g_iCountDown = get_pcvar_num(g_pCvarZombieReleaseTime) - 2
    369.    
    370.     set_task(1.0, "ReleaseZombie_CountDown", TASK_COUNTDOWN2, _, _, "b")
    371. }
    372.  
    373. public ReleaseZombie_CountDown(TaskID)
    374. {
    375.     if (!g_iCountDown)
    376.     {
    377.         ReleaseZombie()
    378.         remove_task(TASK_COUNTDOWN2)
    379.         return
    380.     }
    381.    
    382.     // Release Hud Message
    383.     set_hudmessage(255, 255, 0, -1.0, 0.21, 1, 2.0, 2.0)
    384.     ShowSyncHudMsg(0, g_iReleaseNotice, "%L", LANG_PLAYER, "ZOMBIE_RELEASE", g_iCountDown)
    385.    
    386.     g_iCountDown --
    387. }
    388.  
    389. public ReleaseZombie()
    390. {
    391.     ExecuteForward(g_iForwards[FORWARD_ZOMBIE_RELEASE], g_iFwReturn)
    392.    
    393.     for(new id = 1; id <= g_iMaxClients; id++)
    394.     {
    395.         if (is_user_alive(id) && g_bIsZombie[id])
    396.         {
    397.             g_bIsZombieFrozen[id] = false
    398.             g_bZombieFreezeTime = false
    399.         }
    400.     }
    401. }
    402.  
    403. public Freeze_Zombies(TaskID)
    404. {
    405.     for(new id = 1; id <= g_iMaxClients; id++)
    406.     {
    407.         if(!is_user_alive(id) || !g_bIsZombie[id])
    408.             continue
    409.        
    410.         if (g_bIsZombieFrozen[id])
    411.         {
    412.             // Zombie & Frozen, then Freeze him
    413.             set_entvar(id, var_maxspeed, 1.0)
    414.         }
    415.         else
    416.         {
    417.             if (g_bZSpeedUsed[id])
    418.             {
    419.                 // Zombie but Not Frozen the set his speed form .cfg
    420.                 set_entvar(id, var_maxspeed, float(g_iZSpeedSet[id]))
    421.                 continue;
    422.             }
    423.                
    424.             // Zombie but Not Frozen the set his speed form .cfg
    425.             set_entvar(id, var_maxspeed, get_pcvar_float(g_pCvarZombieSpeed))
    426.         }
    427.     }
    428. }
    429.  
    430. public Fw_TraceAttack_Pre(iVictim, iAttacker, Float:flDamage, Float:flDirection[3], iTracehandle, bitsDamageType)
    431. {
    432.     if (iVictim == iAttacker || !is_user_connected(iVictim) || !is_user_connected(iAttacker))
    433.         return HC_CONTINUE
    434.    
    435.     // Attacker and Victim is in same teams? Skip code blew
    436.     if (get_member(iAttacker, m_iTeam) == get_member(iVictim, m_iTeam))
    437.         return HC_CONTINUE
    438.    
    439.     // In freeze time? Skip all other plugins (Skip the real trace attack event)
    440.     if (g_bIsZombieFrozen[iVictim] || g_bIsZombieFrozen[iAttacker])
    441.         return HC_SUPERCEDE
    442.    
    443.     g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
    444.    
    445.     if (g_bIsZombie[iAttacker])
    446.     {
    447.         // Death Message with Infection style [Added here because of delay in Forward use]
    448.         SendDeathMsg(iAttacker, iVictim)
    449.        
    450.         ExecuteForward(g_iForwards[FORWARD_PRE_INFECTED], g_iFwReturn, iVictim, iAttacker)
    451.        
    452.         if (g_iFwReturn > 0)
    453.         {
    454.             return HC_CONTINUE
    455.         }
    456.        
    457.         Set_User_Zombie(iVictim)
    458.        
    459.         ExecuteForward(g_iForwards[FORWARD_INFECTED], g_iFwReturn, iVictim, iAttacker)
    460.        
    461.         if (g_iAliveHumansNum == 1) // Check if this is Last Human, Because of Delay i can't check if it's 0 instead of 1
    462.         {
    463.             // End round event called one time
    464.             g_bEndCalled = true
    465.            
    466.             // Round is Ending
    467.             g_bIsRoundEnding = true
    468.            
    469.             // Zombie Win, Leave text blank so we use ours from ML
    470.             rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
    471.            
    472.             // Show Our Message
    473.             client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
    474.            
    475.             // This needed so forward work also to add +1 for Zombies
    476.             g_iTeam = 1 // ZE_TEAM_ZOMBIE
    477.             ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
    478.         }
    479.     }
    480.    
    481.     return HC_CONTINUE
    482. }
    483.  
    484. public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
    485. {
    486.     // Not Vaild Victim or Attacker so skip the event (Important to block out bounds errors)
    487.     if (!is_user_connected(iVictim) || !is_user_connected(iAttacker))
    488.         return HC_CONTINUE
    489.    
    490.     // Set Knockback here, So if we blocked damage in TraceAttack event player won't get knockback (Fix For Madness)
    491.     if (g_bIsZombie[iVictim] && !g_bIsZombie[iAttacker])
    492.     {
    493.         // Remove Shock Pain
    494.         set_member(iVictim, m_flVelocityModifier, 1.0)
    495.        
    496.         // Set Knockback
    497.         static Float:flOrigin[3]
    498.         get_entvar(iAttacker, var_origin, flOrigin)
    499.         Set_Knockback(iVictim, flOrigin, get_pcvar_float(g_pCvarZombieKnockback), 2)
    500.     }
    501.    
    502.     return HC_CONTINUE
    503. }
    504.  
    505. public Round_End()
    506. {
    507.     g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
    508.    
    509.     if (g_iAliveZombiesNum == 0 && g_bGameStarted)
    510.     {
    511.         g_iTeam = 2 // ZE_TEAM_HUMAN
    512.         ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
    513.         client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
    514.         g_iHumansScore++
    515.         g_bIsRoundEnding = true
    516.         return // To block Execute the code blew
    517.     }
    518.    
    519.     g_iTeam = 1 // ZE_TEAM_ZOMBIE
    520.     g_iZombiesScore++
    521.     g_bIsRoundEnding = true
    522.    
    523.     // If it's already called one time, don't call it again
    524.     if (!g_bEndCalled)
    525.     {
    526.         ExecuteForward(g_iForwards[FORWARD_ROUNDEND], g_iFwReturn, g_iTeam)
    527.     }
    528.    
    529.     client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
    530. }
    531.  
    532. public Event_RoundEnd_Pre(WinStatus:status, ScenarioEventEndRound:event, Float:tmDelay)
    533. {
    534.     // The two unhandeld cases by rg_round_end() native in our Mod
    535.     if (event == ROUND_CTS_WIN || event == ROUND_TERRORISTS_WIN)
    536.     {
    537.         SetHookChainArg(3, ATYPE_FLOAT, get_pcvar_float(g_pCvarRoundEndDelay))
    538.     }
    539. }
    540.  
    541. public Round_Start()
    542. {
    543.     g_flReferenceTime = get_gametime()
    544.     g_iRoundTime = get_member_game(m_iRoundTime)
    545. }
    546.  
    547. public Check_RoundTimeleft()
    548. {
    549.     new Float:flRoundTimeLeft = (g_flReferenceTime + float(g_iRoundTime)) - get_gametime()
    550.    
    551.     if (floatround(flRoundTimeLeft) == 0)
    552.     {
    553.         // Round is Ending
    554.         g_bIsRoundEnding = true
    555.        
    556.         // If Time is Out then Terminate the Round
    557.         rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
    558.        
    559.         // Show our Message
    560.         client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
    561.     }
    562. }
    563.  
    564. public client_disconnected(id)
    565. {
    566.     // Delay Then Check Players to Terminate The round (Delay needed)
    567.     set_task(0.1, "Check_AlivePlayers")
    568.    
    569.     // Reset speed for this dropped id
    570.     g_bHSpeedUsed[id] = false
    571.     g_bZSpeedUsed[id] = false
    572. }
    573.  
    574. // This check done when player disconnect
    575. public Check_AlivePlayers()
    576. {
    577.     g_iAliveZombiesNum = GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
    578.     g_iAliveHumansNum = GetAlivePlayersNum(CsTeams:TEAM_CT)
    579.    
    580.     // Game Started? (There is at least 2 players Alive?)
    581.     if (g_bGameStarted)
    582.     {
    583.         // We are in freeze time?
    584.         if (get_member_game(m_bFreezePeriod))
    585.         {
    586.             // Humans alive number = 1 and no zombies?
    587.             if (g_iAliveHumansNum < get_pcvar_num(g_pCvarReqPlayers))
    588.             {
    589.                 // Game started false again
    590.                 g_bGameStarted = false
    591.             }
    592.         }
    593.         else // Not freeze time?
    594.         {
    595.             // Variables
    596.             new iAllZombiesNum = GetTeamPlayersNum(CsTeams:TEAM_TERRORIST),
    597.             iAllHumansNum = GetTeamPlayersNum(CsTeams:TEAM_CT),
    598.             iDeadZombiesNum = GetDeadPlayersNum(CsTeams:TEAM_TERRORIST),
    599.             iDeadHumansNum = GetDeadPlayersNum(CsTeams:TEAM_CT)
    600.    
    601.             // Alive humans number = 1 and no zombies at all, And no dead humans?
    602.             if (g_iAliveHumansNum < get_pcvar_num(g_pCvarReqPlayers) && iDeadHumansNum == 0 && iAllZombiesNum == 0)
    603.             {
    604.                 // Game started is false and humans wins (Escape Success)
    605.                 g_bGameStarted = false
    606.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_CTS, ROUND_CTS_WIN, "")
    607.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
    608.             }
    609.            
    610.             // Alive zombies number = 1 and no humans at all, And no dead zombies?
    611.             if (g_iAliveZombiesNum < get_pcvar_num(g_pCvarReqPlayers) && iDeadZombiesNum == 0 && iAllHumansNum == 0)
    612.             {
    613.                 // Game started is false and zombies wins (Escape Fail)
    614.                 g_bGameStarted = false
    615.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "")
    616.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_FAIL")
    617.             }
    618.            
    619.             // Humans number more than 1 and no zombies?
    620.             if (g_iAliveHumansNum >= get_pcvar_num(g_pCvarReqPlayers) && g_iAliveZombiesNum == 0 && !g_bIsRoundEnding)
    621.             {
    622.                 // Then Escape success as there is no Zombies
    623.                 rg_round_end(get_pcvar_float(g_pCvarRoundEndDelay), WINSTATUS_CTS, ROUND_CTS_WIN, "")
    624.                 client_print(0, print_center, "%L", LANG_PLAYER, "ESCAPE_SUCCESS")
    625.             }
    626.            
    627.             // Zombies number more than 1 and no humans?
    628.             if (g_iAliveZombiesNum >= get_pcvar_num(g_pCvarReqPlayers) && g_iAliveHumansNum == 0 && !g_bIsRoundEnding)
    629.             {
    630.                 // Then Escape Fail as there is no humans
    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.     }
    636. }
    637.  
    638. public client_putinserver(id)
    639. {
    640.     // Add Delay and Check Conditions To start the Game (Delay needed)
    641.     set_task(1.0, "Check_AllPlayersNumber", _, _, _, "b")
    642. }
    643.  
    644. public Check_AllPlayersNumber(TaskID)
    645. {
    646.     if (g_bGameStarted)
    647.     {
    648.         // If game started remove the task and block the blew Checks
    649.         remove_task(TaskID)
    650.         return
    651.     }
    652.    
    653.     if (GetAllAlivePlayersNum() >= get_pcvar_num(g_pCvarReqPlayers))
    654.     {
    655.         // Players In server == The Required so game started is true
    656.         g_bGameStarted = true
    657.        
    658.         // Restart the game
    659.         server_cmd("sv_restart 2")
    660.        
    661.         // Print Fake game Commencing Message
    662.         client_print(0, print_center, "%L", LANG_PLAYER, "START_GAME")
    663.        
    664.         // Remove the task
    665.         remove_task(TaskID)
    666.     }
    667. }
    668.  
    669. public Set_User_Human(id)
    670. {
    671.     if (!is_user_alive(id))
    672.         return
    673.    
    674.     g_bIsZombie[id] = false
    675.     set_entvar(id, var_health, get_pcvar_float(g_pCvarHumanHealth))
    676.     set_entvar(id, var_gravity, get_pcvar_float(g_pCvarHumanGravity)/800.0)
    677.     ExecuteForward(g_iForwards[FORWARD_HUMANIZED], g_iFwReturn, id)
    678.    
    679.     if (get_member(id, m_iTeam) != TEAM_CT)
    680.         rg_set_user_team(id, TEAM_CT, MODEL_UNASSIGNED)
    681. }
    682.  
    683. public Set_User_Zombie(id)
    684. {
    685.     if (!is_user_alive(id))
    686.         return
    687.    
    688.     g_bIsZombie[id] = true
    689.     set_entvar(id, var_health, get_pcvar_float(g_pCvarZombieHealth))
    690.     set_entvar(id, var_gravity, get_pcvar_float(g_pCvarZombieGravity)/800.0)
    691.     rg_remove_all_items(id)
    692.     rg_give_item(id, "weapon_knife", GT_APPEND)
    693.     ExecuteForward(g_iForwards[FORWARD_INFECTED], g_iFwReturn, id, 0)
    694.    
    695.     if (get_member(id, m_iTeam) != TEAM_TERRORIST)
    696.         rg_set_user_team(id, TEAM_TERRORIST, MODEL_UNASSIGNED)
    697. }
    698.  
    699. public Map_Restart()
    700. {
    701.     // Add Delay To help Rest Scores if player kill himself, and there no one else him so round draw (Delay needed)
    702.     set_task(0.1, "Reset_Score_Message")
    703. }
    704.  
    705. public Reset_Score_Message()
    706. {
    707.     g_iHumansScore = 0
    708.     g_iZombiesScore = 0
    709.     g_iRoundNum = 0
    710. }
    711.  
    712. // Natives
    713. public native_ze_is_user_zombie(id)
    714. {
    715.     if (!is_user_connected(id))
    716.     {
    717.         return -1;
    718.     }
    719.    
    720.     return g_bIsZombie[id]
    721. }
    722.  
    723. public native_ze_set_user_zombie(id)
    724. {
    725.     if (!is_user_connected(id))
    726.     {
    727.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    728.         return false;
    729.     }
    730.    
    731.     Set_User_Zombie(id)
    732.     return true;
    733. }
    734.  
    735. public native_ze_set_user_human(id)
    736. {
    737.     if (!is_user_connected(id))
    738.     {
    739.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    740.         return false;
    741.     }
    742.    
    743.     Set_User_Human(id)
    744.     return true;
    745. }
    746.  
    747. public native_ze_is_game_started()
    748. {
    749.     return g_bGameStarted
    750. }
    751.  
    752. public native_ze_is_zombie_frozen(id)
    753. {
    754.     if (!is_user_connected(id) || !g_bIsZombie[id])
    755.     {
    756.         return -1;
    757.     }
    758.    
    759.     return g_bIsZombieFrozen[id]
    760. }
    761.  
    762. public native_ze_get_round_number()
    763. {
    764.     if (!g_bGameStarted)
    765.     {
    766.         return -1;
    767.     }
    768.    
    769.     return g_iRoundNum
    770. }
    771.  
    772. public native_ze_get_humans_number()
    773. {
    774.     return GetAlivePlayersNum(CsTeams:TEAM_CT)
    775. }
    776.  
    777. public native_ze_get_zombies_number()
    778. {
    779.     return GetAlivePlayersNum(CsTeams:TEAM_TERRORIST)
    780. }
    781.  
    782. public native_ze_set_human_speed_factor(id, iFactor)
    783. {
    784.     if (!is_user_connected(id))
    785.     {
    786.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    787.         return false;
    788.     }
    789.    
    790.     g_bHSpeedUsed[id] = true
    791.     g_iHSpeedFactor[id] = iFactor
    792.     ExecuteHamB(Ham_Item_PreFrame, id)
    793.     return true;
    794. }
    795.  
    796. public native_ze_reset_human_speed(id)
    797. {
    798.     if (!is_user_connected(id))
    799.     {
    800.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    801.         return false;
    802.     }
    803.    
    804.     g_bHSpeedUsed[id] = false
    805.     ExecuteHamB(Ham_Item_PreFrame, id)
    806.     return true;
    807. }
    808.  
    809. public native_ze_set_zombie_speed(id, iSpeed)
    810. {
    811.     if (!is_user_connected(id))
    812.     {
    813.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    814.         return false;
    815.     }
    816.    
    817.     g_bZSpeedUsed[id] = true
    818.     g_iZSpeedSet[id] = iSpeed
    819.     return true;
    820. }
    821.  
    822. public native_ze_reset_zombie_speed(id)
    823. {
    824.     if (!is_user_connected(id))
    825.     {
    826.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
    827.         return false;
    828.     }
    829.    
    830.     g_bZSpeedUsed[id] = false
    831.     return true;
    832. }
He who fails to plan is planning to fail

Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Who is online

Users browsing this forum: No registered users and 1 guest