So the issue I've run into is not present on Windows CS:S, only on Linux SRCDS.
The following code
Syntax: Select all
from entities.entity import Entity
from entities.hooks import EntityCondition, EntityPreHook
from events import Event
from memory import make_object
from players.entity import Player
from players.helpers import index_from_userid
from mathlib import NULL_VECTOR
def strip(player):
for index in player.weapon_indexes():
weapon = Entity(index)
print("Dropping {}".format(weapon.classname))
player.drop_weapon(weapon.pointer, NULL_VECTOR, NULL_VECTOR)
print("Dropped successfully.")
weapon.remove()
@Event('player_jump')
def on_player_jump(game_event):
player = Player(index_from_userid(game_event['userid']))
strip(player)
@EntityPreHook(EntityCondition.is_player, 'on_take_damage')
def on_take_damage(args):
player = make_object(Player, args[0])
strip(player)
should strip player's weapons in 2 cases:
a. They jump (just to prove that stripping weapons works)
b. They take damage
So stripping the weapons during jumping event works fine.
Stripping the weapons in on_take_damage pre-hook works fine too, but only on Windows. On Linux it crashes between those two print statements. And it's not getting weapon's pointer, I checked that too, it specifically crashes on drop_weapon.
What I'm trying to do though is a pretty simple thing - I need to strip player's weapons on their death, and I'm the reason they die - I set TakeDamageInfo's damage attribute higher than their health. And I'm dead set against using events instead of OnTakeDamage hook because I may need to cancel the function from executing.
If there's no way this thing won't crash on Linux, I guess I'll need to save player's weapons indexes before they die, then catch player_death and remove these weapons by the saved indexes.