Raised This Month: $218 Target: $400
 54% 

Solved [TF2] How to Get Saxxy Classname?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PC Gamer
Senior Member
Join Date: Mar 2014
Old 11-16-2019 , 23:44   [TF2] How to Get Saxxy Classname?
Reply With Quote #1

Team,

How can I reliably return the weapon classname of a players active weapon when they are holding a saxxy weapon such as 'The Bat Outta Hell' or the 'Prinny Machete'

For example, if I equip 'The Bat Outta Hell' each of these functions will return a classname of 'tf_weapon_bonesaw'. How do I get a classname of 'saxxy'?

Code:
char sWeapon2[32];
GetClientWeapon(target, sWeapon2, sizeof(sWeapon2));

/**
* Gets the classname and entity index of the current/active weapon of a client.
*
* @param client		Client Index.
* @param buffer		String Buffer to store the weapon's classname.
* @param size			Max size of String: buffer.
* @return				Weapon Entity Index on success or INVALID_ENT_REFERENCE otherwise
*/
stock Client_GetActiveWeaponName(client, String:buffer[], size)
{
	new weapon = Client_GetActiveWeapon(client);

	if (weapon == INVALID_ENT_REFERENCE) {
		buffer[0] = '\0';
		return INVALID_ENT_REFERENCE;
	}

	Entity_GetClassName(weapon, buffer, size);

	return weapon;
}
Note, these functions seem to return the correct classname on all of the other weapon classes that I tested.

Last edited by PC Gamer; 11-18-2019 at 10:36. Reason: Solved
PC Gamer is offline
Shadowysn
Senior Member
Join Date: Sep 2015
Location: Location:
Old 11-17-2019 , 01:17   Re: [TF2] How to Get Saxxy Classname?
Reply With Quote #2

There's a netprop for the weapons named m_iItemDefinitionIndex. You can try to get the Saxxy's index, then have a check on the netprop comparing it to the numbered index you found.

As far as I know not all weapons have their own classnames; some just reuse existing ones.
__________________
Shadowysn is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 11-17-2019 , 10:02   Re: [TF2] How to Get Saxxy Classname?
Reply With Quote #3

Sounds like an XY problem; what's your goal here, exactly?

The most foolproof way would be to look it up in the schema with the item's definition index. TF2Econ_GetItemClassName from my Econ Data library would be the newest way of going about that.
__________________
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; 11-17-2019 at 10:25.
nosoop is offline
PC Gamer
Senior Member
Join Date: Mar 2014
Old 11-17-2019 , 22:46   Re: [TF2] How to Get Saxxy Classname?
Reply With Quote #4

Thanks nosoop! The TF2Econ_GetItemClassName works great.

Use case: I use it to troubleshoot weapon specific problems within the Uber Upgrades plugin because it uses weapon classes to determine upgrade menus that are displayed to the client.

Example Problem: In my most recent example an Engineer claimed the buildings upgrade menu wouldn't appear when he used the Prinny Machete (a saxxy class weapon).

Typical troubleshooting step: I use the !getweapon command from Joined Senses Attribute Setter plugin to determine a players weapon class. I noticed the weapon indexes being returned were sometimes wrong, and also noticed that the weaponclass returned was always wrong when the player had a saxxy class weapon equipped.

While testing fixes to the plugin I realized that the SourceMod function "GetClientWeapon" and SMLIB Function "Client_GetActiveWeaponName" do not return the correct classname with saxxy class weapons. However, the TF2Econ_GetItemClassName function you provided works great. Thanks!
PC Gamer is offline
Reply


Thread Tools
Display Modes

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 14:49.


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