Moved ZHP to its own module, plugin now uses InfectPlayer.

This commit is contained in:
Greyscale 2009-04-16 01:18:08 +02:00
parent 37dfea2f8c
commit 75e654992c
10 changed files with 240 additions and 308 deletions

View File

@ -1,7 +1,7 @@
"Phrases"
{
// ===========================
// Chat Messages
// General
// ===========================
"Round objective"
@ -77,19 +77,6 @@
"en" "Switched zombie class to \"{1}\""
"ru" "Класс зомби переключен на \"{1}\""
}
"Spawn protection begin"
{
"#format" "{1:d}"
"en" "Zombies are present, you have {1} seconds to find a safe place before you lose immunity."
"ru" "Зомби на свободе, у вас {1} секунд, чтобы найти безопасное место, пока не потеряли иммунитет."
}
"Spawn protection end"
{
"en" "You are now susceptible to zombie infection."
"ru" "Теперь вы восприимчивы к зомби инфекции."
}
"!ztele amount"
{
@ -152,18 +139,6 @@
"en" "Teleport successful."
}
"!zhp enabled"
{
"en" "HP display enabled, your real HP will be displayed persistently after infection."
"ru" "Отображение здоровья включено, ваше реальное здоровье будет показано после инфицирования."
}
"!zhp disabled"
{
"en" "HP display disabled."
"ru" "Отображение здоровья включено."
}
// ===========================
// Generic
// ===========================
@ -317,6 +292,60 @@
"en" "Unrestrict All Group Weapons"
}
// ===========================
// Spawn Protect
// ===========================
// General
"Spawn protection begin"
{
"#format" "{1:d}"
"en" "Zombies are present, you have {1} seconds to find a safe place before you lose immunity."
"ru" "Зомби на свободе, у вас {1} секунд, чтобы найти безопасное место, пока не потеряли иммунитет."
}
"Spawn protection end"
{
"en" "You are now susceptible to zombie infection."
"ru" "Теперь вы восприимчивы к зомби инфекции."
}
// HUD
"Spawn Protect"
{
"#format" "{1:d}"
"en" "Zombie protection ends in: {1} seconds."
}
// ===========================
// ZHP
// ===========================
// General
"ZHP enable"
{
"en" "HP display enabled, your real HP will be displayed after infection."
}
"ZHP disable"
{
"en" "HP display disabled."
"ru" "Отображение здоровья включено."
}
// HUD
"Display HP"
{
"#format" "{1:d}"
"en" "HP: {1}"
"ru" "Здоровье: {1}"
}
"Suicide text"
{
"en" "Nice try n00b!"
@ -403,36 +432,36 @@
"en" "Rebuy"
"ru" "Купить снова"
}
// ===========================
// Class menu
// ===========================
"!zclass title"
{
"en" "Class Selection:"
}
"!zclass zombie"
{
"en" "Select Zombie Class"
}
"!zclass human"
{
"en" "Select Human Class"
}
"!zclass admin"
{
"en" "Select Admin Class"
}
"!zclass admin mode enabled"
{
"en" "Admin mode is enabled!"
}
"!zclass admin mode toggle"
{
"en" "Toggle Admin Mode"
@ -589,23 +618,6 @@
"en" "Toggle Logging Flags:"
}
// ===========================
// HudHints
// ===========================
"Display HP"
{
"#format" "{1:d}"
"en" "HP: {1}"
"ru" "Здоровье: {1}"
}
"Spawn Protect"
{
"#format" "{1:d}"
"en" "Zombie protection ends in: {1} seconds."
}
// ===========================
// Server Messages
// ===========================

View File

@ -45,6 +45,9 @@
// Spawn protect
#include "zr/spawnprotect"
// ZHP
#include "zr/zhp"
#include "zr/zadmin"
#include "zr/damagecontrol"
#include "zr/commands"
@ -173,12 +176,12 @@ public OnClientPutInServer(client)
bZVision[client] = !IsFakeClient(client);
new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP_DEFAULT]);
dispHP[client] = zhp;
// Forward event to modules.
WeaponsClientInit(client);
ClassClientInit(client);
WeaponsClientInit(client);
SpawnProtectClientInit(client);
ZHPClientInit(client);
if (!IsFakeClient(client)) AmbienceStart(client);
ClientHookAttack(client);
@ -199,8 +202,8 @@ public OnClientDisconnect(client)
PlayerLeft(client);
// Forward event to modules.
WeaponsOnClientDisconnect(client);
ClassOnClientDisconnect(client);
WeaponsOnClientDisconnect(client);
ZTeleResetClient(client);
AmbienceStop(client);

