-
Notifications
You must be signed in to change notification settings - Fork 36
Description
ive asked something like this a while back in the forums and didnt get an answer. ive encountered the same problem again today, so i wanted to bring it to attention again.
my goal is to read the name of a players weapon. especially for exceptions like usp/p2000,m4a1/m4a1s etc..
ive found, that the most convenient way, might be to expand source pythons' weapon class for csgo to return a weapons name..
so ive added to "source-python\weapons\engines\csgo__init__.py":
from filters.weapons import WeaponIter
# =============================================================================
# >> CLASSES
# =============================================================================
wn_exceptions = {"models/weapons/v_rif_m4a1_s.mdl":"m4a1_silencer","models/weapons/v_rif_m4a1.mdl":"m4a1","models/weapons/v_pist_223.mdl":"usp_silencer","models/weapons/v_pist_hkp2000.mdl":"p2000","models/weapons/v_pist_revolver.mdl":"revolver","models/weapons/v_pist_deagle.mdl":"deagle","models/weapons/v_pist_cz_75.mdl":"cz75aw","models/weapons/v_pist_fiveseven.mdl":"fiveseven","models/weapons/v_pist_tec9.mdl":"tec9"}
class Weapon(_Weapon):
"""Allows easy usage of the weapon's attributes."""
def get_name(self):
"""Return the name of the player weapon."""
name = weapon_manager[self.classname].basename
if name in ("hkp2000","m4a1"):
player = self._validate_ammo()
for weapon in WeaponIter():
if player.inthandle == weapon.get_property_int("m_hOwner"):
if name in weapon.get_property_string_pointer("m_iClassname"):
return wn_exceptions[weapon.get_property_string_pointer("m_ModelName")]
return weapon_manager[self.classname].basename
this is not very efficient, but i couldnt find a distinguished int-identifier/handle.. maybe someone with insight into all the sp files, could jump onto this and maybe have a better solution for this issue..
testcode:
player.active_weapon.get_name()
UPDATE:
preferably the "weapon_" prefix could be added into the return in conjunction with "give_named_item"-calls for example