From fd92c9e112a9785fcf7bc8804976f2eb1006e8ed Mon Sep 17 00:00:00 2001 From: nosoop Date: Wed, 1 Sep 2021 02:47:52 -0700 Subject: [PATCH] Add GetEntityMaxHealth, change GetPlayerMaxHealth to GetPlayerMaxHealthBoost GetEntityMaxHealth returns the base max health of an entity. GetPlayerMaxHealthBoost (renamed from GetPlayerMaxHealth) returns the maximum allowed overheal of a player depending on various factors. See #1. --- gamedata/tf2.utils.nosoop.txt | 5 +++++ scripting/include/tf2utils.inc | 20 ++++++++++++++++++-- scripting/tf2utils.sp | 26 +++++++++++++++++++++++--- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/gamedata/tf2.utils.nosoop.txt b/gamedata/tf2.utils.nosoop.txt index 16d5fb4..621ad98 100644 --- a/gamedata/tf2.utils.nosoop.txt +++ b/gamedata/tf2.utils.nosoop.txt @@ -30,6 +30,11 @@ "windows" "327" "linux" "333" } + "CBaseEntity::GetMaxHealth()" + { + "windows" "117" + "linux" "118" + } "CBaseEntity::IsBaseCombatWeapon()" { "windows" "86" diff --git a/scripting/include/tf2utils.inc b/scripting/include/tf2utils.inc index 47e9fc8..c3a229e 100644 --- a/scripting/include/tf2utils.inc +++ b/scripting/include/tf2utils.inc @@ -43,9 +43,18 @@ native int TF2Util_GetPlayerMaxAmmo(int client, int iAmmoIndex, TFClassType playerClass = TFClass_Unknown); /** - * Returns the current maximum health of the player. + * Returns the current maximum allowed health of an entity. */ -native int TF2Util_GetPlayerMaxHealth(int client, bool bIgnoreAttributes = false, +native int TF2Util_GetEntityMaxHealth(int entity); + +/** + * Returns the maximum allowed overhealed health of a player, taking into account the amount + * it can gain through overhealing by mediguns. + * + * @param bIgnoreAttributes + * @param bIgnoreOverheal Ignores excessive overheal. + */ +native int TF2Util_GetPlayerMaxHealthBoost(int client, bool bIgnoreAttributes = false, bool bIgnoreOverheal = false); /** @@ -199,6 +208,13 @@ native void TF2Util_UpdatePlayerSpeed(int client, bool immediate = false); native bool TF2Util_IsPointInRespawnRoom(const float[3] position, int entity = INVALID_ENT_REFERENCE, bool bRestrictToSameTeam = false); +/** + * Returns the current maximum health of the player. + */ +#pragma deprecated Misnamed; use TF2Util_GetEntityMaxHealth or TF2Util_GetPlayerMaxHealthBoost. +native int TF2Util_GetPlayerMaxHealth(int client, bool bIgnoreAttributes = false, + bool bIgnoreOverheal = false); + // compile-time compatibility shim for tf2wearables natives #if defined USE_TF2WEARABLE_FUNCTION_SHIMS #define TF2_GetPlayerLoadoutSlot TF2Util_GetPlayerLoadoutEntity diff --git a/scripting/tf2utils.sp b/scripting/tf2utils.sp index 1842d2d..79beca7 100644 --- a/scripting/tf2utils.sp +++ b/scripting/tf2utils.sp @@ -11,7 +11,7 @@ #include -#define PLUGIN_VERSION "0.12.0" +#define PLUGIN_VERSION "0.13.0" public Plugin myinfo = { name = "TF2 Utils", author = "nosoop", @@ -28,6 +28,7 @@ Handle g_SDKCallPlayerTakeHealth; Handle g_SDKCallPlayerGetShootPosition; Handle g_SDKCallPlayerGetEntityForLoadoutSlot; +Handle g_SDKCallEntityGetMaxHealth; Handle g_SDKCallPlayerSharedGetMaxHealth; Handle g_SDKCallIsEntityWeapon; @@ -57,7 +58,8 @@ public APLRes AskPluginLoad2(Handle self, bool late, char[] error, int maxlen) { CreateNative("TF2Util_UpdatePlayerSpeed", Native_UpdatePlayerSpeed); CreateNative("TF2Util_TakeHealth", Native_TakeHealth); - CreateNative("TF2Util_GetPlayerMaxHealth", Native_GetMaxHealth); + CreateNative("TF2Util_GetEntityMaxHealth", Native_GetMaxHealth); + CreateNative("TF2Util_GetPlayerMaxHealthBoost", Native_GetMaxHealthBoost); CreateNative("TF2Util_GetPlayerMaxAmmo", Native_GetMaxAmmo); CreateNative("TF2Util_GetConditionCount", Native_GetConditionCount); @@ -84,6 +86,9 @@ public APLRes AskPluginLoad2(Handle self, bool late, char[] error, int maxlen) { CreateNative("TF2Util_IsPointInRespawnRoom", Native_IsPointInRespawnRoom); + // deprecated name for backcompat + CreateNative("TF2Util_GetPlayerMaxHealth", Native_GetMaxHealthBoost); + return APLRes_Success; } @@ -125,6 +130,11 @@ public void OnPluginStart() { PrepSDKCall_AddParameter(SDKType_Bool, SDKPass_Plain); g_SDKCallPlayerSharedGetMaxHealth = EndPrepSDKCall(); + StartPrepSDKCall(SDKCall_Entity); + PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain); + PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, "CBaseEntity::GetMaxHealth()"); + g_SDKCallEntityGetMaxHealth = EndPrepSDKCall(); + StartPrepSDKCall(SDKCall_Entity); PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, "CBaseEntity::IsBaseCombatWeapon()"); PrepSDKCall_SetReturnInfo(SDKType_Bool, SDKPass_Plain); @@ -281,8 +291,18 @@ public int Native_GetMaxAmmo(Handle plugin, int nParams) { return SDKCall(g_SDKCallPlayerGetMaxAmmo, client, ammoIndex, playerClass); } -// int(int client, bool bIgnoreAttributes, bool bIgnoreOverheal); +// int(int entity); public int Native_GetMaxHealth(Handle plugin, int nParams) { + int entity = GetNativeCell(1); + if (!IsValidEntity(entity)) { + return ThrowNativeError(SP_ERROR_NATIVE, "Entity %d is invalid", entity); + } + + return SDKCall(g_SDKCallEntityGetMaxHealth, entity); +} + +// int(int client, bool bIgnoreAttributes, bool bIgnoreOverheal); +public int Native_GetMaxHealthBoost(Handle plugin, int nParams) { int client = GetNativeCell(1); bool bIgnoreAttributes = !!GetNativeCell(2); bool bIgnoreOverheal = !!GetNativeCell(3);