Stripping weapons

Post Python examples to help other users.
User avatar
L'In20Cible
Project Leader
Posts: 1016
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Stripping weapons

Postby L'In20Cible » Mon Dec 04, 2017 2:44 am

You should probably call drop_weapon() prior remove() tho so the weapons are no longer mapped in the m_hMyWeapons array for that player. Doesn't matter for Source.Python because we ensure the handles are valid, but other plugins might not and attempt to manipulate them.
User avatar
satoon101
Project Leader
Posts: 2452
Joined: Sat Jul 07, 2012 1:59 am

Re: Stripping weapons

Postby satoon101 » Mon Dec 04, 2017 3:07 am

L'In20Cible wrote:You should probably call drop_weapon() prior remove() tho so the weapons are no longer mapped in the m_hMyWeapons array for that player.

Don't forget, as long as you are using Weapon instances, it will do the drop automatically:
https://github.com/Source-Python-Dev-Te ... 6f77f651bc
Image
User avatar
BackRaw
Senior Member
Posts: 474
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Re: Stripping weapons

Postby BackRaw » Mon Dec 04, 2017 3:45 am

BackRaw wrote: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?
Ayuto wrote:No, iterating over the player's weapons and removing them is perfectly fine.

Alright cool.
battleweaver
Junior Member
Posts: 26
Joined: Mon Oct 02, 2017 7:57 am
Location: Moscow
Contact:

Re: Stripping weapons

Postby battleweaver » Tue Dec 12, 2017 1:44 pm

Hello everybody!
I am puzzled a little
This code works fine

Syntax: Select all

@TypedSayCommand('!strip')
def cmd_on_strip(command_info):
player = Player(command_info.index)
weapon = Weapon((player.primary).index) # TODO: BaseEntity would be enough here?
player.drop_weapon(weapon.pointer, Vector(0, 0, 0), Vector(0, 0, 0))
weapon.remove()


While this code

Syntax: Select all

backpack = Backpack()

@OnButtonStateChanged
def on_buttons_state_changed(player, old_buttons, new_buttons):
status = get_button_combination_status(old_buttons, new_buttons,
PlayerButtons.DUCK|PlayerButtons.USE)
if status == ButtonStatus.PRESSED:
backpack.scroll(Player(player.index))

class Backpack:

def scroll(self, player):
#getting rid of weapon in hand
weapon = Entity((player.primary).index) # Tried Weapon and Entity class
print (f'Going to drop {weapon.weapon_name}')
player.drop_weapon(weapon.pointer, Vector(0, 0, 0), Vector(0, 0, 0)) #SEGMENTATION FAULT at this very line, server reboot
print ('Dropped weapon')
weapon.remove()#If I comment 2 lines above,SEGMENTATION FAULT here!
print ('Removed weapon")
#end of fragment

What am I doing wrong?

Return to “Code examples / Cookbook”

Who is online

Users browsing this forum: iPlayer and 2 guests