AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved [TF2] How to Get Saxxy Classname? (https://forums.alliedmods.net/showthread.php?t=319730)

PC Gamer 11-16-2019 22:44

[TF2] How to Get Saxxy Classname?
 
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.

Shadowysn 11-17-2019 00:17

Re: [TF2] How to Get Saxxy Classname?
 
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.

nosoop 11-17-2019 09:02

Re: [TF2] How to Get Saxxy Classname?
 
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.

PC Gamer 11-17-2019 21:46

Re: [TF2] How to Get Saxxy Classname?
 
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!


All times are GMT -4. The time now is 16:06.

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