Skip to content

Commit 8de14fd

Browse files
committed
Add GetMaxClip
1 parent 441479d commit 8de14fd

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

gamedata/tf2.utils.nosoop.txt

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
"windows" "64"
2121
"linux" "65"
2222
}
23+
"CTFWeaponBase::GetMaxClip1()"
24+
{
25+
"windows" "317"
26+
"linux" "323"
27+
}
2328
"CTFWeaponBase::GetWeaponID()"
2429
{
2530
"windows" "372"

scripting/include/tf2utils.inc

+7
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ native int TF2Util_GetWeaponSlot(int entity);
7070
*/
7171
native int TF2Util_GetWeaponID(int entity);
7272

73+
/**
74+
* Returns the weapon entity's maximum clip.
75+
*
76+
* @error Entity is not valid or not a weapon.
77+
*/
78+
native int TF2Util_GetWeaponMaxClip(int entity);
79+
7380
/**
7481
* @return Wearable entity at the given index.
7582
* @error Index is negative or out of bounds.

scripting/tf2utils.sp

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

1212
#include <stocksoup/memory>
1313

14-
#define PLUGIN_VERSION "0.7.0"
14+
#define PLUGIN_VERSION "0.8.0"
1515
public Plugin myinfo = {
1616
name = "TF2 Utils",
1717
author = "nosoop",
@@ -31,6 +31,7 @@ Handle g_SDKCallPlayerSharedGetMaxHealth;
3131
Handle g_SDKCallIsEntityWeapon;
3232
Handle g_SDKCallWeaponGetSlot;
3333
Handle g_SDKCallWeaponGetID;
34+
Handle g_SDKCallWeaponGetMaxClip;
3435

3536
Address offs_CTFPlayer_hMyWearables;
3637

@@ -48,6 +49,7 @@ public APLRes AskPluginLoad2(Handle self, bool late, char[] error, int maxlen) {
4849
CreateNative("TF2Util_IsEntityWeapon", Native_IsEntityWeapon);
4950
CreateNative("TF2Util_GetWeaponSlot", Native_GetWeaponSlot);
5051
CreateNative("TF2Util_GetWeaponID", Native_GetWeaponID);
52+
CreateNative("TF2Util_GetWeaponMaxClip", Native_GetWeaponMaxClip);
5153

5254
return APLRes_Success;
5355
}
@@ -99,6 +101,11 @@ public void OnPluginStart() {
99101
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
100102
g_SDKCallWeaponGetID = EndPrepSDKCall();
101103

104+
StartPrepSDKCall(SDKCall_Entity);
105+
PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, "CTFWeaponBase::GetMaxClip1()");
106+
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
107+
g_SDKCallWeaponGetMaxClip = EndPrepSDKCall();
108+
102109
// networked CUtlVector offset support landed in 1.11; try to locate an offset there first
103110
offs_CTFPlayer_hMyWearables =
104111
view_as<Address>(FindSendPropInfo("CTFPlayer", "m_hMyWearables"));
@@ -247,6 +254,16 @@ public int Native_GetWeaponID(Handle plugin, int nParams) {
247254
return SDKCall(g_SDKCallWeaponGetID, entity);
248255
}
249256

257+
// int(int entity);
258+
public int Native_GetWeaponMaxClip(Handle plugin, int nParams) {
259+
int entity = GetNativeCell(1);
260+
if (!IsEntityWeapon(entity)) {
261+
ThrowNativeError(SP_ERROR_NATIVE, "Entity index %d (%d) is not a weapon", entity,
262+
EntRefToEntIndex(entity));
263+
}
264+
return SDKCall(g_SDKCallWeaponGetMaxClip, entity);
265+
}
266+
250267
bool IsEntityWeapon(int entity) {
251268
if (!IsValidEntity(entity)) {
252269
ThrowNativeError(SP_ERROR_NATIVE, "Entity %d (%d) is invalid", entity,

0 commit comments

Comments
 (0)