Css bombplant site get

Please post any questions about developing your plugin here. Please use the search function before posting!
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Css bombplant site get

Postby cssbestrpg » Thu Sep 24, 2020 4:58 pm

Hi

Some reason i can't get bombsite show at bombplant event

Console just spamms this:

Code: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
  File "..\addons\source-python\packages\source-python\events\listener.py", line 92, in fire_game_event
    callback(game_event)
  File "..\addons\source-python\plugins\rpg\rpg.py", line 2372, in bomb_planted
    site = args.get_short('site')

AttributeError: 'GameEvent' object has no attribute 'get_short'


The code:

Syntax: Select all

@Event('bomb_planted')
def bomb_planted(args):
userid = args.get_int('userid')
site = args.get_short('site')
for i in rpglib.getUseridList():
rpglib.tell(i, 'Bombsite %s' % (site))
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: Css bombplant site get

Postby VinciT » Thu Sep 24, 2020 6:02 pm

Even though the events page says the site attribute is a short, you retrieve its value by using get_int():

Syntax: Select all

@Event('bomb_planted')
def bomb_planted(args):
site = args.get_int('site')
print(f'bomb site index: {site}')
An easier way to get this value and not worry about its type would be:

Syntax: Select all

site = args['site']
ImageImageImageImageImage
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: Css bombplant site get

Postby cssbestrpg » Fri Sep 25, 2020 9:55 am

Oh, i thought it would show bombsite where bomb is planted, like if plants A bombsite it would show its A the bombsite
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Css bombplant site get

Postby L'In20Cible » Fri Sep 25, 2020 10:25 am

cssbestrpg wrote:Oh, i thought it would show bombsite where bomb is planted, like if plants A bombsite it would show its A the bombsite

Syntax: Select all

from entities.entity import Entity
from events import Event

@Event('bomb_planted')
def bomb_planted(game_event):
try:
site = Entity(game_event['site'])
except ValueError:
return

manager = Entity.find('cs_player_manager')
if manager is None:
return

mins, maxs = site.mins, site.maxs
if manager.get_network_property_vector('m_bombsiteCenterA').is_within_box(mins, maxs):
print('The bomb was planted at A')
elif manager.get_network_property_vector('m_bombsiteCenterB').is_within_box(mins, maxs):
print('The bomb was planted at B')
else:
print('The bomb was planted somewhere')
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: Css bombplant site get

Postby cssbestrpg » Fri Sep 25, 2020 1:29 pm

Thanks L'In20Cible, the code you gave works perfectly

Return to “Plugin Development Support”

Who is online

Users browsing this forum: Bing [Bot] and 25 guests