CS:GO giving weapons weird problem
Posted: Wed Oct 01, 2014 8:30 pm
Hi,
I'm currently trying to find out how to give weapons propery in CS:GO. I use this code:
And this code to execute it:
Most of the time the players receive their flashbangs, but sometimes they don't. They just walk around without any gun and there's no error in the console. What am I doing wrong?
I'm currently trying to find out how to give weapons propery in CS:GO. I use this code:
Syntax: Select all
from players.entity import PlayerEntity
class _Player(PlayerEntity):
# __init__(self, index) ...
def on_spawn(self):
self.cash = 0
self.armor = 0
self.equip(True)
def equip(self, strip=False):
"""
Checks the player if they're already equipped before giving them another flashbang grenade.
"""
# are we dead?
if self.isdead:
# if yes, no need to go further
return
# is stripping forced or do we already have at least one flashbang?
if strip or self.get_prop_int("m_iAmmo.012"):
# if yes, strip the player after a tick
tick_delays.delay(0, self._strip)
# equip the player after two ticks
tick_delays.delay(0.1 if strip else 0, self._equip)
def _equip(self):
# create the weapon_flashbang entity
flashbang = BaseEntity(server_tools.create_entity("weapon_flashbang"))
# set its origin to the player's location
flashbang.set_key_value_vector("origin", self.location)
# spawn it
server_tools.spawn_entity(flashbang.index)
def _strip(self):
"""
Strip the player off their weapons and items.
"""
# loop through all weapons the player currently carries
try:
for weapon in map(BaseEntity, self.weapon_indexes()):
# set its hammerid to its index (CS:GO crash fix)
weapon.set_key_value_int("hammerid", weapon.index)
# remove it
server_tools.remove_entity(weapon.index)
except ValueError:
# if the index_from_inthandle() converison failed, the console would be spammed with the error
# so just pass here to not spam the console
pass
# _Player objects are held in a player_manager dict
And this code to execute it:
Syntax: Select all
from events import Event
from flashfunsp.players import player_manager # dict that holds _Player objects
@Event
def flashbang_detonate(game_event):
"""
Gets called whenever a flashbang grenade detonates.
"""
# get the player's _Player instance
player = player_manager[game_event.get_int("userid")]
# were we successful?
if not player is None:
# give the player another one after a tick
player.equip()
@Event
def player_spawn(game_event):
"""
Gets called whenever a player entity spawns on the server (doesn't necessarily mean 'physically')
"""
# grab the player object
player = player_manager[game_event.get_int("userid")]
# were we successful and are we on a team?
if not player is None and player.team > 1:
# if yes, call the _Player instance's on_spawn() method
player.on_spawn()
Most of the time the players receive their flashbangs, but sometimes they don't. They just walk around without any gun and there's no error in the console. What am I doing wrong?