Weapons

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
velocity
Senior Member
Posts: 134
Joined: Sat May 10, 2014 6:17 pm

Weapons

Postby velocity » Sat Aug 18, 2018 10:19 pm

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)
User avatar
satoon101
Project Leader
Posts: 2578
Joined: Sat Jul 07, 2012 1:59 am

Re: Weapons

Postby satoon101 » Sat Aug 18, 2018 10:38 pm

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.
Image
User avatar
L'In20Cible
Project Leader
Posts: 1094
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Weapons

Postby L'In20Cible » Sun Aug 19, 2018 2:09 am

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)

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 3 guests