Finished functions for applying class attributes.
This commit is contained in:
		| @@ -6,6 +6,8 @@ | |||||||
|  * ====================  |  * ====================  | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
|  | // TODO: Move skybox and lightning functions into this file. | ||||||
|  |  | ||||||
| new bool:AmbienceLoaded = false; | new bool:AmbienceLoaded = false; | ||||||
| new String:AmbienceSound[64]; | new String:AmbienceSound[64]; | ||||||
| new Float:AmbienceVolume; | new Float:AmbienceVolume; | ||||||
|   | |||||||
| @@ -32,6 +32,11 @@ bool:ClassApplyAttributes(client, bool:improved = false) | |||||||
|     ClassApplyModel(client, classindex); |     ClassApplyModel(client, classindex); | ||||||
|     ClassApplyAlpha(client, classindex); |     ClassApplyAlpha(client, classindex); | ||||||
|     ClassApplyOverlay(client, classindex); |     ClassApplyOverlay(client, classindex); | ||||||
|  |     ClassApplyNightVision(client, classindex); | ||||||
|  |     ClassApplyFOV(client, classindex); | ||||||
|  |     ClassApplyHealth(client, classindex, improved); | ||||||
|  |     ClassApplyHealthRegen(client, classindex); | ||||||
|  |     ClassApplySpeed(client, classindex); | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -145,3 +150,179 @@ bool:ClassApplyOverlay(client, classindex, cachetype = ZR_CLASS_CACHE_PLAYER) | |||||||
|     ClassOverlayInitialize(client, overlay); |     ClassOverlayInitialize(client, overlay); | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Gives night vision to a player. | ||||||
|  |  * | ||||||
|  |  * @param client        The client index. | ||||||
|  |  * @param classindex    The class to read from. | ||||||
|  |  * @param cachetype     Optional. Specifies what class cache to read from. | ||||||
|  |  *                      Options: | ||||||
|  |  *                      ZR_CLASS_CACHE_ORIGINAL - Unchanced class data. | ||||||
|  |  *                      ZR_CLASS_CACHE_MODIFIED - Changed/newest class data. | ||||||
|  |  *                      ZR_CLASS_CACHE_PLAYER (default) - Player cache. | ||||||
|  |  * @return  True on success, false otherwise. | ||||||
|  |  */ | ||||||
|  | bool:ClassApplyNightVision(client, classindex, cachetype = ZR_CLASS_CACHE_PLAYER) | ||||||
|  | { | ||||||
|  |     new bool:nvgs; | ||||||
|  |      | ||||||
|  |     // Get the night vision setting from the specified cache. | ||||||
|  |     if (cachetype == ZR_CLASS_CACHE_PLAYER) | ||||||
|  |     { | ||||||
|  |         nvgs = ClassGetNvgs(client, cachetype); | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         nvgs = ClassGetNvgs(classindex, cachetype); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     NightVision(client, nvgs); | ||||||
|  |      | ||||||
|  |     // Turn on night vision if applied. | ||||||
|  |     if (nvgs) | ||||||
|  |     { | ||||||
|  |         NightVisionOn(client, nvgs); | ||||||
|  |     } | ||||||
|  |     return true; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Sets the field of view setting on a player. | ||||||
|  |  * | ||||||
|  |  * @param client        The client index. | ||||||
|  |  * @param classindex    The class to read from. | ||||||
|  |  * @param cachetype     Optional. Specifies what class cache to read from. | ||||||
|  |  *                      Options: | ||||||
|  |  *                      ZR_CLASS_CACHE_ORIGINAL - Unchanced class data. | ||||||
|  |  *                      ZR_CLASS_CACHE_MODIFIED - Changed/newest class data. | ||||||
|  |  *                      ZR_CLASS_CACHE_PLAYER (default) - Player cache. | ||||||
|  |  * @return  True on success, false otherwise. | ||||||
|  |  */ | ||||||
|  | bool:ClassApplyFOV(client, classindex, cachetype = ZR_CLASS_CACHE_PLAYER) | ||||||
|  | { | ||||||
|  |     new fov; | ||||||
|  |      | ||||||
|  |     // Get the field of view setting from the specified cache. | ||||||
|  |     if (cachetype == ZR_CLASS_CACHE_PLAYER) | ||||||
|  |     { | ||||||
|  |         fov = ClassGetFOV(client, cachetype); | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         fov = ClassGetFOV(classindex, cachetype); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     SetPlayerFOV(client, fov); | ||||||
|  |     return true; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Gives health points on a player. | ||||||
|  |  * | ||||||
|  |  * @param client        The client index. | ||||||
|  |  * @param classindex    The class to read from. | ||||||
|  |  * @param boost         Double health boost. Default: false | ||||||
|  |  * @param cachetype     Optional. Specifies what class cache to read from. | ||||||
|  |  *                      Options: | ||||||
|  |  *                      ZR_CLASS_CACHE_ORIGINAL - Unchanced class data. | ||||||
|  |  *                      ZR_CLASS_CACHE_MODIFIED - Changed/newest class data. | ||||||
|  |  *                      ZR_CLASS_CACHE_PLAYER (default) - Player cache. | ||||||
|  |  * @return  True on success, false otherwise. | ||||||
|  |  */ | ||||||
|  | bool:ClassApplyHealth(client, classindex, bool:boost = false, cachetype = ZR_CLASS_CACHE_PLAYER) | ||||||
|  | { | ||||||
|  |     new health; | ||||||
|  |      | ||||||
|  |     // Get the health points from the specified cache. | ||||||
|  |     if (cachetype == ZR_CLASS_CACHE_PLAYER) | ||||||
|  |     { | ||||||
|  |         health = ClassGetHealth(client, cachetype); | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         health = ClassGetHealth(classindex, cachetype); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     if (boost) | ||||||
|  |     { | ||||||
|  |         health *= 2; | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     SetEntityHealth(client, health); | ||||||
|  |     return true; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Applies health regeneration on a player if enabled. | ||||||
|  |  * | ||||||
|  |  * @param client        The client index. | ||||||
|  |  * @param classindex    The class to read from. | ||||||
|  |  * @param boost         Double health boost. Default: false | ||||||
|  |  * @param cachetype     Optional. Specifies what class cache to read from. | ||||||
|  |  *                      Options: | ||||||
|  |  *                      ZR_CLASS_CACHE_ORIGINAL - Unchanced class data. | ||||||
|  |  *                      ZR_CLASS_CACHE_MODIFIED - Changed/newest class data. | ||||||
|  |  *                      ZR_CLASS_CACHE_PLAYER (default) - Player cache. | ||||||
|  |  * @return  True if applied, false otherwise. | ||||||
|  |  */ | ||||||
|  | bool:ClassApplyHealthRegen(client, classindex, cachetype = ZR_CLASS_CACHE_PLAYER) | ||||||
|  | { | ||||||
|  |     new Float:interval; | ||||||
|  |     new amount; | ||||||
|  |     new max; | ||||||
|  |      | ||||||
|  |     // Get the health regeneration info from the specified cache. | ||||||
|  |     if (cachetype == ZR_CLASS_CACHE_PLAYER) | ||||||
|  |     { | ||||||
|  |         interval = ClassGetHealthRegenInterval(client, cachetype); | ||||||
|  |         amount = ClassGetHealthRegenAmount(client, cachetype); | ||||||
|  |         max = ClassGetHealth(client, cachetype); | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         interval = ClassGetHealthRegenInterval(classindex, cachetype); | ||||||
|  |         amount = ClassGetHealthRegenAmount(classindex, cachetype); | ||||||
|  |         max = ClassGetHealth(classindex, cachetype); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     if (interval > 0) | ||||||
|  |     { | ||||||
|  |         ClassHealthRegenInitialize(client, interval, amount, max); | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Sets the players speed. | ||||||
|  |  * | ||||||
|  |  * @param client        The client index. | ||||||
|  |  * @param classindex    The class to read from. | ||||||
|  |  * @param cachetype     Optional. Specifies what class cache to read from. | ||||||
|  |  *                      Options: | ||||||
|  |  *                      ZR_CLASS_CACHE_ORIGINAL - Unchanced class data. | ||||||
|  |  *                      ZR_CLASS_CACHE_MODIFIED - Changed/newest class data. | ||||||
|  |  *                      ZR_CLASS_CACHE_PLAYER (default) - Player cache. | ||||||
|  |  * @return  True on success, false otherwise. | ||||||
|  |  */ | ||||||
|  | bool:ClassApplySpeed(client, classindex, cachetype = ZR_CLASS_CACHE_PLAYER) | ||||||
|  | { | ||||||
|  |     new speed; | ||||||
|  |      | ||||||
|  |     // Get the health points from the specified cache. | ||||||
|  |     if (cachetype == ZR_CLASS_CACHE_PLAYER) | ||||||
|  |     { | ||||||
|  |         speed = ClassGetSpeed(client, cachetype); | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         speed = ClassGetSpeed(classindex, cachetype); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     SetPlayerSpeed(client, speed); | ||||||
|  |     return true; | ||||||
|  | } | ||||||
|   | |||||||
| @@ -384,7 +384,7 @@ ClassGetOverlayPath(index, String:buffer[], maxlen, cachetype = ZR_CLASS_CACHE_P | |||||||
|  *                  is used, index will be used as a client index. |  *                  is used, index will be used as a client index. | ||||||
|  * @return  The night vision setting from the specified class. False on error. |  * @return  The night vision setting from the specified class. False on error. | ||||||
|  */ |  */ | ||||||
| bool:ClassGetNVGs(index, cachetype = ZR_CLASS_CACHE_PLAYER) | bool:ClassGetNvgs(index, cachetype = ZR_CLASS_CACHE_PLAYER) | ||||||
| { | { | ||||||
|     switch (cachetype) |     switch (cachetype) | ||||||
|     { |     { | ||||||
|   | |||||||
							
								
								
									
										66
									
								
								src/zr/playerclasses/healthregen.inc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								src/zr/playerclasses/healthregen.inc
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,66 @@ | |||||||
|  | /* | ||||||
|  |  * ============================================================================ | ||||||
|  |  * | ||||||
|  |  *   Zombie:Reloaded | ||||||
|  |  * | ||||||
|  |  *   File:        healthregen.inc | ||||||
|  |  *   Description: Functions for managing health regeneration on a client. | ||||||
|  |  *   Author:      Richard Helgeby | ||||||
|  |  * | ||||||
|  |  * ============================================================================ | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | new ClientHealthRegenAmount[MAXPLAYERS + 1]; | ||||||
|  | new ClientHealthRegenMax[MAXPLAYERS + 1]; | ||||||
|  | new Handle:tHealthRegen[MAXPLAYERS + 1] = {INVALID_HANDLE, ...}; | ||||||
|  |  | ||||||
|  | ClassHealthRegenInitialize(client, Float:interval, amount, max) | ||||||
|  | { | ||||||
|  |     ClientHealthRegenAmount[client] = amount; | ||||||
|  |     ClientHealthRegenMax[client] = max; | ||||||
|  |     ClassHealthRegenStart(client, interval); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | ClassHealthRegenStart(client, Float:interval) | ||||||
|  | { | ||||||
|  |     // Kill the timer if it exist. | ||||||
|  |     if (tHealthRegen[client] != INVALID_HANDLE) | ||||||
|  |     { | ||||||
|  |         KillTimer(tHealthRegen[client]); | ||||||
|  |         tHealthRegen[client] = INVALID_HANDLE; | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     tHealthRegen[client] = CreateTimer(interval, ClassHealthRegenTimer, client, TIMER_REPEAT); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | ClassHealthRegenStop(client) | ||||||
|  | { | ||||||
|  |     // Kill the timer if it exist. | ||||||
|  |     if (tHealthRegen[client] != INVALID_HANDLE) | ||||||
|  |     { | ||||||
|  |         KillTimer(tHealthRegen[client]); | ||||||
|  |         tHealthRegen[client] = INVALID_HANDLE; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | public Action:ClassHealthRegenTimer(Handle:timer, any:client) | ||||||
|  | { | ||||||
|  |     // Kill the timer if the player is dead. | ||||||
|  |     if (!IsPlayerAlive(client)) | ||||||
|  |     { | ||||||
|  |         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; | ||||||
|  | } | ||||||
| @@ -208,6 +208,7 @@ new ClassActive[MAXPLAYERS + 1][ZR_CLASS_TEAMCOUNT - 1]; | |||||||
| #include "zr/playerclasses/attributes" | #include "zr/playerclasses/attributes" | ||||||
| #include "zr/playerclasses/apply" | #include "zr/playerclasses/apply" | ||||||
| #include "zr/playerclasses/clientoverlays" | #include "zr/playerclasses/clientoverlays" | ||||||
|  | #include "zr/playerclasses/healthregen" | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Loads class attributes from playerclasses.txt into the ClassData array. If |  * Loads class attributes from playerclasses.txt into the ClassData array. If | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user