Skip to content

Commit ab7acea

Browse files
committed
Add 'TF2Util_IsPointInRespawnRoom'
1 parent 8a0eb55 commit ab7acea

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

gamedata/tf2.utils.nosoop.txt

+6
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@
6868
"linux" "@_ZN15CTFPlayerShared18GetMaxBuffedHealthEbb"
6969
"windows" "\x55\x8B\xEC\x83\xEC\x08\x56\x8B\xF1\x57\x8B\x8E\x2A\x01\x00\x00"
7070
}
71+
"PointInRespawnRoom()"
72+
{
73+
"library" "server"
74+
"linux" "@_Z18PointInRespawnRoomPK11CBaseEntityRK6Vectorb"
75+
"windows" "\x55\x8B\xEC\x53\x33\xDB\x56\x57"
76+
}
7177
}
7278
}
7379
}

scripting/include/tf2utils.inc

+15
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@ native int TF2Util_GetPlayerWearableCount(int client);
103103
*/
104104
native void TF2Util_UpdatePlayerSpeed(int client, bool immediate = false);
105105

106+
/**
107+
* Returns whether or not a position / entity is in an active respawn room. If an entity is
108+
* passed in, this also checks if the entity is touching an active respawn room, instead of just
109+
* the given position.
110+
*
111+
* @param position A position to check. Should be the center / origin of an entity.
112+
* @param entity An optional entity to check.
113+
* @param bTouchingSameTeam Whether or not the respawn room must either match the entity's
114+
* team, or not be assigned to a team. Always treated as true if
115+
* the position is in an active spawn room. Has no effect if no
116+
* entity is provided.
117+
*/
118+
native bool TF2Util_IsPointInRespawnRoom(const float[3] position,
119+
int entity = INVALID_ENT_REFERENCE, bool bRestrictToSameTeam = false);
120+
106121
public SharedPlugin __pl_tf2utils = {
107122
name = "nosoop_tf2utils",
108123
file = "tf2utils.smx",

scripting/tf2utils.sp

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

1212
#include <stocksoup/memory>
1313

14-
#define PLUGIN_VERSION "0.9.0"
14+
#define PLUGIN_VERSION "0.10.0"
1515
public Plugin myinfo = {
1616
name = "TF2 Utils",
1717
author = "nosoop",
@@ -34,6 +34,8 @@ Handle g_SDKCallWeaponGetSlot;
3434
Handle g_SDKCallWeaponGetID;
3535
Handle g_SDKCallWeaponGetMaxClip;
3636

37+
Handle g_SDKCallPointInRespawnRoom;
38+
3739
Address offs_CTFPlayer_hMyWearables;
3840

3941
public APLRes AskPluginLoad2(Handle self, bool late, char[] error, int maxlen) {
@@ -54,6 +56,8 @@ public APLRes AskPluginLoad2(Handle self, bool late, char[] error, int maxlen) {
5456

5557
CreateNative("TF2Util_GetPlayerShootPosition", Native_GetPlayerShootPosition);
5658

59+
CreateNative("TF2Util_IsPointInRespawnRoom", Native_IsPointInRespawnRoom);
60+
5761
return APLRes_Success;
5862
}
5963

@@ -115,6 +119,14 @@ public void OnPluginStart() {
115119
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
116120
g_SDKCallWeaponGetMaxClip = EndPrepSDKCall();
117121

122+
StartPrepSDKCall(SDKCall_Static);
123+
PrepSDKCall_SetFromConf(hGameConf, SDKConf_Signature, "PointInRespawnRoom()");
124+
PrepSDKCall_SetReturnInfo(SDKType_Bool, SDKPass_Plain);
125+
PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer, VDECODE_FLAG_ALLOWNULL);
126+
PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_ByRef);
127+
PrepSDKCall_AddParameter(SDKType_Bool, SDKPass_Plain);
128+
g_SDKCallPointInRespawnRoom = EndPrepSDKCall();
129+
118130
// networked CUtlVector offset support landed in 1.11; try to locate an offset there first
119131
offs_CTFPlayer_hMyWearables =
120132
view_as<Address>(FindSendPropInfo("CTFPlayer", "m_hMyWearables"));
@@ -284,6 +296,26 @@ public int Native_GetWeaponMaxClip(Handle plugin, int nParams) {
284296
return SDKCall(g_SDKCallWeaponGetMaxClip, entity);
285297
}
286298

299+
// bool(const float[3] position, int entity, bool bRestrictToSameTeam)
300+
public int Native_IsPointInRespawnRoom(Handle plugin, int nParams) {
301+
if (IsNativeParamNullVector(1)) {
302+
return ThrowNativeError(SP_ERROR_NATIVE, "Cannot use NULL_VECTOR as origin");
303+
}
304+
305+
float origin[3];
306+
GetNativeArray(1, origin, sizeof(origin));
307+
308+
int entity = GetNativeCell(2);
309+
if (entity != INVALID_ENT_REFERENCE && !IsValidEntity(entity)) {
310+
return ThrowNativeError(SP_ERROR_NATIVE, "Entity %d (%d) is invalid", entity,
311+
EntRefToEntIndex(entity));
312+
}
313+
314+
bool bRestrictToSameTeam = GetNativeCell(3);
315+
316+
return SDKCall(g_SDKCallPointInRespawnRoom, entity, origin, bRestrictToSameTeam);
317+
}
318+
287319
bool IsEntityWeapon(int entity) {
288320
if (!IsValidEntity(entity)) {
289321
ThrowNativeError(SP_ERROR_NATIVE, "Entity %d (%d) is invalid", entity,

0 commit comments

Comments
 (0)