Stripping weapons
- L'In20Cible
- Project Leader
- Posts: 1533
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
Re: Stripping weapons
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.
Re: Stripping weapons
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
Re: Stripping weapons
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.
-
- Member
- Posts: 43
- Joined: Mon Oct 02, 2017 7:57 am
- Location: Moscow
- Contact:
Re: Stripping weapons
Hello everybody!
I am puzzled a little
This code works fine
While this code
What am I doing wrong?
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?
Re: Stripping weapons
Try delaying weapon dropping/removing. @OnButtonStateChanged listener is based on a hook on player's run_command. Removing entities while in a hook can lead to crashes. So try this:
Delaying by 0 seconds doesn't execute immediately. Your callback will still be executed in a regular tick-based flow. That means outside of hooks.
If you use Weapon class, it will force-drop the weapon automatically when you call .remove()
Syntax: Select all
weapon.delay(0, weapon.remove)
Delaying by 0 seconds doesn't execute immediately. Your callback will still be executed in a regular tick-based flow. That means outside of hooks.
If you use Weapon class, it will force-drop the weapon automatically when you call .remove()
![Image](https://i.imgur.com/JHTw1M6.png)
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam
Hail, Companion. [...] Hands to yourself, sneak thief.
![Image](https://i.imgur.com/Ibm81zR.png)
Re: Stripping weapons
In addition to what iPlayer said, I would like to add that you are doing a few redundant calls. "player.primary" already returns a Weapon instance (or None if the player has no primary). So, your scroll method should look like this:
Syntax: Select all
def scroll(self, player):
primary = player.primary
if primary is None:
return
primary.delay(0, primary.remove)
Return to “Code examples / Cookbook”
Who is online
Users browsing this forum: No registered users and 66 guests