Raised This Month: $51 Target: $400
 12% 

Solved [TF2] Get weapon max clip size?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Qtheman
Junior Member
Join Date: Oct 2010
Old 04-24-2018 , 02:32   [TF2] Get weapon max clip size?
Reply With Quote #1

Wow, it's been ages since I was here last... Hi!

So, for context here - I'm trying to set up a little MvM server for my friends and I, and something I thought would be interesting is to use Custom Weapons 3 on it. To that end, I've installed it and gotten it working, and have recreated a few Advanced Weaponiser weapons to test it with.

Having said that, I'm having to do some small rewrites to the attributes plugins to get things more functional with MvM. Everything I've tried so far seems to work fine, but for one of the attributes that I do need to modify, I've hit a bit of a dead end, because I don't know how to retrieve a weapon's maximum clip size.

I know I can get the current clip with m_iClip1, but is there a similar property for the max clip size? If not, what would be the best way to go about getting it? Thanks.

Last edited by Qtheman; 04-24-2018 at 21:36.
Qtheman is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 04-24-2018 , 11:43   Re: [TF2] Get weapon max clip size?
Reply With Quote #2

Working on a similar thing myself; you'll want to SDKCall CTFWeaponBase::GetMaxClip1().

Code:
StartPrepSDKCall(SDKCall_Entity);
PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, "CTFWeaponBase::GetMaxClip1()");
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);

// handle in global scope
g_SDKGetMaxClip1 = EndPrepSDKCall();
Code:
int hWeapon = GetPlayerWeaponSlot(attacker, 0);
int nMaxClip1 = SDKCall(g_SDKGetMaxClip1, hWeapon);
Pull the offsets from the VTable dumper (current offsets should be 317 and 323 for Windows and Linux respectively).

Not sure about miniguns off the top of my head (max clip size reports -1 on those), but this works as expected on the rocket launchers that I was testing against (including attribute modifers).

Edit: Chdata has some SDKCall functions here.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 04-24-2018 at 11:59.
nosoop is offline
Qtheman
Junior Member
Join Date: Oct 2010
Old 04-24-2018 , 13:36   Re: [TF2] Get weapon max clip size?
Reply With Quote #3

While Chdata's functions do seem particularly useful, I'm afraid I still can't figure this out, sorry. It's been ages since I touched SourcePawn and I've completely forgotten how to do this stuff, heh.

After doing a bit of poking around, I've found myself with an exception getting thrown up: "Couldn't load SDK function (CTFWeaponBase::GetMaxClip1)." I've got the gamedata file from Chdata's post installed, and spcomp compiles my modified plugin with only a tag mismatch warning, so I don't know what I'm doing wrong.

Here's what my modified code looks like:

Code:
else if(StrEqual(attrib, "reload clip on damage"))
	{
		new String:values[2][10];
		ExplodeString(value, " ", values, sizeof(values), sizeof(values[]));
		DamageReloads[client][slot] = true;
		
		new hWeapon = GetSlotContainingAttribute(client, DamageReloads);
		new maxClip = GetMaxClip(hWeapon);

		DamageReloads_Damage[client][slot] = StringToFloat(values[0]);
		DamageReloads_Max[client][slot] = maxClip;
		
		g_fTotalDamage1296[client] = 0.0;
		
		action = Plugin_Handled;
	}
EDIT: And for comparison, here's the unmodified code:
Code:
else if(StrEqual(attrib, "reload clip on damage"))
	{
		new String:values[2][10];
		ExplodeString(value, " ", values, sizeof(values), sizeof(values[]));
		
		DamageReloads[client][slot] = true;
		
		DamageReloads_Max[client][slot] = StringToFloat(values[0]);
		DamageReloads_Damage[client][slot] = StringToFloat(values[1]);
		
		g_fTotalDamage1296[client] = 0.0;
		
		action = Plugin_Handled;
	}
(I know I don't need the ExplodeString stuff in my version since I'm trying to reduce it from two values required to just one, but I'm trying to take this one step at a time right now)

spcomp tells me the tag mismatch is on the "DamageReloads_Max = maxClip;" line, and the stack trace that Sourcemod gives me on the server just points to the line where I added "OnPluginStart_RegisterWeaponData();" in the plugin, which doesn't really tell me much. I couldn't quite figure it out with my own SDKCall either, but I forget what exactly happened there, I think it just didn't function properly in-game. I'll try again later to see if I can figure it out.

In the meantime, is there something obviously wrong with my code here that needs fixing? ^^;

Last edited by Qtheman; 04-24-2018 at 13:38.
Qtheman is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 04-24-2018 , 13:52   Re: [TF2] Get weapon max clip size?
Reply With Quote #4

Are you running a TF2 server on Windows? Chdata only has Linux / Mac symbols; you could get a signature for the Windows function, but you might be better off just calling the virtual function (see my post for code, use attached gamedata with LoadGameConfigFile).

Is DamageReloads_Max tagged as a specific type of array (from the rest of the code, maybe float?). That's the only thing I can think of that would cause a mismatch there.

Also, if you've done programming in any other languages, you might want to read up on the new syntax for SourcePawn.
Attached Files
File Type: txt tf2.maxclip.txt (139 Bytes, 224 views)
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
Qtheman
Junior Member
Join Date: Oct 2010
Old 04-24-2018 , 17:53   Re: [TF2] Get weapon max clip size?
Reply With Quote #5

I'm running on Windows (this is sort of a "halfway" server if you will, for when our main server guy is at college and can't host), yeah, but there's a github link on the second page that's allegedly for a Windows gamedata file (it's got the same offset listed for MaxClip1 as yours does).

And yeah, DamageReloads_Max is tagged as a float, that's what was causing the tag mismatch, whoops. Oh well, easy fix.

Either way, after a bit of trial and error, I've managed to get it working now! Thanks for your help!
Qtheman is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:01.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode