Skip to content

Commit 87a293b

Browse files
committed
Add healer array support
1 parent 9d2661e commit 87a293b

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

scripting/include/tf2utils.inc

+8
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ native void TF2Util_SetPlayerBurnDuration(int client, float duration);
136136
*/
137137
native void TF2Util_GetPlayerShootPosition(int client, float result[3]);
138138

139+
/**
140+
* Returns the healer entity index at the given position in the player's healer array.
141+
* To get the number of healers available, use the m_nNumHealers netprop.
142+
*
143+
* @return Healer entity index at the given index.
144+
*/
145+
native int TF2Util_GetPlayerHealer(int client, int index);
146+
139147
/**
140148
* Returns whether or not the given entity is a weapon.
141149
*

scripting/tf2utils.sp

+27-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include <stocksoup/memory>
1313

14-
#define PLUGIN_VERSION "0.14.1"
14+
#define PLUGIN_VERSION "0.15.0"
1515
public Plugin myinfo = {
1616
name = "TF2 Utils",
1717
author = "nosoop",
@@ -42,6 +42,7 @@ Handle g_SDKCallPlayerEquipWearable;
4242
Handle g_SDKCallPointInRespawnRoom;
4343

4444
Address offs_ConditionNames;
45+
Address offs_CTFPlayer_aHealers;
4546

4647
Address offs_CTFPlayer_hMyWearables;
4748

@@ -73,6 +74,8 @@ public APLRes AskPluginLoad2(Handle self, bool late, char[] error, int maxlen) {
7374
CreateNative("TF2Util_GetPlayerBurnDuration", Native_GetPlayerBurnDuration);
7475
CreateNative("TF2Util_SetPlayerBurnDuration", Native_SetPlayerBurnDuration);
7576

77+
CreateNative("TF2Util_GetPlayerHealer", Native_GetPlayerHealer);
78+
7679
CreateNative("TF2Util_IsEntityWearable", Native_IsEntityWearable);
7780
CreateNative("TF2Util_GetPlayerWearable", Native_GetPlayerWearable);
7881
CreateNative("TF2Util_GetPlayerWearableCount", Native_GetPlayerWearableCount);
@@ -225,6 +228,8 @@ public void OnPluginStart() {
225228
}
226229
offs_ConditionNames = GameConfGetAddress(hGameConf, "g_aConditionNames");
227230

231+
offs_CTFPlayer_aHealers = view_as<Address>(FindSendPropInfo("CTFPlayer", "m_nNumHealers") + 0xC);
232+
228233
delete hGameConf;
229234
}
230235

@@ -388,6 +393,27 @@ public int Native_GetPlayerShootPosition(Handle plugin, int nParams) {
388393
SetNativeArray(2, vecResult, sizeof(vecResult));
389394
}
390395

396+
// int(int client, int index);
397+
int Native_GetPlayerHealer(Handle plugin, int nParams) {
398+
// Pelipoika did this ages ago https://forums.alliedmods.net/showthread.php?t=306854
399+
// it's bundled here for consistency's sake, and in case it needs maintenance in the future
400+
int client = GetNativeCell(1);
401+
int index = GetNativeCell(2);
402+
403+
if (client < 1 || client > MaxClients || !IsClientInGame(client)) {
404+
ThrowNativeError(SP_ERROR_NATIVE, "Client index %d is invalid", client);
405+
}
406+
407+
int count = GetEntProp(client, Prop_Send, "m_nNumHealers");
408+
if (index < 0 || index >= count) {
409+
ThrowNativeError(SP_ERROR_NATIVE, "Invalid index %d (count: %d)", index, count);
410+
}
411+
412+
Address pData = DereferencePointer(GetEntityAddress(client)
413+
+ view_as<Address>(offs_CTFPlayer_aHealers));
414+
return EntRefToEntIndex(LoadEntityHandleFromAddress(pData + view_as<Address>(0x24 * index)));
415+
}
416+
391417
// bool(int entity);
392418
public int Native_IsEntityWeapon(Handle plugin, int nParams) {
393419
int entity = GetNativeCell(1);

0 commit comments

Comments
 (0)