2009-04-16 03:57:46 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
|
|
|
* 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.
|
2009-04-20 02:56:26 +02:00
|
|
|
new bool:zhp = GetConVarBool(g_hCvarsList[CVAR_ZHP_DEFAULT]);
|
2009-04-16 03:57:46 +02:00
|
|
|
|
|
|
|
// Set flag to default value.
|
|
|
|
pZHP[client] = zhp;
|
|
|
|
|
|
|
|
// Reset timer handle.
|
|
|
|
tZHP[client] = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
2009-04-16 05:30:26 +02:00
|
|
|
/**
|
|
|
|
* Client is spawning into the game.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
ZHPOnClientSpawn(client)
|
|
|
|
{
|
|
|
|
// If timer is running, kill it.
|
|
|
|
if (tZHP[client] != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
KillTimer(tZHP[client]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset timer handle.
|
|
|
|
tZHP[client] = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client has been killed.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
ZHPOnClientDeath(client)
|
|
|
|
{
|
|
|
|
// If timer is running, kill it.
|
|
|
|
if (tZHP[client] != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
KillTimer(tZHP[client]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset timer handle.
|
|
|
|
tZHP[client] = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
2009-04-16 03:57:46 +02:00
|
|
|
/**
|
|
|
|
* Player has been infected.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
ZHPOnClientInfected(client)
|
|
|
|
{
|
|
|
|
// If ZHP is disabled, then stop.
|
2009-04-20 02:56:26 +02:00
|
|
|
new bool:zhp = GetConVarBool(g_hCvarsList[CVAR_ZHP]);
|
2009-04-16 03:57:46 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-04-17 10:20:04 +02:00
|
|
|
* Client has been hurt.
|
2009-04-16 03:57:46 +02:00
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
2009-04-17 10:20:04 +02:00
|
|
|
ZHPOnClientHurt(client)
|
2009-04-16 03:57:46 +02:00
|
|
|
{
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2009-04-17 10:20:04 +02:00
|
|
|
/**
|
|
|
|
* Toggle ZHP on a client.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
ZHPToggle(client)
|
|
|
|
{
|
|
|
|
// If ZHP is disabled, then stop.
|
2009-04-20 02:56:26 +02:00
|
|
|
new bool:zhp = GetConVarBool(g_hCvarsList[CVAR_ZHP]);
|
2009-04-17 10:20:04 +02:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2009-04-16 03:57:46 +02:00
|
|
|
/**
|
|
|
|
* Update HP display for a player.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
ZHPUpdateHUD(client)
|
|
|
|
{
|
|
|
|
// If ZHP is disabled, then stop.
|
2009-04-20 02:56:26 +02:00
|
|
|
new bool:zhp = GetConVarBool(g_hCvarsList[CVAR_ZHP]);
|
2009-04-16 03:57:46 +02:00
|
|
|
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;
|
2009-04-16 01:21:09 +02:00
|
|
|
}
|