Skip to content

Commit fd92c9e

Browse files
committed
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.
1 parent 5cdaadb commit fd92c9e

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

gamedata/tf2.utils.nosoop.txt

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
"windows" "327"
3131
"linux" "333"
3232
}
33+
"CBaseEntity::GetMaxHealth()"
34+
{
35+
"windows" "117"
36+
"linux" "118"
37+
}
3338
"CBaseEntity::IsBaseCombatWeapon()"
3439
{
3540
"windows" "86"

scripting/include/tf2utils.inc

+18-2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,18 @@ native int TF2Util_GetPlayerMaxAmmo(int client, int iAmmoIndex,
4343
TFClassType playerClass = TFClass_Unknown);
4444

4545
/**
46-
* Returns the current maximum health of the player.
46+
* Returns the current maximum allowed health of an entity.
4747
*/
48-
native int TF2Util_GetPlayerMaxHealth(int client, bool bIgnoreAttributes = false,
48+
native int TF2Util_GetEntityMaxHealth(int entity);
49+
50+
/**
51+
* Returns the maximum allowed overhealed health of a player, taking into account the amount
52+
* it can gain through overhealing by mediguns.
53+
*
54+
* @param bIgnoreAttributes
55+
* @param bIgnoreOverheal Ignores excessive overheal.
56+
*/
57+
native int TF2Util_GetPlayerMaxHealthBoost(int client, bool bIgnoreAttributes = false,
4958
bool bIgnoreOverheal = false);
5059

5160
/**
@@ -199,6 +208,13 @@ native void TF2Util_UpdatePlayerSpeed(int client, bool immediate = false);
199208
native bool TF2Util_IsPointInRespawnRoom(const float[3] position,
200209
int entity = INVALID_ENT_REFERENCE, bool bRestrictToSameTeam = false);
201210

211+
/**
212+
* Returns the current maximum health of the player.
213+
*/
214+
#pragma deprecated Misnamed; use TF2Util_GetEntityMaxHealth or TF2Util_GetPlayerMaxHealthBoost.
215+
native int TF2Util_GetPlayerMaxHealth(int client, bool bIgnoreAttributes = false,
216+
bool bIgnoreOverheal = false);
217+
202218
// compile-time compatibility shim for tf2wearables natives
203219
#if defined USE_TF2WEARABLE_FUNCTION_SHIMS
204220
#define TF2_GetPlayerLoadoutSlot TF2Util_GetPlayerLoadoutEntity

scripting/tf2utils.sp

+23-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include <stocksoup/memory>
1313

14-
#define PLUGIN_VERSION "0.12.0"
14+
#define PLUGIN_VERSION "0.13.0"
1515
public Plugin myinfo = {
1616
name = "TF2 Utils",
1717
author = "nosoop",
@@ -28,6 +28,7 @@ Handle g_SDKCallPlayerTakeHealth;
2828
Handle g_SDKCallPlayerGetShootPosition;
2929
Handle g_SDKCallPlayerGetEntityForLoadoutSlot;
3030

31+
Handle g_SDKCallEntityGetMaxHealth;
3132
Handle g_SDKCallPlayerSharedGetMaxHealth;
3233

3334
Handle g_SDKCallIsEntityWeapon;
@@ -57,7 +58,8 @@ public APLRes AskPluginLoad2(Handle self, bool late, char[] error, int maxlen) {
5758

5859
CreateNative("TF2Util_UpdatePlayerSpeed", Native_UpdatePlayerSpeed);
5960
CreateNative("TF2Util_TakeHealth", Native_TakeHealth);
60-
CreateNative("TF2Util_GetPlayerMaxHealth", Native_GetMaxHealth);
61+
CreateNative("TF2Util_GetEntityMaxHealth", Native_GetMaxHealth);
62+
CreateNative("TF2Util_GetPlayerMaxHealthBoost", Native_GetMaxHealthBoost);
6163
CreateNative("TF2Util_GetPlayerMaxAmmo", Native_GetMaxAmmo);
6264

6365
CreateNative("TF2Util_GetConditionCount", Native_GetConditionCount);
@@ -84,6 +86,9 @@ public APLRes AskPluginLoad2(Handle self, bool late, char[] error, int maxlen) {
8486

8587
CreateNative("TF2Util_IsPointInRespawnRoom", Native_IsPointInRespawnRoom);
8688

89+
// deprecated name for backcompat
90+
CreateNative("TF2Util_GetPlayerMaxHealth", Native_GetMaxHealthBoost);
91+
8792
return APLRes_Success;
8893
}
8994

@@ -125,6 +130,11 @@ public void OnPluginStart() {
125130
PrepSDKCall_AddParameter(SDKType_Bool, SDKPass_Plain);
126131
g_SDKCallPlayerSharedGetMaxHealth = EndPrepSDKCall();
127132

133+
StartPrepSDKCall(SDKCall_Entity);
134+
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
135+
PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, "CBaseEntity::GetMaxHealth()");
136+
g_SDKCallEntityGetMaxHealth = EndPrepSDKCall();
137+
128138
StartPrepSDKCall(SDKCall_Entity);
129139
PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, "CBaseEntity::IsBaseCombatWeapon()");
130140
PrepSDKCall_SetReturnInfo(SDKType_Bool, SDKPass_Plain);
@@ -281,8 +291,18 @@ public int Native_GetMaxAmmo(Handle plugin, int nParams) {
281291
return SDKCall(g_SDKCallPlayerGetMaxAmmo, client, ammoIndex, playerClass);
282292
}
283293

284-
// int(int client, bool bIgnoreAttributes, bool bIgnoreOverheal);
294+
// int(int entity);
285295
public int Native_GetMaxHealth(Handle plugin, int nParams) {
296+
int entity = GetNativeCell(1);
297+
if (!IsValidEntity(entity)) {
298+
return ThrowNativeError(SP_ERROR_NATIVE, "Entity %d is invalid", entity);
299+
}
300+
301+
return SDKCall(g_SDKCallEntityGetMaxHealth, entity);
302+
}
303+
304+
// int(int client, bool bIgnoreAttributes, bool bIgnoreOverheal);
305+
public int Native_GetMaxHealthBoost(Handle plugin, int nParams) {
286306
int client = GetNativeCell(1);
287307
bool bIgnoreAttributes = !!GetNativeCell(2);
288308
bool bIgnoreOverheal = !!GetNativeCell(3);

0 commit comments

Comments
 (0)