View File

@ -70,7 +70,7 @@ public Action:Command_Infect(client, argc)
for (new x = 0; x < tcount; x++)
{
Zombify(targets[x], 0);
InfectPlayer(targets[x]);
if (LogFlagCheck(LOG_GAME_EVENTS, LOG_MODULE_COMMANDS))
{
GetClientName(targets[x], target_name, sizeof(target_name));

View File

@ -232,7 +232,7 @@ public Action:PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
// Check if spawn protection is disabled and the weapon is a knife.
if (!pProtect[index] && StrEqual(weapon, "knife"))
{
Zombify(index, attacker);
InfectPlayer(index, attacker);
}
}
}
@ -265,7 +265,7 @@ public Action:PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
// Forward event to modules.
ClassAlphaUpdate(index);
UpdateHPDisplay(index);
ZHPOnPlayerHurt(index);
}
public Action:PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
@ -300,7 +300,8 @@ public Action:PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
SetEntityHealth(attacker, health + healthgain);
UpdateHPDisplay(attacker);
// Forward event to modules.
ZHPOnHealthInfectGain(attacker);
}
}
else

View File

@ -99,7 +99,10 @@ public MainMenuHandle(Handle:menu_main, MenuAction:action, client, slot)
}
case 6:
{
ZHP(client);
// Toggle ZHP.
ZHPToggle(client);
// Resend menu.
MainMenu(client);
}
}

View File

@ -65,7 +65,8 @@ public Action:SayCommand(client, argc)
else if (StrEqual(args, "!zhp", false))
{
ZHP(client);
// Toggle ZHP.
ZHPToggle(client);
}
else if (StrContains(args, "teleport", false) != -1
|| StrContains(args, "stuck", false) != -1
@ -165,27 +166,4 @@ ZSpawn(client)
RespawnPlayer(client);
AddPlayerToList(client);
}
ZHP(client)
{
new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP]);
if (!zhp)
{
ZR_PrintToChat(client, "Feature is disabled");
return;
}
if (dispHP[client])
{
ZR_PrintToChat(client, "!zhp disabled");
}
else
{
ZR_PrintToChat(client, "!zhp enabled");
UpdateHPDisplay(client);
}
dispHP[client] = !dispHP[client];
}

View File

@ -1,145 +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)
{
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;
}

View File

@ -397,7 +397,7 @@ public ZRInfectHandle(Handle:menu_infect, MenuAction:action, client, slot)
{
decl String:name[64];
GetClientName(target, name, sizeof(name));
Zombify(target, 0);
InfectPlayer(target);
ShowActivity2(client, "[ZR] ", "Infected %s", name);
ZRInfectMenu(client);
}

View File

@ -138,7 +138,7 @@ public Action:MotherZombie(Handle:timer)
randclient = RandomPlayerFromList();
} while (!IsPlayerAlive(randclient) || gBlockMotherInfect[randclient]);
Zombify_Mother(randclient);
InfectPlayer(randclient, _, true);
}
else
{
@ -151,7 +151,7 @@ public Action:MotherZombie(Handle:timer)
randclient = RandomPlayerFromList();
} while (IsPlayerZombie(randclient) || !IsPlayerAlive(randclient) || gBlockMotherInfect[randclient]);
Zombify_Mother(randclient);
InfectPlayer(randclient, _, true);
}
}
@ -160,7 +160,7 @@ public Action:MotherZombie(Handle:timer)
zombieSpawned = true;
}
Zombify_Mother(client)
/*Zombify_Mother(client)
{
gZombie[client] = true;
motherZombie[client] = true;
@ -193,21 +193,7 @@ Zombify_Mother(client)
}
tHandles[client][TMOAN] = CreateTimer(interval, ZombieMoanTimer, client, TIMER_REPEAT);
}
if (tHandles[client][TZHP] != INVALID_HANDLE)
{
KillTimer(tHandles[client][TZHP]);
tHandles[client][TZHP] = INVALID_HANDLE;
}
new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP]);
if (zhp)
{
UpdateHPDisplay(client);
tHandles[client][TZHP] = CreateTimer(5.0, ZHPTimer, client, TIMER_REPEAT);
}
}
}*/
/**
* Zombifies a player. Execute events, sets attributes and flags that indicate
@ -217,7 +203,7 @@ Zombify_Mother(client)
* @param attacker Optional. The attacker who did the infect.
* @param motherinfect Optional. Indicates a mother zombie infect.
*/
Zombify(client, attacker = -1, bool:motherinfect = false)
InfectPlayer(client, attacker = -1, bool:motherinfect = false)
{
// Check if the attacker was specified.
if (attacker > 0)
@ -262,23 +248,9 @@ Zombify(client, attacker = -1, bool:motherinfect = false)
tHandles[client][TMOAN] = CreateTimer(interval, ZombieMoanTimer, client, TIMER_REPEAT);
}
// Kill HP display timer.
if (tHandles[client][TZHP] != INVALID_HANDLE)
{
KillTimer(tHandles[client][TZHP]);
tHandles[client][TZHP] = INVALID_HANDLE;
}
// Start HP display if enabled.
new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP]);
if (zhp)
{
UpdateHPDisplay(client);
tHandles[client][TZHP] = CreateTimer(5.0, ZHPTimer, client, TIMER_REPEAT);
}
// Forward event to modules.
ClassOnClientInfected(client);
ClassOnClientInfected(client, motherinfect);
ZHPOnClientInfected(client);
AbortTeleport(client);
// Apply effects.
@ -425,7 +397,7 @@ PlayerLeft(client)
}
new randclient = GetArrayCell(aClients, GetRandomInt(0, size-1));
Zombify_Mother(randclient);
InfectPlayer(randclient, _, true);
ZR_PrintToChat(randclient, "Zombie replacement");
@ -582,42 +554,6 @@ public Action:ZombieMoanTimer(Handle:timer, any:index)
return Plugin_Continue;
}
UpdateHPDisplay(client)
{
new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP]);
if (!zhp)
{
return;
}
if (!IsPlayerZombie(client) || !dispHP[client])
{
return;
}
new health = GetClientHealth(client);
if (health < 0)
{
health = 0;
}
ZR_HudHint(client, "Display HP", health);
}
public Action:ZHPTimer(Handle:timer, any:index)
{
if (!IsClientInGame(index))
{
tHandles[index][TZHP] = INVALID_HANDLE;
return Plugin_Stop;
}
UpdateHPDisplay(index);
return Plugin_Continue;
}
RespawnPlayer(client)
{
if (!IsClientInGame(client))
@ -637,13 +573,13 @@ RespawnPlayer(client)
if (StrEqual(team, "zombie", false))
{
Zombify(client, 0);
InfectPlayer(client);
return;
}
if (GetConVarBool(gCvars[CVAR_SUICIDE_WORLD_DAMAGE]) && gKilledByWorld[client])
{
Zombify(client, 0);
InfectPlayer(client);
gKilledByWorld[client] = false;
}
}

View File

@ -73,7 +73,6 @@ new bool:gBlockMotherInfect[MAXPLAYERS + 1];
new bool:bZVision[MAXPLAYERS + 1];
//new bool:bZVisionOn[MAXPLAYERS + 1];
//new String:ZVisionOverlay[MAXPLAYERS + 1][PLATFORM_MAX_PATH];
new bool:dispHP[MAXPLAYERS + 1];
new bool:pProtect[MAXPLAYERS + 1];
new bool:gKilledByWorld[MAXPLAYERS + 1] = {false, ...};
@ -95,14 +94,13 @@ new Handle:tInfect = INVALID_HANDLE;
new Handle:pList = INVALID_HANDLE;
#define MAXTIMERS 6
#define MAXTIMERS 5
#define TMOAN 0
#define TREGEN 1
#define TTELE 2
#define TZHP 3
#define TRESPAWN 4
#define TZVISION 5
#define TRESPAWN 3
#define TZVISION 4
new Handle:tHandles[MAXPLAYERS + 1][MAXTIMERS];