Skip to content

Commit

Permalink
Add GetEntityMaxHealth, change GetPlayerMaxHealth to GetPlayerMaxHeal…
Browse files Browse the repository at this point in the history
…thBoost

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.
  • Loading branch information
nosoop committed Sep 1, 2021
1 parent 5cdaadb commit fd92c9e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
5 changes: 5 additions & 0 deletions gamedata/tf2.utils.nosoop.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"windows" "327"
"linux" "333"
}
"CBaseEntity::GetMaxHealth()"
{
"windows" "117"
"linux" "118"
}
"CBaseEntity::IsBaseCombatWeapon()"
{
"windows" "86"
Expand Down
20 changes: 18 additions & 2 deletions scripting/include/tf2utils.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**
Expand Down Expand Up @@ -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
Expand Down
26 changes: 23 additions & 3 deletions scripting/tf2utils.sp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <stocksoup/memory>

#define PLUGIN_VERSION "0.12.0"
#define PLUGIN_VERSION "0.13.0"
public Plugin myinfo = {
name = "TF2 Utils",
author = "nosoop",
Expand All @@ -28,6 +28,7 @@ Handle g_SDKCallPlayerTakeHealth;
Handle g_SDKCallPlayerGetShootPosition;
Handle g_SDKCallPlayerGetEntityForLoadoutSlot;

Handle g_SDKCallEntityGetMaxHealth;
Handle g_SDKCallPlayerSharedGetMaxHealth;

Handle g_SDKCallIsEntityWeapon;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fd92c9e

Please sign in to comment.