Page 1 of 1

Weapons

Posted: Sat Aug 18, 2018 10:19 pm
by velocity
I'm trying to make the player switch weapons

Syntax: Select all

@SayCommand('!knife')
def sayHintText(say, index, team_only=None):
p = Player(index)
p.set_active_weapon(Weapon('weapon_knife'))


But I get an error

Code: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
  File "..\addons\source-python\packages\source-python\commands\auth.py", line 44, in __call__
    return self.callback(*args)
  File "..\addons\source-python\plugins\t\t.py", line 72, in sayHintText
    p.set_active_weapon(Weapon('weapon_knife'))
  File "..\addons\source-python\packages\source-python\entities\_base.py", line 94, in __init__
    super().__init__(index)

Boost.Python.ArgumentError: Python argument types in
    BaseEntity.__init__(Weapon, str)
did not match C++ signature:
    __init__(class boost::python::api::object, unsigned int entity_index)

Re: Weapons

Posted: Sat Aug 18, 2018 10:38 pm
by satoon101
The weapon class inherits from the Entity class. It requires an index, not a string.

Syntax: Select all

@SayCommand('!knife')
def sayHintText(say, index, team_only=None):
player = Player(index)
weapon = player.get_weapon('weapon_knife')
if weapon is not None:
player.active_weapon = weapon


I think there is also a client command you can call in your plugin which will change their weapon based on the weapon string, but I don't remember it off hand.

Re: Weapons

Posted: Sun Aug 19, 2018 2:09 am
by L'In20Cible
satoon101 wrote:I think there is also a client command you can call in your plugin which will change their weapon based on the weapon string, but I don't remember it off hand.

If I remember correctly, that would be the following command:

Syntax: Select all

player.client_command('use weapon_knife', server_side=True)