Stripping weapons

Post Python examples to help other users.
qazuar
Junior Member
Posts: 16
Joined: Fri Jun 20, 2014 9:05 am

Postby qazuar » Mon Sep 29, 2014 1:03 pm

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

Postby L'In20Cible » Mon Sep 29, 2014 1:14 pm

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.
qazuar
Junior Member
Posts: 16
Joined: Fri Jun 20, 2014 9:05 am

Postby qazuar » Mon Sep 29, 2014 2:38 pm

Very true, but in the post before mine he claims he can make it work, so i was just wondering.
User avatar
L'In20Cible
Project Leader
Posts: 1534
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Mon Sep 29, 2014 3:00 pm

Probably different games.
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Postby 8guawong » Mon Sep 29, 2014 4:08 pm

qazuar wrote:Very true, but in the post before mine he claims he can make it work, so i was just wondering.


are you refering to me??

drop weapon works for me
remove also works

csgo on linux
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Mon Sep 29, 2014 6:12 pm

L'In20Cible wrote:Probably different games.
or operating system.
DJiSer
Junior Member
Posts: 20
Joined: Sat May 10, 2014 2:44 pm

Postby DJiSer » Sun Dec 21, 2014 9:36 pm

When i take enemy's weapon and trying to drop it:

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

Postby L'In20Cible » Sun Dec 21, 2014 9:50 pm

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

Postby satoon101 » Sun Dec 21, 2014 10:04 pm

As for the signatures, when the entities_changes are complete, we won't be using those signatures anyway, as both of those functions can be gotten by virtual offset instead. Also, as in another thread, CS:GO's GiveNamedItem takes another argument which we have yet to fully explore.
Image
User avatar
Mahi
Senior Member
Posts: 236
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

Postby Mahi » Thu Mar 05, 2015 4:41 pm

Is it possible to restrict a weapon completely? Like, to prevent a player for picking it up in the first place?
User avatar
satoon101
Project Leader
Posts: 2698
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Thu Mar 05, 2015 4:44 pm

Yes, you can hook touch (can't remember the full function name) to stop it. I intend to create a weapon restrict mod that will also handle purchasing weapons.
Image
User avatar
L'In20Cible
Project Leader
Posts: 1534
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Thu Mar 05, 2015 6:11 pm

The easiest function to hook is CCSPlayer::BumpWeapon.
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Postby decompile » Sat Dec 19, 2015 12:01 pm

Is there an easier way of stripping a player completly?
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Postby iPlayer » Sat Dec 19, 2015 12:21 pm

1st approach. This strips all weapons from a player:

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.
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Postby decompile » Sun Dec 20, 2015 11:42 pm

Sounds good.. How can i use the player_weaponstrip Entity? Is it just Firing the Entity On the given player?
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Postby iPlayer » Mon Dec 21, 2015 4:19 am

I believe this way

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

Postby satoon101 » Mon Dec 21, 2015 11:50 am

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()
Image
User avatar
rocco
Junior Member
Posts: 5
Joined: Thu Jun 29, 2017 5:56 am

Re: Stripping weapons

Postby rocco » Mon Oct 16, 2017 5:39 pm

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.
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Re: Stripping weapons

Postby BackRaw » Sun Dec 03, 2017 8:09 pm

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?
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Stripping weapons

Postby Ayuto » Sun Dec 03, 2017 8:19 pm

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 8 guests