2009-04-07 02:13:25 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
2009-07-05 08:49:23 +02:00
|
|
|
* Zombie:Reloaded
|
2009-04-07 02:13:25 +02:00
|
|
|
*
|
2009-06-12 05:51:26 +02:00
|
|
|
* File: healthregen.inc
|
|
|
|
* Type: Core
|
|
|
|
* Description: Functions for managing health regeneration on a client.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Greyscale, Richard Helgeby
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-04-07 02:13:25 +02:00
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
new ClientHealthRegenAmount[MAXPLAYERS + 1];
|
|
|
|
new ClientHealthRegenMax[MAXPLAYERS + 1];
|
2009-12-03 01:22:20 +01:00
|
|
|
new Handle:tHealthRegen[MAXPLAYERS + 1];
|
2009-04-07 02:13:25 +02:00
|
|
|
|
2009-12-03 01:22:20 +01:00
|
|
|
/**
|
|
|
|
* Resets all timer handles. (called from classevents)
|
|
|
|
*/
|
|
|
|
ClassHealthRegenInit()
|
|
|
|
{
|
|
|
|
for (new client = 0; client < MAXPLAYERS + 1; client++)
|
|
|
|
{
|
|
|
|
tHealthRegen[client] = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepares and starts HP regeneration on a client.
|
|
|
|
*
|
|
|
|
* @param client The client to apply HP regeneration on.
|
|
|
|
* @param interval Regeneration interval.
|
|
|
|
* @param amount HP amount per interval.
|
|
|
|
* @param max Regeneration limit. Don't give HP if player HP is above
|
|
|
|
* this value.
|
|
|
|
*/
|
|
|
|
ClassHealthRegenInitClient(client, Float:interval, amount, max)
|
2009-04-07 02:13:25 +02:00
|
|
|
{
|
|
|
|
ClientHealthRegenAmount[client] = amount;
|
|
|
|
ClientHealthRegenMax[client] = max;
|
|
|
|
ClassHealthRegenStart(client, interval);
|
|
|
|
}
|
|
|
|
|
2009-12-03 01:22:20 +01:00
|
|
|
/**
|
|
|
|
* Starts HP regeneration on a client using current client settings.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param interval Regeneration interval.
|
|
|
|
*/
|
2009-04-07 02:13:25 +02:00
|
|
|
ClassHealthRegenStart(client, Float:interval)
|
|
|
|
{
|
2009-12-02 23:35:20 +01:00
|
|
|
// Stop timer if it already exist.
|
|
|
|
ClassHealthRegenStop(client);
|
2009-04-07 02:13:25 +02:00
|
|
|
|
2009-12-02 23:35:20 +01:00
|
|
|
// Create new timer.
|
2009-10-31 03:39:00 +01:00
|
|
|
tHealthRegen[client] = CreateTimer(interval, ClassHealthRegenTimer, client, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
|
2009-04-07 02:13:25 +02:00
|
|
|
}
|
|
|
|
|
2009-12-03 01:22:20 +01:00
|
|
|
/**
|
|
|
|
* Stops HP regeneration on a client.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
2009-04-07 02:13:25 +02:00
|
|
|
ClassHealthRegenStop(client)
|
|
|
|
{
|
|
|
|
// Kill the timer if it exist.
|
|
|
|
if (tHealthRegen[client] != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
KillTimer(tHealthRegen[client]);
|
|
|
|
tHealthRegen[client] = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-03 01:22:20 +01:00
|
|
|
/**
|
|
|
|
* Timer callback for HP regeneration.
|
|
|
|
*/
|
2009-04-07 02:13:25 +02:00
|
|
|
public Action:ClassHealthRegenTimer(Handle:timer, any:client)
|
|
|
|
{
|
2009-09-27 23:45:17 +02:00
|
|
|
// Kill the timer if the player is dead or not in game.
|
|
|
|
if (!IsClientConnected(client) || !IsClientInGame(client) || !IsPlayerAlive(client))
|
2009-04-07 02:13:25 +02:00
|
|
|
{
|
|
|
|
tHealthRegen[client] = INVALID_HANDLE;
|
|
|
|
return Plugin_Stop;
|
|
|
|
}
|
|
|
|
|
|
|
|
new health = GetClientHealth(client);
|
|
|
|
health += ClientHealthRegenAmount[client];
|
|
|
|
|
|
|
|
// Check if the health points is below the limit.
|
|
|
|
if (health < ClientHealthRegenMax[client])
|
|
|
|
{
|
|
|
|
// Increase health.
|
|
|
|
SetEntityHealth(client, health);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Plugin_Continue;
|
2009-05-01 11:22:45 +02:00
|
|
|
}
|