diff --git a/src/zr/playerclasses/apply.inc b/src/zr/playerclasses/apply.inc index b683d99..1b405c7 100644 --- a/src/zr/playerclasses/apply.inc +++ b/src/zr/playerclasses/apply.inc @@ -381,7 +381,7 @@ bool:ClassApplyHealthRegen(client, classindex, cachetype = ZR_CLASS_CACHE_PLAYER if (interval > 0) { - ClassHealthRegenInitialize(client, interval, amount, max); + ClassHealthRegenInitClient(client, interval, amount, max); return true; } else diff --git a/src/zr/playerclasses/classevents.inc b/src/zr/playerclasses/classevents.inc index d741b65..e197cd3 100644 --- a/src/zr/playerclasses/classevents.inc +++ b/src/zr/playerclasses/classevents.inc @@ -57,6 +57,9 @@ ClassOnMapStart() { // Clear multipliers. ClassResetMultiplierCache(); + + // Prepare hp regeneration module. + ClassHealthRegenInit(); } /** diff --git a/src/zr/playerclasses/healthregen.inc b/src/zr/playerclasses/healthregen.inc index 40b8b86..cea3d96 100644 --- a/src/zr/playerclasses/healthregen.inc +++ b/src/zr/playerclasses/healthregen.inc @@ -27,15 +27,41 @@ new ClientHealthRegenAmount[MAXPLAYERS + 1]; new ClientHealthRegenMax[MAXPLAYERS + 1]; -new Handle:tHealthRegen[MAXPLAYERS + 1] = {INVALID_HANDLE, ...}; +new Handle:tHealthRegen[MAXPLAYERS + 1]; -ClassHealthRegenInitialize(client, Float:interval, amount, max) +/** + * 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) { ClientHealthRegenAmount[client] = amount; ClientHealthRegenMax[client] = max; ClassHealthRegenStart(client, interval); } +/** + * Starts HP regeneration on a client using current client settings. + * + * @param client The client index. + * @param interval Regeneration interval. + */ ClassHealthRegenStart(client, Float:interval) { // Stop timer if it already exist. @@ -45,6 +71,11 @@ ClassHealthRegenStart(client, Float:interval) tHealthRegen[client] = CreateTimer(interval, ClassHealthRegenTimer, client, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE); } +/** + * Stops HP regeneration on a client. + * + * @param client The client index. + */ ClassHealthRegenStop(client) { // Kill the timer if it exist. @@ -55,6 +86,9 @@ ClassHealthRegenStop(client) } } +/** + * Timer callback for HP regeneration. + */ public Action:ClassHealthRegenTimer(Handle:timer, any:client) { // Kill the timer if the player is dead or not in game.