11
11
12
12
#include <stocksoup/memory>
13
13
14
- #define PLUGIN_VERSION " 0.10 .0"
14
+ #define PLUGIN_VERSION " 0.11 .0"
15
15
public Plugin myinfo = {
16
16
name = " TF2 Utils" ,
17
17
author = " nosoop" ,
@@ -26,6 +26,7 @@ bool g_bDeferredSpeedUpdate[MAXPLAYERS + 1];
26
26
Handle g_SDKCallPlayerGetMaxAmmo ;
27
27
Handle g_SDKCallPlayerTakeHealth ;
28
28
Handle g_SDKCallPlayerGetShootPosition ;
29
+ Handle g_SDKCallPlayerGetEntityForLoadoutSlot ;
29
30
30
31
Handle g_SDKCallPlayerSharedGetMaxHealth ;
31
32
@@ -34,6 +35,9 @@ Handle g_SDKCallWeaponGetSlot;
34
35
Handle g_SDKCallWeaponGetID ;
35
36
Handle g_SDKCallWeaponGetMaxClip ;
36
37
38
+ Handle g_SDKCallIsEntityWearable ;
39
+ Handle g_SDKCallPlayerEquipWearable ;
40
+
37
41
Handle g_SDKCallPointInRespawnRoom ;
38
42
39
43
Address offs_CTFPlayer_hMyWearables ;
@@ -46,14 +50,18 @@ public APLRes AskPluginLoad2(Handle self, bool late, char[] error, int maxlen) {
46
50
CreateNative (" TF2Util_GetPlayerMaxHealth" , Native_GetMaxHealth );
47
51
CreateNative (" TF2Util_GetPlayerMaxAmmo" , Native_GetMaxAmmo );
48
52
53
+ CreateNative (" TF2Util_IsEntityWearable" , Native_IsEntityWearable );
49
54
CreateNative (" TF2Util_GetPlayerWearable" , Native_GetPlayerWearable );
50
55
CreateNative (" TF2Util_GetPlayerWearableCount" , Native_GetPlayerWearableCount );
56
+ CreateNative (" TF2Util_EquipPlayerWearable" , Native_EquipPlayerWearable );
51
57
52
58
CreateNative (" TF2Util_IsEntityWeapon" , Native_IsEntityWeapon );
53
59
CreateNative (" TF2Util_GetWeaponSlot" , Native_GetWeaponSlot );
54
60
CreateNative (" TF2Util_GetWeaponID" , Native_GetWeaponID );
55
61
CreateNative (" TF2Util_GetWeaponMaxClip" , Native_GetWeaponMaxClip );
56
62
63
+ CreateNative (" TF2Util_GetPlayerLoadoutEntity" , Native_GetPlayerLoadoutEntity );
64
+
57
65
CreateNative (" TF2Util_GetPlayerShootPosition" , Native_GetPlayerShootPosition );
58
66
59
67
CreateNative (" TF2Util_IsPointInRespawnRoom" , Native_IsPointInRespawnRoom );
@@ -104,6 +112,11 @@ public void OnPluginStart() {
104
112
PrepSDKCall_SetReturnInfo (SDKType_Bool , SDKPass_Plain );
105
113
g_SDKCallIsEntityWeapon = EndPrepSDKCall ();
106
114
115
+ StartPrepSDKCall (SDKCall_Entity );
116
+ PrepSDKCall_SetFromConf (hGameConf , SDKConf_Virtual , " CBaseEntity::IsWearable()" );
117
+ PrepSDKCall_SetReturnInfo (SDKType_Bool , SDKPass_Plain );
118
+ g_SDKCallIsEntityWearable = EndPrepSDKCall ();
119
+
107
120
StartPrepSDKCall (SDKCall_Entity );
108
121
PrepSDKCall_SetFromConf (hGameConf , SDKConf_Virtual , " CBaseCombatWeapon::GetSlot()" );
109
122
PrepSDKCall_SetReturnInfo (SDKType_PlainOldData , SDKPass_Plain );
@@ -119,6 +132,19 @@ public void OnPluginStart() {
119
132
PrepSDKCall_SetReturnInfo (SDKType_PlainOldData , SDKPass_Plain );
120
133
g_SDKCallWeaponGetMaxClip = EndPrepSDKCall ();
121
134
135
+ StartPrepSDKCall (SDKCall_Player );
136
+ PrepSDKCall_SetFromConf (hGameConf , SDKConf_Signature ,
137
+ " CTFPlayer::GetEntityForLoadoutSlot()" );
138
+ PrepSDKCall_AddParameter (SDKType_PlainOldData , SDKPass_Plain );
139
+ PrepSDKCall_AddParameter (SDKType_Bool , SDKPass_Plain );
140
+ PrepSDKCall_SetReturnInfo (SDKType_CBaseEntity , SDKPass_Pointer );
141
+ g_SDKCallPlayerGetEntityForLoadoutSlot = EndPrepSDKCall ();
142
+
143
+ StartPrepSDKCall (SDKCall_Player );
144
+ PrepSDKCall_SetFromConf (hGameConf , SDKConf_Virtual , " CTFPlayer::EquipWearable()" );
145
+ PrepSDKCall_AddParameter (SDKType_CBaseEntity , SDKPass_Pointer );
146
+ g_SDKCallPlayerEquipWearable = EndPrepSDKCall ();
147
+
122
148
StartPrepSDKCall (SDKCall_Static );
123
149
PrepSDKCall_SetFromConf (hGameConf , SDKConf_Signature , " PointInRespawnRoom()" );
124
150
PrepSDKCall_SetReturnInfo (SDKType_Bool , SDKPass_Plain );
@@ -221,6 +247,20 @@ public int Native_GetMaxHealth(Handle plugin, int nParams) {
221
247
bIgnoreAttributes , bIgnoreOverheal );
222
248
}
223
249
250
+ public int Native_EquipPlayerWearable (Handle plugin , int numParams ) {
251
+ int client = GetNativeCell (1 );
252
+ if (client < 1 || client > MaxClients || ! IsClientInGame (client )) {
253
+ ThrowNativeError (SP_ERROR_NATIVE , " Client index %d is invalid" , client );
254
+ }
255
+
256
+ int wearable = GetNativeCell (2 );
257
+ if (! IsEntityWearable (wearable )) {
258
+ ThrowNativeError (SP_ERROR_NATIVE , " Entity index %d is not a wearable" ,
259
+ EntRefToEntIndex (wearable ));
260
+ }
261
+ SDKCall (g_SDKCallPlayerEquipWearable , client , wearable );
262
+ }
263
+
224
264
// int(int client, int index);
225
265
public int Native_GetPlayerWearable (Handle plugin , int nParams ) {
226
266
int client = GetNativeCell (1 );
@@ -266,6 +306,12 @@ public int Native_IsEntityWeapon(Handle plugin, int nParams) {
266
306
return IsEntityWeapon (entity );
267
307
}
268
308
309
+ // bool(int entity);
310
+ public int Native_IsEntityWearable (Handle plugin , int nParams ) {
311
+ int entity = GetNativeCell (1 );
312
+ return IsEntityWearable (entity );
313
+ }
314
+
269
315
// int(int entity);
270
316
public int Native_GetWeaponSlot (Handle plugin , int nParams ) {
271
317
int entity = GetNativeCell (1 );
@@ -316,6 +362,18 @@ public int Native_IsPointInRespawnRoom(Handle plugin, int nParams) {
316
362
return SDKCall (g_SDKCallPointInRespawnRoom , entity , origin , bRestrictToSameTeam );
317
363
}
318
364
365
+ // int(int client, int loadoutSlot, bool includeWearableWeapons);
366
+ int Native_GetPlayerLoadoutEntity (Handle plugin , int numParams ) {
367
+ int client = GetNativeCell (1 );
368
+ if (client < 1 || client > MaxClients || ! IsClientInGame (client )) {
369
+ ThrowNativeError (SP_ERROR_NATIVE , " Client index %d is invalid" , client );
370
+ }
371
+ int loadoutSlot = GetNativeCell (2 );
372
+ bool check_wearable = numParams < 3 ? true : GetNativeCell (3 );
373
+
374
+ return SDKCall (g_SDKCallPlayerGetEntityForLoadoutSlot , client , loadoutSlot , check_wearable );
375
+ }
376
+
319
377
bool IsEntityWeapon (int entity ) {
320
378
if (! IsValidEntity (entity )) {
321
379
ThrowNativeError (SP_ERROR_NATIVE , " Entity %d (%d ) is invalid" , entity ,
@@ -324,6 +382,14 @@ bool IsEntityWeapon(int entity) {
324
382
return SDKCall (g_SDKCallIsEntityWeapon , entity );
325
383
}
326
384
385
+ bool IsEntityWearable (int entity ) {
386
+ if (! IsValidEntity (entity )) {
387
+ ThrowNativeError (SP_ERROR_NATIVE , " Entity %d (%d ) is invalid" , entity ,
388
+ EntRefToEntIndex (entity ));
389
+ }
390
+ return SDKCall (g_SDKCallIsEntityWearable , entity );
391
+ }
392
+
327
393
static Address GameConfGetAddressOffset (Handle gamedata , const char [] key ) {
328
394
Address offs = view_as <Address >(GameConfGetOffset (gamedata , key ));
329
395
if (offs == view_as <Address >(- 1 )) {
0 commit comments