Raised This Month: $64 Target: $400
 16% 

Solved [CSGO] Possible to get the Weapon Name from Weapon ID? (Not Classname!)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Muhlex
Junior Member
Join Date: Mar 2019
Old 05-26-2019 , 19:03   [CSGO] Possible to get the Weapon Name from Weapon ID? (Not Classname!)
Reply With Quote #1

As CS:GO has weapons that share the same classname (the one's that are in the same inventory slot), for example the P2000 and USP-S (weapon_hkp2000, weapon_usp_silencer), I am now looking for a way to get the actual weapon name from a weapon's ID.

I tested getting various EntProps but all i found working was the Classname via m_iClassname once again. The only function i know is GetClientWeapon of the clients.inc include. But this always gets the currently active weapon from a player and doesn't allow me to check weapons that are not currently equipped.
How can I do that?

Last edited by Muhlex; 05-28-2019 at 08:33.
Muhlex is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 05-27-2019 , 05:08   Re: [CSGO] Possible to get the Weapon Name from Weapon ID? (Not Classname!)
Reply With Quote #2

Quote:
Originally Posted by Muhlex View Post
As CS:GO has weapons that share the same classname (the one's that are in the same inventory slot), for example the P2000 and USP-S (weapon_hkp2000, weapon_usp_silencer), I am now looking for a way to get the actual weapon name from a weapon's ID.

I tested getting various EntProps but all i found working was the Classname via m_iClassname once again. The only function i know is GetClientWeapon of the clients.inc include. But this always gets the currently active weapon from a player and doesn't allow me to check weapons that are not currently equipped.
How can I do that?
https://sm.alliedmods.net/new-api/cs...eaponIDToAlias

If you give it CSWeapon_AWP, it'll put "awp" in buffer. CSWeapon_HKP2000, "hpk2000"

Just use Format(buffer, len, "weapon_%s", buffer); to convert alias into classname
__________________
Accepting private work. Contact me if you're interested.
If you like my work, feel free to donate in appreciation with PayPal or CSGO Skins.

Total Donated: 10$
eyal282 is online now
Muhlex
Junior Member
Join Date: Mar 2019
Old 05-27-2019 , 05:46   Re: [CSGO] Possible to get the Weapon Name from Weapon ID? (Not Classname!)
Reply With Quote #3

Quote:
Originally Posted by eyal282 View Post
https://sm.alliedmods.net/new-api/cs...eaponIDToAlias

If you give it CSWeapon_AWP, it'll put "awp" in buffer. CSWeapon_HKP2000, "hpk2000"
Thanks a lot for the reply. However I meant to use the Entity Index of the weapon (called it weapon ID by mistake) and get the name from there.

Basically what I want to do is check a player's secondary slot for which weapon he has. E.g. "weapon_deagle". I could use GetPlayerWeaponSlot(client, 1) and then GetEntityClassname on the result. Would work like a charm if it didn't return weapon_hkp2000 for the USP-S for example.

I checked the documentation for a way to get the CSWeaponID from the weapon entity, so that I could use your solution. Didn't find anything though.

Last edited by Muhlex; 05-27-2019 at 05:46.
Muhlex is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 05-27-2019 , 06:11   Re: [CSGO] Possible to get the Weapon Name from Weapon ID? (Not Classname!)
Reply With Quote #4

https://sm.alliedmods.net/new-api/cs...ToItemDefIndex

Try turning the weapon ID into a defindex and use

GetEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex");

See if definition index changes with weapon used. Also, check if a weapon skin affects itemdefindex ( just compare with the free skins you get from Casual.
__________________
Accepting private work. Contact me if you're interested.
If you like my work, feel free to donate in appreciation with PayPal or CSGO Skins.

Total Donated: 10$

Last edited by eyal282; 05-27-2019 at 06:11.
eyal282 is online now
Muhlex
Junior Member
Join Date: Mar 2019
Old 05-27-2019 , 06:50   Re: [CSGO] Possible to get the Weapon Name from Weapon ID? (Not Classname!)
Reply With Quote #5

So I now built this:

PHP Code:
int iWeapon GetPlayerWeaponSlot(iClient1);
int iWeaponItemDefIndex GetEntProp(iWeaponProp_Send"m_iItemDefinitionIndex");

CSWeaponID cswWeaponToCheck CS_AliasToWeaponID("weapon_usp_silencer");
int iWeaponToCheckItemDefIndex CS_WeaponIDToItemDefIndex(cswWeaponToCheck);

if (
iWeaponItemDefIndex == iWeaponToCheckItemDefIndex)
{
  
// SUCCESS

Which actually seems to work flawlessly. Every weapon has it's own ItemDefIndex that skins don't seem to change.

Thanks a lot. Will report if I have more time to test and if it doesn't work in some case.
Muhlex is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 05-28-2019 , 05:05   Re: [CSGO] Possible to get the Weapon Name from Weapon ID? (Not Classname!)
Reply With Quote #6

Quote:
Originally Posted by Muhlex View Post
So I now built this:

PHP Code:
int iWeapon GetPlayerWeaponSlot(iClient1);
int iWeaponItemDefIndex GetEntProp(iWeaponProp_Send"m_iItemDefinitionIndex");

CSWeaponID cswWeaponToCheck CS_AliasToWeaponID("weapon_usp_silencer");
int iWeaponToCheckItemDefIndex CS_WeaponIDToItemDefIndex(cswWeaponToCheck);

if (
iWeaponItemDefIndex == iWeaponToCheckItemDefIndex)
{
  
// SUCCESS

Which actually seems to work flawlessly. Every weapon has it's own ItemDefIndex that skins don't seem to change.

Thanks a lot. Will report if I have more time to test and if it doesn't work in some case.

Mark the thread as solved so people who google the question can instantly see that it's working.
__________________
Accepting private work. Contact me if you're interested.
If you like my work, feel free to donate in appreciation with PayPal or CSGO Skins.

Total Donated: 10$
eyal282 is online now
Muhlex
Junior Member
Join Date: Mar 2019
Old 05-28-2019 , 08:31   Re: [CSGO] Possible to get the Weapon Name from Weapon ID? (Not Classname!)
Reply With Quote #7

Thanks for the reminder, missed to do that.

Gonna leave this code here, which will get the actual weapon name/alias from a weapon entity index for CSGO (and probably CSS):
PHP Code:
#include <cstrike>

char szWeaponName[33];

int iItemDefIndex GetEntProp(iWeaponProp_Send"m_iItemDefinitionIndex");
CS_WeaponIDToAlias(CS_ItemDefIndexToID(iItemDefIndex), szWeaponNamesizeof(szWeaponName); 
One might want to add the "weapon_" prefix.
PHP Code:
Format(szWeaponNamesizeof(szWeaponName), "weapon_%s"szWeaponName); 
Muhlex 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 09:20.


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