diff --git a/src/zombiereloaded.sp b/src/zombiereloaded.sp index 7b889b7..7e9ce4c 100644 --- a/src/zombiereloaded.sp +++ b/src/zombiereloaded.sp @@ -127,7 +127,6 @@ public OnLibraryAdded(const String:name[]) public OnMapStart() { - maxclients = GetMaxClients(); MapChangeCleanup(); LoadModelData(); @@ -226,13 +225,14 @@ MapChangeCleanup() AmbienceStopAll(); 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(); for (new x = 1; x <= maxplayers; x++) { - if (!IsClientConnected(x) || !IsClientInGame(x)) + if (!IsClientInGame(x)) { continue; } diff --git a/src/zr/ambience.inc b/src/zr/ambience.inc index 2056350..ff7e285 100644 --- a/src/zr/ambience.inc +++ b/src/zr/ambience.inc @@ -97,9 +97,10 @@ AmbienceStop(client) 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() { - for (new client = 1; client < maxclients; client++) + // x = client index. + for (new x = 1; x < MaxClients; x++) { - AmbienceRestart(client); + AmbienceRestart(x); } } diff --git a/src/zr/anticamp.inc b/src/zr/anticamp.inc index 7d6630f..d79431a 100644 --- a/src/zr/anticamp.inc +++ b/src/zr/anticamp.inc @@ -324,48 +324,50 @@ id damage interval x_min y_min z_min x_max y_max z_max UpdatePlayerLocations() { - new client; - for (client = 1; client <= maxclients; client++) + // x = client index. + 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) { - new client; new client_health; decl String:client_name[64]; decl String:buffer[192]; 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) && - IsClientInGame(client) && - IsPlayerAlive(client) && - IsPlayerHuman(client)) + if (IsClientInGame(x) && + IsPlayerAlive(x) && + IsPlayerHuman(x)) { - if (IsPlayerInVolume(client, volume_index)) + if (IsPlayerInVolume(x, volume_index)) { - ZR_PrintToChat(client, "Unfair camping"); - client_health = GetClientHealth(client) - volumes[volume_index][volume_damage]; + ZR_PrintToChat(x, "Unfair camping"); + client_health = GetClientHealth(x) - volumes[volume_index][volume_damage]; if (client_health > 0) { - SetEntityHealth(client, client_health); + SetEntityHealth(x, client_health); } else { - ForcePlayerSuicide(client); + ForcePlayerSuicide(x); - GetClientName(client, client_name, sizeof(client_name)); - SetGlobalTransTarget(client); + GetClientName(x, client_name, sizeof(client_name)); + SetGlobalTransTarget(x); 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) { FormatTextString(buffer, sizeof(buffer)); diff --git a/src/zr/commands.inc b/src/zr/commands.inc index 75e44cd..2ac5b99 100644 --- a/src/zr/commands.inc +++ b/src/zr/commands.inc @@ -250,7 +250,7 @@ public Action:Command_GetClassKnockback(client, argc) public Action:Command_AdminMenu(client, argc) { - if (IsClientPlayer(client)) + if (ZRIsValidClient(client)) { ZRAdminMenu(client); } @@ -264,7 +264,7 @@ public Action:Command_AdminMenu(client, argc) public Action:Command_KnockbackMMenu(client, argc) { - if (IsClientPlayer(client)) + if (ZRIsValidClient(client)) { // Disabled, under construction. // ZRKnockbackMMenu(client); @@ -279,7 +279,7 @@ public Action:Command_KnockbackMMenu(client, argc) public Action:Command_TeleMenu(client, argc) { - if (IsClientPlayer(client)) + if (ZRIsValidClient(client)) { ZRZTeleMenu(client); } diff --git a/src/zr/damagecontrol.inc b/src/zr/damagecontrol.inc index e6d5774..baca8db 100644 --- a/src/zr/damagecontrol.inc +++ b/src/zr/damagecontrol.inc @@ -24,11 +24,8 @@ new gHooks[MAXPLAYERS + 1][ZRHooks]; InitDmgControl() { - /* It's case sensitive! */ RegConsoleCmd("kill", Attempt_Suicide); - RegConsoleCmd("KILL", Attempt_Suicide); RegConsoleCmd("jointeam", Attempt_Suicide); - RegConsoleCmd("JOINTEAM", 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]); - if (!attacker || !IsClientPlayer(attacker) || !IsClientInGame(attacker) || !enabled) + if (!attacker || !ZRIsValidClient(attacker) || !IsClientInGame(attacker) || !enabled) { return Hacks_Continue; } @@ -99,7 +96,7 @@ public OnTakeDamage(client, inflictor, attacker, damage, damagetype, ammotype) if (damagetype & DMG_BLAST) { - if (!IsPlayerHuman(client) || !IsClientPlayer(attacker) || !IsClientInGame(attacker)) + if (!IsPlayerHuman(client) || !ZRIsValidClient(attacker) || !IsClientInGame(attacker)) { return Hacks_Continue; } @@ -109,12 +106,12 @@ public OnTakeDamage(client, inflictor, attacker, damage, damagetype, ammotype) if (damagetype & DMG_BULLET) { - if (!client || !IsClientPlayer(client) || !IsClientInGame(client)) + if (!client || !ZRIsValidClient(client) || !IsClientInGame(client)) { return Hacks_Continue; } - if (!attacker || !IsClientPlayer(attacker) || !IsClientInGame(attacker)) + if (!attacker || !ZRIsValidClient(attacker) || !IsClientInGame(attacker)) { return Hacks_Continue; } diff --git a/src/zr/event.inc b/src/zr/event.inc index 6899a23..aaf5c93 100644 --- a/src/zr/event.inc +++ b/src/zr/event.inc @@ -220,11 +220,8 @@ public Action:PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast) decl String:weapon[32]; GetEventString(event, "weapon", weapon, sizeof(weapon)); - // Forward event to modules. - KnockbackPlayerHurt(index, attacker, weapon, hitgroup, dmg_health); - // Check if the attacker is a player. - if (attacker != 0) + if (ZRIsValidClient(attacker)) { // Check if a zombie attacks a human. if (IsPlayerHuman(index) && IsPlayerZombie(attacker)) @@ -265,6 +262,7 @@ public Action:PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast) // Forward event to modules. ClassAlphaUpdate(index); + KnockbackPlayerHurt(index, attacker, weapon, hitgroup, dmg_health); ZHPOnPlayerHurt(index); } @@ -285,13 +283,13 @@ public Action:PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast) if (StrEqual(weapon, "zombie_claws_of_death", false)) { // Add a death count to the players score. - if (index) + if (ZRIsValidClient(index)) { AddPlayerDeath(index, 1); } // Give a point to the attacker. - if (attacker) + if (ZRIsValidClient(attacker)) { AddPlayerScore(attacker, 1); @@ -317,14 +315,14 @@ public Action:PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast) EmitSoundToAll(sound, index); // Give kill bonus. - if (attacker) + if (ZRIsValidClient(attacker)) { new bonus = ClassGetKillBonus(attacker); AddPlayerScore(attacker, bonus); } // Check if the player was killed by world damage. - if (!IsClientPlayer(attacker)) + if (!ZRIsValidClient(attacker)) { gKilledByWorld[index] = true; } diff --git a/src/zr/menu.inc b/src/zr/menu.inc index 329e981..ea96458 100644 --- a/src/zr/menu.inc +++ b/src/zr/menu.inc @@ -9,7 +9,7 @@ MainMenu(client) { new Handle:menu_main = CreateMenu(MainMenuHandle); - new itemdraw = (IsClientAdmin(client)) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED; + new itemdraw = (ZRIsClientAdmin(client)) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED; SetGlobalTransTarget(client); diff --git a/src/zr/playerclasses/classmenus.inc b/src/zr/playerclasses/classmenus.inc index 08fee72..428bb32 100644 --- a/src/zr/playerclasses/classmenus.inc +++ b/src/zr/playerclasses/classmenus.inc @@ -48,7 +48,7 @@ Admin mode is enabled! ClassMenuMain(client) { new Handle:menu = CreateMenu(ClassMenuMainHandle); - new itemdraw = (IsClientAdmin(client)) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED; + new itemdraw = (ZRIsClientAdmin(client)) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED; SetGlobalTransTarget(client); SetMenuTitle(menu, "%t\n", "!zclass title"); @@ -83,7 +83,7 @@ ClassMenuMain(client) Format(humanselect, sizeof(humanselect), "%t\n %s", "!zclass human", humanclass); AddMenuItem(menu, "", humanselect); - if (IsClientAdmin(client)) + if (ZRIsClientAdmin(client)) { // List admin class options. 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: { - ClassMenuToggleAdmin(client); + // ClassMenuToggleAdmin(client); } } } @@ -273,5 +273,4 @@ public ClassMenuSelectHandle(Handle:menu, MenuAction:action, client, slot) ClassMenuToggleAdmin(client) { - } diff --git a/src/zr/playerclasses/playerclasses.inc b/src/zr/playerclasses/playerclasses.inc index b0e150e..33c4a07 100644 --- a/src/zr/playerclasses/playerclasses.inc +++ b/src/zr/playerclasses/playerclasses.inc @@ -457,7 +457,7 @@ bool:ClassReloadDataCache() bool:ClassReloadPlayerCache(client, classindex, cachetype = ZR_CLASS_CACHE_MODIFIED) { // Validate indexes. - if (!ClassValidateIndex(classindex) || !IsClientPlayer(client)) + if (!ClassValidateIndex(classindex) || !ZRIsValidClient(client)) { return false; } diff --git a/src/zr/spawnprotect.inc b/src/zr/spawnprotect.inc index 4a5a31b..3e796d8 100644 --- a/src/zr/spawnprotect.inc +++ b/src/zr/spawnprotect.inc @@ -1,146 +1,146 @@ -/* - * ============================================================================ - * - * Zombie:Reloaded - * - * File: spawnprotect.inc - * Description: Protects late-joining players from zombies for x seconds. - * - * ============================================================================ - */ - -/** - * Array for storing spawn protect timer handles per client. - */ -new Handle:tSpawnProtect[MAXPLAYERS + 1]; - -/** - * Array for flagging client to be protected. - */ -new bool:pSpawnProtect[MAXPLAYERS + 1]; - -/** - * Array for storing time left for spawn protection per client. - */ -new pSpawnProtectTime[MAXPLAYERS + 1]; - -/** - * Client is joining the server. - * - * @param client The client index. - */ -SpawnProtectClientInit(client) -{ - // Reset timer handle. - tSpawnProtect[client] = INVALID_HANDLE; -} - -/** - * Player is spawning into the game. - * - * @param client The client index. - */ -SpawnProtectPlayerSpawn(client) -{ - // Disable spawn protection on client. - pSpawnProtect[client] = false; - - // If zombie hasn't spawned, then stop. - if (!zombieSpawned) - { - return; - } - - // If protect cvar is invalid or 0, then stop. - new protect = GetConVarInt(gCvars[CVAR_PROTECT]); - if (protect <= 0) - { - return; - } - - // Get respawn team. - decl String:respawnteam[32]; - 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 - // 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])) - { - // Set spawn protect flag on client. - pSpawnProtect[client] = true; - - // Set improved attributes - // (Move to cvar?) - SetPlayerAlpha(client, 0); - SetPlayerSpeed(client, 600.0); - - // Set time left to zr_protect's value. - pSpawnProtectTime[client] = protect; - - // Tell client they are being protected. - ZR_PrintToChat(client, "Spawn protection begin", protect); - - // Send time left in a hud message. - ZR_HudHint(client, "Spawn Protect", pSpawnProtectTime[client]); - - // If timer is currently running, kill it. - if (tSpawnProtect[client] != INVALID_HANDLE) - { - KillTimer(tSpawnProtect[client]); - } - - // Start repeating timer. - tSpawnProtect[client] = CreateTimer(1.0, SpawnProtectTimer, client, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT); - } -} - -/** - * Timer callback function, countdown for spawn protection. - * - * @param timer The timer handle. - * @param client The client index. - */ -public Action:SpawnProtectTimer(Handle:timer, any:client) -{ - // If client leaves, then stop timer. - if (!IsClientInGame(client)) - { - return Plugin_Stop; - } - - // If client has become a zombie, then stop timer. - if (!IsPlayerHuman(client)) - { - return Plugin_Stop; - } - - // Decrement time left. - pSpawnProtectTime[client]--; - - // Print time left to client. - ZR_HudHint(client, "Spawn Protect", pSpawnProtectTime[client]); - - // Time has expired. - if (pSpawnProtectTime[client] <= 0) - { - // Remove protect flag. - pSpawnProtect[client] = false; - - // Tell client spawn protection is over. - ZR_HudHint(client, "Spawn protection end"); - - // Fix attributes. - // TODO: Set class attributes. - SetPlayerAlpha(client, 255); - SetPlayerSpeed(client, 300.0); - - // Clear timer handle. - tSpawnProtect[client] = INVALID_HANDLE; - - // Stop timer. - return Plugin_Stop; - } - - // Allow timer to continue repeating. - return Plugin_Continue; +/* + * ============================================================================ + * + * Zombie:Reloaded + * + * File: spawnprotect.inc + * Description: Protects late-joining players from zombies for x seconds. + * + * ============================================================================ + */ + +/** + * Array for storing spawn protect timer handles per client. + */ +new Handle:tSpawnProtect[MAXPLAYERS + 1]; + +/** + * Array for flagging client to be protected. + */ +new bool:pSpawnProtect[MAXPLAYERS + 1]; + +/** + * Array for storing time left for spawn protection per client. + */ +new pSpawnProtectTime[MAXPLAYERS + 1]; + +/** + * Client is joining the server. + * + * @param client The client index. + */ +SpawnProtectClientInit(client) +{ + // Reset timer handle. + tSpawnProtect[client] = INVALID_HANDLE; +} + +/** + * Player is spawning into the game. + * + * @param client The client index. + */ +SpawnProtectPlayerSpawn(client) +{ + // Disable spawn protection on client. + pSpawnProtect[client] = false; + + // If zombie hasn't spawned, then stop. + if (!zombieSpawned) + { + return; + } + + // If protect cvar is invalid or 0, then stop. + new protect = GetConVarInt(gCvars[CVAR_PROTECT]); + if (protect <= 0) + { + return; + } + + // Get respawn team. + decl String:respawnteam[32]; + 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 + // 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])) + { + // Set spawn protect flag on client. + pSpawnProtect[client] = true; + + // Set improved attributes + // (Move to cvar?) + SetPlayerAlpha(client, 0); + SetPlayerSpeed(client, 600.0); + + // Set time left to zr_protect's value. + pSpawnProtectTime[client] = protect; + + // Tell client they are being protected. + ZR_PrintToChat(client, "Spawn protection begin", protect); + + // Send time left in a hud message. + ZR_HudHint(client, "Spawn Protect", pSpawnProtectTime[client]); + + // If timer is currently running, kill it. + if (tSpawnProtect[client] != INVALID_HANDLE) + { + KillTimer(tSpawnProtect[client]); + } + + // Start repeating timer. + tSpawnProtect[client] = CreateTimer(1.0, SpawnProtectTimer, client, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT); + } +} + +/** + * Timer callback function, countdown for spawn protection. + * + * @param timer The timer handle. + * @param client The client index. + */ +public Action:SpawnProtectTimer(Handle:timer, any:client) +{ + // If client leaves, then stop timer. + if (!IsClientInGame(client)) + { + return Plugin_Stop; + } + + // If client has become a zombie, then stop timer. + if (!IsPlayerHuman(client)) + { + return Plugin_Stop; + } + + // Decrement time left. + pSpawnProtectTime[client]--; + + // Print time left to client. + ZR_HudHint(client, "Spawn Protect", pSpawnProtectTime[client]); + + // Time has expired. + if (pSpawnProtectTime[client] <= 0) + { + // Remove protect flag. + pSpawnProtect[client] = false; + + // Tell client spawn protection is over. + ZR_HudHint(client, "Spawn protection end"); + + // Fix attributes. + // TODO: Set class attributes. + SetPlayerAlpha(client, 255); + SetPlayerSpeed(client, 300.0); + + // Clear timer handle. + tSpawnProtect[client] = INVALID_HANDLE; + + // Stop timer. + return Plugin_Stop; + } + + // Allow timer to continue repeating. + return Plugin_Continue; } \ No newline at end of file diff --git a/src/zr/translation.inc b/src/zr/translation.inc index 92181fe..b9a73f4 100644 --- a/src/zr/translation.inc +++ b/src/zr/translation.inc @@ -23,7 +23,7 @@ stock ZR_PrintToChat(client, any:...) { decl String:phrase[192]; - if (client) + if (ZRIsValidClient(client)) { SetGlobalTransTarget(client); @@ -204,11 +204,13 @@ stock ZR_PrintToAdminChat(String:message[]) { decl String:buffer[256]; 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); } } } \ No newline at end of file diff --git a/src/zr/zadmin.inc b/src/zr/zadmin.inc index f9c33a0..e3bbc06 100644 --- a/src/zr/zadmin.inc +++ b/src/zr/zadmin.inc @@ -11,7 +11,7 @@ new curMenuClass[MAXPLAYERS + 1]; bool:ZRAdminMenu(client) { - if (!IsClientAdmin(client)) + if (!ZRIsClientAdmin(client)) { ZR_PrintToChat(client, "Must be admin"); return false; @@ -417,7 +417,8 @@ public ZRInfectHandle(Handle:menu_infect, MenuAction:action, client, slot) ZRSpawnAll(client) { - for (new x = 1; x < maxclients; x++) + // x = client index. + for (new x = 1; x < MaxClients; x++) { if (IsClientInGame(x)) { diff --git a/src/zr/zhp.inc b/src/zr/zhp.inc index 5b5a40d..6601397 100644 --- a/src/zr/zhp.inc +++ b/src/zr/zhp.inc @@ -1,175 +1,175 @@ -/* - * ============================================================================ - * - * Zombie:Reloaded - * - * File: zhp.inc - * Description: Displays - * Author: Greyscale, Richard Helgeby - * - * ============================================================================ - */ - -/** - * Array for storing ZHP timer handles per client. - */ -new Handle:tZHP[MAXPLAYERS + 1]; - -/** - * Array for flagging client to display HP - */ -new bool:pZHP[MAXPLAYERS + 1]; - -/** - * Client is joining the server. - * - * @param client The client index. - */ -ZHPClientInit(client) -{ - // Get default client setting from cvar. - new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP_DEFAULT]); - - // Set flag to default value. - pZHP[client] = zhp; - - // Reset timer handle. - tZHP[client] = INVALID_HANDLE; -} - -/** - * Toggle ZHP on a client. - * - * @param client The client index. - */ -ZHPToggle(client) -{ - // If ZHP is disabled, then stop. - new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP]); - if (!zhp) - { - // Tell client feature is disabled. - ZR_PrintToChat(client, "Feature is disabled"); - - // Stop. - return; - } - - // If ZHP is enabled, then tell client it's being disabled. - if (pZHP[client]) - { - ZR_PrintToChat(client, "ZHP disable"); - } - // If ZHP is disabled, then tell client it's being enabled. - else - { - ZR_PrintToChat(client, "ZHP enable"); - - // Update HP display. - ZHPUpdateHUD(client); - } - - // Toggle ZHP flag. - pZHP[client] = !pZHP[client]; -} - -/** - * Player has been infected. - * - * @param client The client index. - */ -ZHPOnClientInfected(client) -{ - // If ZHP is disabled, then stop. - new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP]); - if (!zhp) - { - return; - } - - // Update HP display. - ZHPUpdateHUD(client); - - // If timer is currently running, kill it. - if (tZHP[client] != INVALID_HANDLE) - { - KillTimer(tZHP[client]); - } - - // Start repeating timer to update display. - tZHP[client] = CreateTimer(5.0, ZHPTimer, client, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT); -} - -/** - * Player has been hurt. - * - * @param client The client index. - */ -ZHPOnPlayerHurt(client) -{ - // Update HP display. - ZHPUpdateHUD(client); -} - -/** - * Zombie has gained health for infecting a player. - * - * @param client The client index. - */ -ZHPOnHealthInfectGain(client) -{ - // Update HP display. - ZHPUpdateHUD(client); -} - -/** - * Update HP display for a player. - * - * @param client The client index. - */ -ZHPUpdateHUD(client) -{ - // If ZHP is disabled, then stop. - new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP]); - if (!zhp) - { - return; - } - - // If player is a zombie, or has ZHP disabled, then stop. - if (!IsPlayerZombie(client) || !pZHP[client]) - { - return; - } - - // Get health, and if below 0 then set back to 0. (for display purposes) - new health = GetClientHealth(client); - if (health < 0) - { - health = 0; - } - - // Display HP - ZR_HudHint(client, "Display HP", health); -} - -/** - * Timer callback. Repetitively calls ZHPUpdateHUD() until stopped. - * - * @param timer The timer handle. - * @param client The client index. - */ -public Action:ZHPTimer(Handle:timer, any:client) -{ - // If client leaves, then stop timer. - if (!IsClientInGame(client)) - { - return Plugin_Stop; - } - - // Update HP display. - ZHPUpdateHUD(client); - - // Allow timer to continue. - return Plugin_Continue; +/* + * ============================================================================ + * + * Zombie:Reloaded + * + * File: zhp.inc + * Description: Displays HP to zombies. + * Author: Greyscale, Richard Helgeby + * + * ============================================================================ + */ + +/** + * Array for storing ZHP timer handles per client. + */ +new Handle:tZHP[MAXPLAYERS + 1]; + +/** + * Array for flagging client to display HP + */ +new bool:pZHP[MAXPLAYERS + 1]; + +/** + * Client is joining the server. + * + * @param client The client index. + */ +ZHPClientInit(client) +{ + // Get default client setting from cvar. + new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP_DEFAULT]); + + // Set flag to default value. + pZHP[client] = zhp; + + // Reset timer handle. + tZHP[client] = INVALID_HANDLE; +} + +/** + * Toggle ZHP on a client. + * + * @param client The client index. + */ +ZHPToggle(client) +{ + // If ZHP is disabled, then stop. + new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP]); + if (!zhp) + { + // Tell client feature is disabled. + ZR_PrintToChat(client, "Feature is disabled"); + + // Stop. + return; + } + + // If ZHP is enabled, then tell client it's being disabled. + if (pZHP[client]) + { + ZR_PrintToChat(client, "ZHP disable"); + } + // If ZHP is disabled, then tell client it's being enabled. + else + { + ZR_PrintToChat(client, "ZHP enable"); + + // Update HP display. + ZHPUpdateHUD(client); + } + + // Toggle ZHP flag. + pZHP[client] = !pZHP[client]; +} + +/** + * Player has been infected. + * + * @param client The client index. + */ +ZHPOnClientInfected(client) +{ + // If ZHP is disabled, then stop. + new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP]); + if (!zhp) + { + return; + } + + // Update HP display. + ZHPUpdateHUD(client); + + // If timer is currently running, kill it. + if (tZHP[client] != INVALID_HANDLE) + { + KillTimer(tZHP[client]); + } + + // Start repeating timer to update display. + tZHP[client] = CreateTimer(5.0, ZHPTimer, client, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT); +} + +/** + * Player has been hurt. + * + * @param client The client index. + */ +ZHPOnPlayerHurt(client) +{ + // Update HP display. + ZHPUpdateHUD(client); +} + +/** + * Zombie has gained health for infecting a player. + * + * @param client The client index. + */ +ZHPOnHealthInfectGain(client) +{ + // Update HP display. + ZHPUpdateHUD(client); +} + +/** + * Update HP display for a player. + * + * @param client The client index. + */ +ZHPUpdateHUD(client) +{ + // If ZHP is disabled, then stop. + new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP]); + if (!zhp) + { + return; + } + + // If player is a zombie, or has ZHP disabled, then stop. + if (!IsPlayerZombie(client) || !pZHP[client]) + { + return; + } + + // Get health, and if below 0 then set back to 0. (for display purposes) + new health = GetClientHealth(client); + if (health < 0) + { + health = 0; + } + + // Display HP + ZR_HudHint(client, "Display HP", health); +} + +/** + * Timer callback. Repetitively calls ZHPUpdateHUD() until stopped. + * + * @param timer The timer handle. + * @param client The client index. + */ +public Action:ZHPTimer(Handle:timer, any:client) +{ + // If client leaves, then stop timer. + if (!IsClientInGame(client)) + { + return Plugin_Stop; + } + + // Update HP display. + ZHPUpdateHUD(client); + + // Allow timer to continue. + return Plugin_Continue; } \ No newline at end of file diff --git a/src/zr/zombiereloaded.inc b/src/zr/zombiereloaded.inc index 8c5122c..1af1c1f 100644 --- a/src/zr/zombiereloaded.inc +++ b/src/zr/zombiereloaded.inc @@ -87,8 +87,6 @@ new Handle:ztele_startup_timer = INVALID_HANDLE; new Handle:ztele_countdown_timer[MAXPLAYERS + 1] = {INVALID_HANDLE, ...}; new Handle:ztele_cooldown_timer[MAXPLAYERS + 1] = {INVALID_HANDLE, ...}; -new maxclients; - new Handle:tRound = INVALID_HANDLE; new Handle:tInfect = INVALID_HANDLE; @@ -233,14 +231,22 @@ bool:IsPlayerInList(client) 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. * @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; } + // Client is not an admin. return false; }