Situation:
CS:GO
I have a data structure {uniqueID : weapon_entity}, which I recieve from, say, outer space.
During the match i want to organize some sort of inventory. The prototype instance of my inventory is dict (player_id : [weapon entities he has ]).
I add weapon entites to inventory by touching them.
Some code.
Ripped from "game flow description" script
Syntax: Select all
backpack = Backpack()
#this part is about creating the set of dictionary keys
@Event('round_start')
def on_round_start(game_event):
#weapon_spawn() #created weapon entities on map
for player in PlayerIter():
backpack.add_player(index_from_userid(player.userid))
@Event('player_connect_full')
def on_player_connected(game_event):
playerID = index_from_userid(game_event['userid'])
backpack.add_player(playerID)
#the sweetest part: inventory dictionary values
@EntityPreHook(EntityCondition.equals_entity_classname(*weapon_index.keys()), 'start_touch')
def pre_start_touch(stack):
weapon = make_object(Weapon, stack[0])
#print(f'----------------------------------')
#print (f'{weapon.classname} is touched')
if weapon.classname in weapon_index.keys():
other = make_object(Entity, stack[1])
if other.is_player():
player = make_object(Player, stack[1])
print(f'Weapon {weapon.classname} was touched by {other.classname}\n')
backpack.add_item(player, weapon)
#weapon.remove() #this thing crushes server
Backpack()
Syntax: Select all
from messages import SayText2
from players._base import Player
from players.helpers import index_from_userid
from steam import SteamID
class Backpack:
def __init__(self):
self.primary_weap_dict = dict()
def add_player(self, playerID):
self.primary_weap_dict[SteamID.parse(Player(playerID).steamid).to_uint64()] = list()
print('Player added')
def add_item(self, player, item):
player_id = SteamID.parse(player.steamid).to_uint64()
player_index = index_from_userid(player.userid)
self.primary_weap_dict[player_id].append(item)
print('Item added')
SayText2(f'{player_id} has {list (map(lambda weapon: weapon.classname),self.primary_weap_dict[player_id])}').send(player_index)
To the point: when I want to pick up a weapon, I should remove it from the map. If I destroy the weapon_entity entirely, how to signal to my first data structure that something happened to the weapon_entity? OR Is there a way to reverse the spawn() method of an entity?