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

@ -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

@ -4,7 +4,7 @@
* 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
* *
* ============================================================================ * ============================================================================

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;
} }