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

[TF2] GetPlayerWeaponSlot returning strange values...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
High Impact Dolphin
New Member
Join Date: Mar 2020
Old 03-28-2020 , 04:33   [TF2] GetPlayerWeaponSlot returning strange values...
Reply With Quote #1

I'm attempting to use the GetPlayerWeaponSlot function to get the index of a client's primary weapon, but it keeps passing back seemingly nonsensical values. Here's the block I'm using to test this:
Code:
public void TF2_OnConditionAdded(int client, TFCond addedCond) {
	int primaryIndex = GetPlayerWeaponSlot(client, TFWeaponSlot_Primary);
	char buffer[32];
	IntToString(revolverIndex, buffer, 32);
	PrintToServer(buffer);
}
So far, I've been handed 977 with the Diamondback and Ambassador, 975 with the stock revolver and the Cow Mangler, 975 (i think?) with the Machina, and 17 and 987 (either or) with the stock sniper rifle. I have no idea what these numbers mean or how I can make them consistent. I'm new to SP, and if anyone has some insight on how I'm misusing this function, please lend me a hand
High Impact Dolphin is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 03-28-2020 , 04:46   Re: [TF2] GetPlayerWeaponSlot returning strange values...
Reply With Quote #2

You don't have "revolverIndex" declared in this code, I guess it's a misprint from some other part.

Use:
PHP Code:
PrintToServer("Weapon entity: %i"primaryIndex); 
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 03-28-2020 , 14:24   Re: [TF2] GetPlayerWeaponSlot returning strange values...
Reply With Quote #3

Here's what I would use to get a weapon index for a weapon in the Primary weapon slot...

PHP Code:
TF2_SwitchtoSlot(client0);    

int weapon GetEntPropEnt(clientProp_Send"m_hActiveWeapon");
int weaponindex GetEntProp(weaponProp_Send"m_iItemDefinitionIndex");


stock void TF2_SwitchtoSlot(int clientint slot)
{
    if (
slot >= && slot <= && IsClientInGame(client) && IsPlayerAlive(client))
    {
        
char wepclassname[64];
        
int wep GetPlayerWeaponSlot(clientslot);
        if (
wep MaxClients && IsValidEdict(wep) && GetEdictClassname(wepwepclassnamesizeof(wepclassname)))
        {
            
FakeClientCommandEx(client"use %s"wepclassname);
            
SetEntPropEnt(clientProp_Send"m_hActiveWeapon"wep);
        }
    }

This forces the client to switch to a particular weapon slot and then gets the weapon index from the active weapon.
PC Gamer is offline
High Impact Dolphin
New Member
Join Date: Mar 2020
Old 03-28-2020 , 17:18   Re: [TF2] GetPlayerWeaponSlot returning strange values...
Reply With Quote #4

Quote:
Originally Posted by Dragokas View Post
You don't have "revolverIndex" declared in this code
That's what I get for trying to post at 3am, I guess

Also didn't realize that I'm getting back the entity index and not the weapon index, but that makes more sense

Quote:
Originally Posted by PC Gamer View Post
This forces the client to switch to a particular weapon slot and then gets the weapon index from the active weapon.
Implemented a version of this that caches the index on weapon equip. Thanks so much!
High Impact Dolphin 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:05.


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