Recoded IsClientPlayer, renamed to IsClientValid, replaced

GetMaxClients() with maxclients
Ignore diff for zhp.inc and spawnprotect.inc
This commit is contained in:
Greyscale 2009-04-16 03:57:46 +02:00
parent f39570205e
commit 872e41e6d2
14 changed files with 394 additions and 385 deletions

View File

@ -127,7 +127,6 @@ public OnLibraryAdded(const String:name[])
public OnMapStart() public OnMapStart()
{ {
maxclients = GetMaxClients();
MapChangeCleanup(); MapChangeCleanup();
LoadModelData(); LoadModelData();
@ -226,13 +225,14 @@ MapChangeCleanup()
AmbienceStopAll(); AmbienceStopAll();
AntiStickReset(); AntiStickReset();
for (new client = 1; client <= maxclients; client++) // x = client index.
for (new x = 1; x <= MaxClients; x++)
{ {
for (new x = 0; x < MAXTIMERS; x++) for (new y = 0; y < MAXTIMERS; y++)
{ {
if (tHandles[client][x] != INVALID_HANDLE) if (tHandles[x][y] != INVALID_HANDLE)
{ {
tHandles[client][x] = INVALID_HANDLE; tHandles[x][y] = INVALID_HANDLE;
} }
} }
} }
@ -250,7 +250,7 @@ ZREnd()
new maxplayers = GetMaxClients(); new maxplayers = GetMaxClients();
for (new x = 1; x <= maxplayers; x++) for (new x = 1; x <= maxplayers; x++)
{ {
if (!IsClientConnected(x) || !IsClientInGame(x)) if (!IsClientInGame(x))
{ {
continue; continue;
} }

View File

@ -97,9 +97,10 @@ AmbienceStop(client)
AmbienceStopAll() AmbienceStopAll()
{ {
for (new client = 1; client < maxclients; client++) // x = client index.
for (new x = 1; x < MaxClients; x++)
{ {
AmbienceStop(client); AmbienceStop(x);
} }
} }
@ -111,9 +112,10 @@ AmbienceRestart(client)
AmbienceRestartAll() AmbienceRestartAll()
{ {
for (new client = 1; client < maxclients; client++) // x = client index.
for (new x = 1; x < MaxClients; x++)
{ {
AmbienceRestart(client); AmbienceRestart(x);
} }
} }

View File

@ -324,48 +324,50 @@ id damage interval x_min y_min z_min x_max y_max z_max
UpdatePlayerLocations() UpdatePlayerLocations()
{ {
new client; // x = client index.
for (client = 1; client <= maxclients; client++) for (new x = 1; x <= MaxClients; x++)
{ {
if (IsClientConnected(client) && IsClientInGame(client)) // If client isn't in-game, then stop.
if (!IsClientInGame(x))
{ {
GetClientAbsOrigin(client, player_loc[client]); return;
} }
GetClientAbsOrigin(x, player_loc[x]);
} }
} }
HurtPlayersInVolume(volume_index) HurtPlayersInVolume(volume_index)
{ {
new client;
new client_health; new client_health;
decl String:client_name[64]; decl String:client_name[64];
decl String:buffer[192]; decl String:buffer[192];
new anticamp_echo = GetConVarBool(gCvars[CVAR_ANTICAMP_ECHO]); new anticamp_echo = GetConVarBool(gCvars[CVAR_ANTICAMP_ECHO]);
for (client = 1; client <= maxclients; client++) // x = client index.
for (new x = 1; x <= MaxClients; x++)
{ {
if (IsClientConnected(client) && if (IsClientInGame(x) &&
IsClientInGame(client) && IsPlayerAlive(x) &&
IsPlayerAlive(client) && IsPlayerHuman(x))
IsPlayerHuman(client))
{ {
if (IsPlayerInVolume(client, volume_index)) if (IsPlayerInVolume(x, volume_index))
{ {
ZR_PrintToChat(client, "Unfair camping"); ZR_PrintToChat(x, "Unfair camping");
client_health = GetClientHealth(client) - volumes[volume_index][volume_damage]; client_health = GetClientHealth(x) - volumes[volume_index][volume_damage];
if (client_health > 0) if (client_health > 0)
{ {
SetEntityHealth(client, client_health); SetEntityHealth(x, client_health);
} }
else else
{ {
ForcePlayerSuicide(client); ForcePlayerSuicide(x);
GetClientName(client, client_name, sizeof(client_name)); GetClientName(x, client_name, sizeof(client_name));
SetGlobalTransTarget(client); SetGlobalTransTarget(x);
Format(buffer, sizeof(buffer), "%T", "Unfair camper slayed", LANG_SERVER, client_name, volume_index); Format(buffer, sizeof(buffer), "%T", "Unfair camper slayed", LANG_SERVER, client_name, volume_index);
if (LogFlagCheck(LOG_GAME_EVENTS, LOG_MODULE_ANTICAMP)) ZR_LogMessageFormatted(client, "anticamp", "kill", "%s", true, buffer); if (LogFlagCheck(LOG_GAME_EVENTS, LOG_MODULE_ANTICAMP)) ZR_LogMessageFormatted(x, "anticamp", "kill", "%s", true, buffer);
if (anticamp_echo) if (anticamp_echo)
{ {
FormatTextString(buffer, sizeof(buffer)); FormatTextString(buffer, sizeof(buffer));

View File

@ -250,7 +250,7 @@ public Action:Command_GetClassKnockback(client, argc)
public Action:Command_AdminMenu(client, argc) public Action:Command_AdminMenu(client, argc)
{ {
if (IsClientPlayer(client)) if (ZRIsValidClient(client))
{ {
ZRAdminMenu(client); ZRAdminMenu(client);
} }
@ -264,7 +264,7 @@ public Action:Command_AdminMenu(client, argc)
public Action:Command_KnockbackMMenu(client, argc) public Action:Command_KnockbackMMenu(client, argc)
{ {
if (IsClientPlayer(client)) if (ZRIsValidClient(client))
{ {
// Disabled, under construction. // Disabled, under construction.
// ZRKnockbackMMenu(client); // ZRKnockbackMMenu(client);
@ -279,7 +279,7 @@ public Action:Command_KnockbackMMenu(client, argc)
public Action:Command_TeleMenu(client, argc) public Action:Command_TeleMenu(client, argc)
{ {
if (IsClientPlayer(client)) if (ZRIsValidClient(client))
{ {
ZRZTeleMenu(client); ZRZTeleMenu(client);
} }

View File

@ -24,11 +24,8 @@ new gHooks[MAXPLAYERS + 1][ZRHooks];
InitDmgControl() InitDmgControl()
{ {
/* It's case sensitive! */
RegConsoleCmd("kill", Attempt_Suicide); RegConsoleCmd("kill", Attempt_Suicide);
RegConsoleCmd("KILL", Attempt_Suicide);
RegConsoleCmd("jointeam", Attempt_Suicide); RegConsoleCmd("jointeam", Attempt_Suicide);
RegConsoleCmd("JOINTEAM", Attempt_Suicide);
RegConsoleCmd("spectate", Attempt_Suicide); RegConsoleCmd("spectate", Attempt_Suicide);
} }
@ -48,7 +45,7 @@ public TraceAttack(client, inflictor, attacker, damage, hitbox, hitgroup)
{ {
new bool:enabled = GetConVarBool(gCvars[CVAR_ENABLE]); new bool:enabled = GetConVarBool(gCvars[CVAR_ENABLE]);
if (!attacker || !IsClientPlayer(attacker) || !IsClientInGame(attacker) || !enabled) if (!attacker || !ZRIsValidClient(attacker) || !IsClientInGame(attacker) || !enabled)
{ {
return Hacks_Continue; return Hacks_Continue;
} }
@ -99,7 +96,7 @@ public OnTakeDamage(client, inflictor, attacker, damage, damagetype, ammotype)
if (damagetype & DMG_BLAST) if (damagetype & DMG_BLAST)
{ {
if (!IsPlayerHuman(client) || !IsClientPlayer(attacker) || !IsClientInGame(attacker)) if (!IsPlayerHuman(client) || !ZRIsValidClient(attacker) || !IsClientInGame(attacker))
{ {
return Hacks_Continue; return Hacks_Continue;
} }
@ -109,12 +106,12 @@ public OnTakeDamage(client, inflictor, attacker, damage, damagetype, ammotype)
if (damagetype & DMG_BULLET) if (damagetype & DMG_BULLET)
{ {
if (!client || !IsClientPlayer(client) || !IsClientInGame(client)) if (!client || !ZRIsValidClient(client) || !IsClientInGame(client))
{ {
return Hacks_Continue; return Hacks_Continue;
} }
if (!attacker || !IsClientPlayer(attacker) || !IsClientInGame(attacker)) if (!attacker || !ZRIsValidClient(attacker) || !IsClientInGame(attacker))
{ {
return Hacks_Continue; return Hacks_Continue;
} }

View File

@ -220,11 +220,8 @@ public Action:PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
decl String:weapon[32]; decl String:weapon[32];
GetEventString(event, "weapon", weapon, sizeof(weapon)); GetEventString(event, "weapon", weapon, sizeof(weapon));
// Forward event to modules.
KnockbackPlayerHurt(index, attacker, weapon, hitgroup, dmg_health);
// Check if the attacker is a player. // Check if the attacker is a player.
if (attacker != 0) if (ZRIsValidClient(attacker))
{ {
// Check if a zombie attacks a human. // Check if a zombie attacks a human.
if (IsPlayerHuman(index) && IsPlayerZombie(attacker)) if (IsPlayerHuman(index) && IsPlayerZombie(attacker))
@ -265,6 +262,7 @@ public Action:PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
// Forward event to modules. // Forward event to modules.
ClassAlphaUpdate(index); ClassAlphaUpdate(index);
KnockbackPlayerHurt(index, attacker, weapon, hitgroup, dmg_health);
ZHPOnPlayerHurt(index); ZHPOnPlayerHurt(index);
} }
@ -285,13 +283,13 @@ public Action:PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
if (StrEqual(weapon, "zombie_claws_of_death", false)) if (StrEqual(weapon, "zombie_claws_of_death", false))
{ {
// Add a death count to the players score. // Add a death count to the players score.
if (index) if (ZRIsValidClient(index))
{ {
AddPlayerDeath(index, 1); AddPlayerDeath(index, 1);
} }
// Give a point to the attacker. // Give a point to the attacker.
if (attacker) if (ZRIsValidClient(attacker))
{ {
AddPlayerScore(attacker, 1); AddPlayerScore(attacker, 1);
@ -317,14 +315,14 @@ public Action:PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
EmitSoundToAll(sound, index); EmitSoundToAll(sound, index);
// Give kill bonus. // Give kill bonus.
if (attacker) if (ZRIsValidClient(attacker))
{ {
new bonus = ClassGetKillBonus(attacker); new bonus = ClassGetKillBonus(attacker);
AddPlayerScore(attacker, bonus); AddPlayerScore(attacker, bonus);
} }
// Check if the player was killed by world damage. // Check if the player was killed by world damage.
if (!IsClientPlayer(attacker)) if (!ZRIsValidClient(attacker))
{ {
gKilledByWorld[index] = true; gKilledByWorld[index] = true;
} }

View File

@ -9,7 +9,7 @@
MainMenu(client) MainMenu(client)
{ {
new Handle:menu_main = CreateMenu(MainMenuHandle); new Handle:menu_main = CreateMenu(MainMenuHandle);
new itemdraw = (IsClientAdmin(client)) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED; new itemdraw = (ZRIsClientAdmin(client)) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED;
SetGlobalTransTarget(client); SetGlobalTransTarget(client);

View File

@ -48,7 +48,7 @@ Admin mode is enabled!
ClassMenuMain(client) ClassMenuMain(client)
{ {
new Handle:menu = CreateMenu(ClassMenuMainHandle); new Handle:menu = CreateMenu(ClassMenuMainHandle);
new itemdraw = (IsClientAdmin(client)) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED; new itemdraw = (ZRIsClientAdmin(client)) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED;
SetGlobalTransTarget(client); SetGlobalTransTarget(client);
SetMenuTitle(menu, "%t\n", "!zclass title"); SetMenuTitle(menu, "%t\n", "!zclass title");
@ -83,7 +83,7 @@ ClassMenuMain(client)
Format(humanselect, sizeof(humanselect), "%t\n %s", "!zclass human", humanclass); Format(humanselect, sizeof(humanselect), "%t\n %s", "!zclass human", humanclass);
AddMenuItem(menu, "", humanselect); AddMenuItem(menu, "", humanselect);
if (IsClientAdmin(client)) if (ZRIsClientAdmin(client))
{ {
// List admin class options. // List admin class options.
ClassGetName(ClassSelected[client][ZR_CLASS_TEAM_ADMINS], adminclass, sizeof(adminclass), ZR_CLASS_CACHE_MODIFIED); ClassGetName(ClassSelected[client][ZR_CLASS_TEAM_ADMINS], adminclass, sizeof(adminclass), ZR_CLASS_CACHE_MODIFIED);
@ -134,7 +134,7 @@ public ClassMenuMainHandle(Handle:menu, MenuAction:action, client, slot)
} }
case 3: case 3:
{ {
ClassMenuToggleAdmin(client); // ClassMenuToggleAdmin(client);
} }
} }
} }
@ -273,5 +273,4 @@ public ClassMenuSelectHandle(Handle:menu, MenuAction:action, client, slot)
ClassMenuToggleAdmin(client) ClassMenuToggleAdmin(client)
{ {
} }

View File

@ -457,7 +457,7 @@ bool:ClassReloadDataCache()
bool:ClassReloadPlayerCache(client, classindex, cachetype = ZR_CLASS_CACHE_MODIFIED) bool:ClassReloadPlayerCache(client, classindex, cachetype = ZR_CLASS_CACHE_MODIFIED)
{ {
// Validate indexes. // Validate indexes.
if (!ClassValidateIndex(classindex) || !IsClientPlayer(client)) if (!ClassValidateIndex(classindex) || !ZRIsValidClient(client))
{ {
return false; return false;
} }

View File

@ -1,146 +1,146 @@
/* /*
* ============================================================================ * ============================================================================
* *
* Zombie:Reloaded * Zombie:Reloaded
* *
* File: spawnprotect.inc * File: spawnprotect.inc
* Description: Protects late-joining players from zombies for x seconds. * Description: Protects late-joining players from zombies for x seconds.
* *
* ============================================================================ * ============================================================================
*/ */
/** /**
* Array for storing spawn protect timer handles per client. * Array for storing spawn protect timer handles per client.
*/ */
new Handle:tSpawnProtect[MAXPLAYERS + 1]; new Handle:tSpawnProtect[MAXPLAYERS + 1];
/** /**
* Array for flagging client to be protected. * Array for flagging client to be protected.
*/ */
new bool:pSpawnProtect[MAXPLAYERS + 1]; new bool:pSpawnProtect[MAXPLAYERS + 1];
/** /**
* Array for storing time left for spawn protection per client. * Array for storing time left for spawn protection per client.
*/ */
new pSpawnProtectTime[MAXPLAYERS + 1]; new pSpawnProtectTime[MAXPLAYERS + 1];
/** /**
* Client is joining the server. * Client is joining the server.
* *
* @param client The client index. * @param client The client index.
*/ */
SpawnProtectClientInit(client) SpawnProtectClientInit(client)
{ {
// Reset timer handle. // Reset timer handle.
tSpawnProtect[client] = INVALID_HANDLE; tSpawnProtect[client] = INVALID_HANDLE;
} }
/** /**
* Player is spawning into the game. * Player is spawning into the game.
* *
* @param client The client index. * @param client The client index.
*/ */
SpawnProtectPlayerSpawn(client) SpawnProtectPlayerSpawn(client)
{ {
// Disable spawn protection on client. // Disable spawn protection on client.
pSpawnProtect[client] = false; pSpawnProtect[client] = false;
// If zombie hasn't spawned, then stop. // If zombie hasn't spawned, then stop.
if (!zombieSpawned) if (!zombieSpawned)
{ {
return; return;
} }
// If protect cvar is invalid or 0, then stop. // If protect cvar is invalid or 0, then stop.
new protect = GetConVarInt(gCvars[CVAR_PROTECT]); new protect = GetConVarInt(gCvars[CVAR_PROTECT]);
if (protect <= 0) if (protect <= 0)
{ {
return; return;
} }
// Get respawn team. // Get respawn team.
decl String:respawnteam[32]; decl String:respawnteam[32];
GetConVarString(gCvars[CVAR_RESPAWN_TEAM], respawnteam, sizeof(respawnteam)); GetConVarString(gCvars[CVAR_RESPAWN_TEAM], respawnteam, sizeof(respawnteam));
// If the respawn team is not set to zombie, and either cvar zr_suicide_world_damage or the client // If the respawn team is not set to zombie, and either cvar zr_suicide_world_damage or the client
// wasn't killed by world is false, then continue to protect client. // wasn't killed by world is false, then continue to protect client.
if (!StrEqual(respawnteam, "zombie", false) && !(GetConVarBool(gCvars[CVAR_SUICIDE_WORLD_DAMAGE]) && gKilledByWorld[client])) if (!StrEqual(respawnteam, "zombie", false) && !(GetConVarBool(gCvars[CVAR_SUICIDE_WORLD_DAMAGE]) && gKilledByWorld[client]))
{ {
// Set spawn protect flag on client. // Set spawn protect flag on client.
pSpawnProtect[client] = true; pSpawnProtect[client] = true;
// Set improved attributes // Set improved attributes
// (Move to cvar?) // (Move to cvar?)
SetPlayerAlpha(client, 0); SetPlayerAlpha(client, 0);
SetPlayerSpeed(client, 600.0); SetPlayerSpeed(client, 600.0);
// Set time left to zr_protect's value. // Set time left to zr_protect's value.
pSpawnProtectTime[client] = protect; pSpawnProtectTime[client] = protect;
// Tell client they are being protected. // Tell client they are being protected.
ZR_PrintToChat(client, "Spawn protection begin", protect); ZR_PrintToChat(client, "Spawn protection begin", protect);
// Send time left in a hud message. // Send time left in a hud message.
ZR_HudHint(client, "Spawn Protect", pSpawnProtectTime[client]); ZR_HudHint(client, "Spawn Protect", pSpawnProtectTime[client]);
// If timer is currently running, kill it. // If timer is currently running, kill it.
if (tSpawnProtect[client] != INVALID_HANDLE) if (tSpawnProtect[client] != INVALID_HANDLE)
{ {
KillTimer(tSpawnProtect[client]); KillTimer(tSpawnProtect[client]);
} }
// Start repeating timer. // Start repeating timer.
tSpawnProtect[client] = CreateTimer(1.0, SpawnProtectTimer, client, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT); tSpawnProtect[client] = CreateTimer(1.0, SpawnProtectTimer, client, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
} }
} }
/** /**
* Timer callback function, countdown for spawn protection. * Timer callback function, countdown for spawn protection.
* *
* @param timer The timer handle. * @param timer The timer handle.
* @param client The client index. * @param client The client index.
*/ */
public Action:SpawnProtectTimer(Handle:timer, any:client) public Action:SpawnProtectTimer(Handle:timer, any:client)
{ {
// If client leaves, then stop timer. // If client leaves, then stop timer.
if (!IsClientInGame(client)) if (!IsClientInGame(client))
{ {
return Plugin_Stop; return Plugin_Stop;
} }
// If client has become a zombie, then stop timer. // If client has become a zombie, then stop timer.
if (!IsPlayerHuman(client)) if (!IsPlayerHuman(client))
{ {
return Plugin_Stop; return Plugin_Stop;
} }
// Decrement time left. // Decrement time left.
pSpawnProtectTime[client]--; pSpawnProtectTime[client]--;
// Print time left to client. // Print time left to client.
ZR_HudHint(client, "Spawn Protect", pSpawnProtectTime[client]); ZR_HudHint(client, "Spawn Protect", pSpawnProtectTime[client]);
// Time has expired. // Time has expired.
if (pSpawnProtectTime[client] <= 0) if (pSpawnProtectTime[client] <= 0)
{ {
// Remove protect flag. // Remove protect flag.
pSpawnProtect[client] = false; pSpawnProtect[client] = false;
// Tell client spawn protection is over. // Tell client spawn protection is over.
ZR_HudHint(client, "Spawn protection end"); ZR_HudHint(client, "Spawn protection end");
// Fix attributes. // Fix attributes.
// TODO: Set class attributes. // TODO: Set class attributes.
SetPlayerAlpha(client, 255); SetPlayerAlpha(client, 255);
SetPlayerSpeed(client, 300.0); SetPlayerSpeed(client, 300.0);
// Clear timer handle. // Clear timer handle.
tSpawnProtect[client] = INVALID_HANDLE; tSpawnProtect[client] = INVALID_HANDLE;
// Stop timer. // Stop timer.
return Plugin_Stop; return Plugin_Stop;
} }
// Allow timer to continue repeating. // Allow timer to continue repeating.
return Plugin_Continue; return Plugin_Continue;
} }

View File

@ -23,7 +23,7 @@ stock ZR_PrintToChat(client, any:...)
{ {
decl String:phrase[192]; decl String:phrase[192];
if (client) if (ZRIsValidClient(client))
{ {
SetGlobalTransTarget(client); SetGlobalTransTarget(client);
@ -204,11 +204,13 @@ stock ZR_PrintToAdminChat(String:message[])
{ {
decl String:buffer[256]; decl String:buffer[256];
Format(buffer, sizeof(buffer), "[ZR] %s", message); Format(buffer, sizeof(buffer), "[ZR] %s", message);
for (new client = 1; client < maxclients; client++)
// x = client index.
for (new x = 1; x < MaxClients; x++)
{ {
if (IsClientConnected(client) && IsClientInGame(client) && GetAdminFlag(GetUserAdmin(client), Admin_Generic)) if (IsClientInGame(x) && ZRIsClientAdmin(x))
{ {
PrintToChat(client, buffer); PrintToChat(x, buffer);
} }
} }
} }

View File

@ -11,7 +11,7 @@ new curMenuClass[MAXPLAYERS + 1];
bool:ZRAdminMenu(client) bool:ZRAdminMenu(client)
{ {
if (!IsClientAdmin(client)) if (!ZRIsClientAdmin(client))
{ {
ZR_PrintToChat(client, "Must be admin"); ZR_PrintToChat(client, "Must be admin");
return false; return false;
@ -417,7 +417,8 @@ public ZRInfectHandle(Handle:menu_infect, MenuAction:action, client, slot)
ZRSpawnAll(client) ZRSpawnAll(client)
{ {
for (new x = 1; x < maxclients; x++) // x = client index.
for (new x = 1; x < MaxClients; x++)
{ {
if (IsClientInGame(x)) if (IsClientInGame(x))
{ {

View File

@ -1,175 +1,175 @@
/* /*
* ============================================================================ * ============================================================================
* *
* Zombie:Reloaded * Zombie:Reloaded
* *
* File: zhp.inc * File: zhp.inc
* Description: Displays * Description: Displays HP to zombies.
* Author: Greyscale, Richard Helgeby * Author: Greyscale, Richard Helgeby
* *
* ============================================================================ * ============================================================================
*/ */
/** /**
* Array for storing ZHP timer handles per client. * Array for storing ZHP timer handles per client.
*/ */
new Handle:tZHP[MAXPLAYERS + 1]; new Handle:tZHP[MAXPLAYERS + 1];
/** /**
* Array for flagging client to display HP * Array for flagging client to display HP
*/ */
new bool:pZHP[MAXPLAYERS + 1]; new bool:pZHP[MAXPLAYERS + 1];
/** /**
* Client is joining the server. * Client is joining the server.
* *
* @param client The client index. * @param client The client index.
*/ */
ZHPClientInit(client) ZHPClientInit(client)
{ {
// Get default client setting from cvar. // Get default client setting from cvar.
new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP_DEFAULT]); new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP_DEFAULT]);
// Set flag to default value. // Set flag to default value.
pZHP[client] = zhp; pZHP[client] = zhp;
// Reset timer handle. // Reset timer handle.
tZHP[client] = INVALID_HANDLE; tZHP[client] = INVALID_HANDLE;
} }
/** /**
* Toggle ZHP on a client. * Toggle ZHP on a client.
* *
* @param client The client index. * @param client The client index.
*/ */
ZHPToggle(client) ZHPToggle(client)
{ {
// If ZHP is disabled, then stop. // If ZHP is disabled, then stop.
new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP]); new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP]);
if (!zhp) if (!zhp)
{ {
// Tell client feature is disabled. // Tell client feature is disabled.
ZR_PrintToChat(client, "Feature is disabled"); ZR_PrintToChat(client, "Feature is disabled");
// Stop. // Stop.
return; return;
} }
// If ZHP is enabled, then tell client it's being disabled. // If ZHP is enabled, then tell client it's being disabled.
if (pZHP[client]) if (pZHP[client])
{ {
ZR_PrintToChat(client, "ZHP disable"); ZR_PrintToChat(client, "ZHP disable");
} }
// If ZHP is disabled, then tell client it's being enabled. // If ZHP is disabled, then tell client it's being enabled.
else else
{ {
ZR_PrintToChat(client, "ZHP enable"); ZR_PrintToChat(client, "ZHP enable");
// Update HP display. // Update HP display.
ZHPUpdateHUD(client); ZHPUpdateHUD(client);
} }
// Toggle ZHP flag. // Toggle ZHP flag.
pZHP[client] = !pZHP[client]; pZHP[client] = !pZHP[client];
} }
/** /**
* Player has been infected. * Player has been infected.
* *
* @param client The client index. * @param client The client index.
*/ */
ZHPOnClientInfected(client) ZHPOnClientInfected(client)
{ {
// If ZHP is disabled, then stop. // If ZHP is disabled, then stop.
new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP]); new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP]);
if (!zhp) if (!zhp)
{ {
return; return;
} }
// Update HP display. // Update HP display.
ZHPUpdateHUD(client); ZHPUpdateHUD(client);
// If timer is currently running, kill it. // If timer is currently running, kill it.
if (tZHP[client] != INVALID_HANDLE) if (tZHP[client] != INVALID_HANDLE)
{ {
KillTimer(tZHP[client]); KillTimer(tZHP[client]);
} }
// Start repeating timer to update display. // Start repeating timer to update display.
tZHP[client] = CreateTimer(5.0, ZHPTimer, client, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT); tZHP[client] = CreateTimer(5.0, ZHPTimer, client, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
} }
/** /**
* Player has been hurt. * Player has been hurt.
* *
* @param client The client index. * @param client The client index.
*/ */
ZHPOnPlayerHurt(client) ZHPOnPlayerHurt(client)
{ {
// Update HP display. // Update HP display.
ZHPUpdateHUD(client); ZHPUpdateHUD(client);
} }
/** /**
* Zombie has gained health for infecting a player. * Zombie has gained health for infecting a player.
* *
* @param client The client index. * @param client The client index.
*/ */
ZHPOnHealthInfectGain(client) ZHPOnHealthInfectGain(client)
{ {
// Update HP display. // Update HP display.
ZHPUpdateHUD(client); ZHPUpdateHUD(client);
} }
/** /**
* Update HP display for a player. * Update HP display for a player.
* *
* @param client The client index. * @param client The client index.
*/ */
ZHPUpdateHUD(client) ZHPUpdateHUD(client)
{ {
// If ZHP is disabled, then stop. // If ZHP is disabled, then stop.
new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP]); new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP]);
if (!zhp) if (!zhp)
{ {
return; return;
} }
// If player is a zombie, or has ZHP disabled, then stop. // If player is a zombie, or has ZHP disabled, then stop.
if (!IsPlayerZombie(client) || !pZHP[client]) if (!IsPlayerZombie(client) || !pZHP[client])
{ {
return; return;
} }
// Get health, and if below 0 then set back to 0. (for display purposes) // Get health, and if below 0 then set back to 0. (for display purposes)
new health = GetClientHealth(client); new health = GetClientHealth(client);
if (health < 0) if (health < 0)
{ {
health = 0; health = 0;
} }
// Display HP // Display HP
ZR_HudHint(client, "Display HP", health); ZR_HudHint(client, "Display HP", health);
} }
/** /**
* Timer callback. Repetitively calls ZHPUpdateHUD() until stopped. * Timer callback. Repetitively calls ZHPUpdateHUD() until stopped.
* *
* @param timer The timer handle. * @param timer The timer handle.
* @param client The client index. * @param client The client index.
*/ */
public Action:ZHPTimer(Handle:timer, any:client) public Action:ZHPTimer(Handle:timer, any:client)
{ {
// If client leaves, then stop timer. // If client leaves, then stop timer.
if (!IsClientInGame(client)) if (!IsClientInGame(client))
{ {
return Plugin_Stop; return Plugin_Stop;
} }
// Update HP display. // Update HP display.
ZHPUpdateHUD(client); ZHPUpdateHUD(client);
// Allow timer to continue. // Allow timer to continue.
return Plugin_Continue; return Plugin_Continue;
} }

View File

@ -87,8 +87,6 @@ new Handle:ztele_startup_timer = INVALID_HANDLE;
new Handle:ztele_countdown_timer[MAXPLAYERS + 1] = {INVALID_HANDLE, ...}; new Handle:ztele_countdown_timer[MAXPLAYERS + 1] = {INVALID_HANDLE, ...};
new Handle:ztele_cooldown_timer[MAXPLAYERS + 1] = {INVALID_HANDLE, ...}; new Handle:ztele_cooldown_timer[MAXPLAYERS + 1] = {INVALID_HANDLE, ...};
new maxclients;
new Handle:tRound = INVALID_HANDLE; new Handle:tRound = INVALID_HANDLE;
new Handle:tInfect = INVALID_HANDLE; new Handle:tInfect = INVALID_HANDLE;
@ -233,14 +231,22 @@ bool:IsPlayerInList(client)
return false; return false;
} }
bool:IsClientPlayer(client) /**
* Check if a client index is a valid player.
*
* @param client The client index.
* @param console True to include console (index 0), false if not.
*/
bool:ZRIsValidClient(client, bool:console = false)
{ {
if (!IsFakeClient(client) && client > 0 && client <= maxclients) // If index is greater than max number of clients, then return false.
if (client > MaxClients)
{ {
return true; return false;
} }
return false; // If console is true, return if client is >= 0, if not, then return client > 0.
return console ? (client >= 0) : (client > 0);
} }
/** /**
@ -249,12 +255,14 @@ bool:IsClientPlayer(client)
* @param client The client index. * @param client The client index.
* @return True if generic admin, false otherwise. * @return True if generic admin, false otherwise.
*/ */
bool:IsClientAdmin(client) bool:ZRIsClientAdmin(client)
{ {
if (IsClientPlayer(client) && GetAdminFlag(GetUserAdmin(client), Admin_Generic)) // Check to make sure client is valid and has the Admin_Generic SourceMod admin flag.
if (ZRIsValidClient(client) && GetAdminFlag(GetUserAdmin(client), Admin_Generic))
{ {
return true; return true;
} }
// Client is not an admin.
return false; return false;
} }