Stripping weapons
I would really like to know how you can make the player drop the weapon because im getting this:
Unable to add attribute 'drop_weapon'of type 'functions' to entity type 'player'
due to the following:
Could not find signature.
[SP] Caught an Exception:
Traceback (most recent call last):
File '..\addons\source-python\packages\source-python\events\listener.py', line
90, in fire_game_event
callback(game_event)
File '..\addons\source-python\plugins\weaponrestrict\weaponrestrict.py', line
56, in item_pickup
player.drop_weapon(weapon.pointer, True, True)
File '..\addons\source-python\packages\source-python\entities\entity.py', line
114, in __getattr__
raise AttributeError('Attribute '{0}' not found'.format(attr))
AttributeError: Attribute 'drop_weapon' not found
Unable to add attribute 'drop_weapon'of type 'functions' to entity type 'player'
due to the following:
Could not find signature.
[SP] Caught an Exception:
Traceback (most recent call last):
File '..\addons\source-python\packages\source-python\events\listener.py', line
90, in fire_game_event
callback(game_event)
File '..\addons\source-python\plugins\weaponrestrict\weaponrestrict.py', line
56, in item_pickup
player.drop_weapon(weapon.pointer, True, True)
File '..\addons\source-python\packages\source-python\entities\entity.py', line
114, in __getattr__
raise AttributeError('Attribute '{0}' not found'.format(attr))
AttributeError: Attribute 'drop_weapon' not found
- L'In20Cible
- Project Leader
- Posts: 1534
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
Signature is outdated.
Code: Select all
Unable to add attribute 'drop_weapon'of type 'functions' to entity type 'player'
due to the following:
Could not find signature.
- L'In20Cible
- Project Leader
- Posts: 1534
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
When i take enemy's weapon and trying to drop it:
CS:GO, Linux
Also CS:GO windows signatures for drop_weapon and give_named_item is outdated.
Code: Select all
File '../addons/source-python/plugins/restrict/restrict.py', line 83, in drop
for weapon_index in player.weapon_indexes(not_filters='knife'):
File '../addons/source-python/packages/source-python/players/weapons/__init__.py', line 355, in weapon_indexes
index = index_from_inthandle(handle)
ValueError: Conversion failed...
CS:GO, Linux
Also CS:GO windows signatures for drop_weapon and give_named_item is outdated.
- L'In20Cible
- Project Leader
- Posts: 1534
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
I explained why this is happening here. Update your ../addons/source-python/packages/source-python/players/weapons/__init__.py to the lastest version and this should be fixed.
- L'In20Cible
- Project Leader
- Posts: 1534
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
1st approach. This strips all weapons from a player:
player here is a PlayerEntity. Also don't forget to import:
Dropping weapons is necessary, too. If you just remove it, it still remains in player's weapons props, later raising exceptions on every attempt to work with the player's weapons.
2nd approach: since you're stripping all weapons, you could just use a player_weaponstrip entity.
I believe, the 1st approach is a subject to change when they release new player/weapon libs.
Syntax: Select all
for index in player.weapon_indexes():
weapon = Entity(index) # TODO: BaseEntity would be enough here?
player.drop_weapon(weapon.pointer, Vector(0, 0, 0), Vector(0, 0, 0))
weapon.remove()
player here is a PlayerEntity. Also don't forget to import:
Syntax: Select all
from mathlib import Vector
from entities.entity import Entity
Dropping weapons is necessary, too. If you just remove it, it still remains in player's weapons props, later raising exceptions on every attempt to work with the player's weapons.
2nd approach: since you're stripping all weapons, you could just use a player_weaponstrip entity.
I believe, the 1st approach is a subject to change when they release new player/weapon libs.
I believe this way
The key moment here is that the player must be an activator
Syntax: Select all
entity = Entity.create('player_weaponstrip')
entity.call_input("Strip", activator=player.index)
entity.remove()
The key moment here is that the player must be an activator
Just a quick note. I added CStripWeapons to the entity data, so now that could just be:
Syntax: Select all
entity = Entity.create('player_weaponstrip')
entity.strip(activator=player.index)
entity.remove()
Re: Stripping weapons
I'm going to have to spend some time on this. For HL2DM, I want to strip all but some weapons from all players who join for certain maps. Example Only for specific map dm_killbox_crossbow_big.bsp might only have crossbows available for the duration of the map level, all other weapons are stripped until the next map level.
Re: Stripping weapons
Does the player_weaponstrip entity has any benefits over calling weapon.remove()? What about iterating over the player's weapons and calling .remove() each time? Or is it just that the weapon filters are more flexible?
Re: Stripping weapons
No, iterating over the player's weapons and removing them is perfectly fine.
Return to “Code examples / Cookbook”
Who is online
Users browsing this forum: No registered users and 2 guests