Skip to content

Commit

Permalink
Add healer array support
Browse files Browse the repository at this point in the history
  • Loading branch information
nosoop committed Jan 9, 2022
1 parent 9d2661e commit 87a293b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
8 changes: 8 additions & 0 deletions scripting/include/tf2utils.inc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ native void TF2Util_SetPlayerBurnDuration(int client, float duration);
*/
native void TF2Util_GetPlayerShootPosition(int client, float result[3]);

/**
* Returns the healer entity index at the given position in the player's healer array.
* To get the number of healers available, use the m_nNumHealers netprop.
*
* @return Healer entity index at the given index.
*/
native int TF2Util_GetPlayerHealer(int client, int index);

/**
* Returns whether or not the given entity is a weapon.
*
Expand Down
28 changes: 27 additions & 1 deletion 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.14.1"
#define PLUGIN_VERSION "0.15.0"
public Plugin myinfo = {
name = "TF2 Utils",
author = "nosoop",
Expand Down Expand Up @@ -42,6 +42,7 @@ Handle g_SDKCallPlayerEquipWearable;
Handle g_SDKCallPointInRespawnRoom;

Address offs_ConditionNames;
Address offs_CTFPlayer_aHealers;

Address offs_CTFPlayer_hMyWearables;

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

CreateNative("TF2Util_GetPlayerHealer", Native_GetPlayerHealer);

CreateNative("TF2Util_IsEntityWearable", Native_IsEntityWearable);
CreateNative("TF2Util_GetPlayerWearable", Native_GetPlayerWearable);
CreateNative("TF2Util_GetPlayerWearableCount", Native_GetPlayerWearableCount);
Expand Down Expand Up @@ -225,6 +228,8 @@ public void OnPluginStart() {
}
offs_ConditionNames = GameConfGetAddress(hGameConf, "g_aConditionNames");

offs_CTFPlayer_aHealers = view_as<Address>(FindSendPropInfo("CTFPlayer", "m_nNumHealers") + 0xC);

delete hGameConf;
}

Expand Down Expand Up @@ -388,6 +393,27 @@ public int Native_GetPlayerShootPosition(Handle plugin, int nParams) {
SetNativeArray(2, vecResult, sizeof(vecResult));
}

// int(int client, int index);
int Native_GetPlayerHealer(Handle plugin, int nParams) {
// Pelipoika did this ages ago https://forums.alliedmods.net/showthread.php?t=306854
// it's bundled here for consistency's sake, and in case it needs maintenance in the future
int client = GetNativeCell(1);
int index = GetNativeCell(2);

if (client < 1 || client > MaxClients || !IsClientInGame(client)) {
ThrowNativeError(SP_ERROR_NATIVE, "Client index %d is invalid", client);
}

int count = GetEntProp(client, Prop_Send, "m_nNumHealers");
if (index < 0 || index >= count) {
ThrowNativeError(SP_ERROR_NATIVE, "Invalid index %d (count: %d)", index, count);
}

Address pData = DereferencePointer(GetEntityAddress(client)
+ view_as<Address>(offs_CTFPlayer_aHealers));
return EntRefToEntIndex(LoadEntityHandleFromAddress(pData + view_as<Address>(0x24 * index)));
}

// bool(int entity);
public int Native_IsEntityWeapon(Handle plugin, int nParams) {
int entity = GetNativeCell(1);
Expand Down

0 comments on commit 87a293b

Please sign in to comment.