[CSGO/ANY] Firing an event to a specific client

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
VinciT
Senior Member
Posts: 247
Joined: Thu Dec 18, 2014 2:41 am

[CSGO/ANY] Firing an event to a specific client

Postby VinciT » Mon Aug 31, 2020 2:11 am

In SourceMod, there's EventManager::FireEventToClient():

Syntax: Select all

void EventManager::FireEventToClient(EventInfo *pInfo, IClient *pClient)
{
// The IClient vtable is +sizeof(void *) from the IGameEventListener2 (CBaseClient) vtable due to multiple inheritance.
IGameEventListener2 *pGameClient = (IGameEventListener2 *)((intptr_t)pClient - sizeof(void *));
pGameClient->FireGameEvent(pInfo->pEvent);
}
I'm not really sure how to accomplish the same in SP. Any help would be greatly appreciated.
ImageImageImageImageImage
User avatar
L'In20Cible
Project Leader
Posts: 1369
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CSGO/ANY] Firing an event to a specific client

Postby L'In20Cible » Thu Sep 03, 2020 12:38 am

Syntax: Select all

from events.manager import game_event_manager
from memory import get_function_info
from players.entity import Player

pl = Player(1)

game_event = game_event_manager.create_event('player_death', True)
game_event.set_int('userid', pl.userid)

pl.base_client.make_virtual_function(
get_function_info('IGameEventListener2', 'FireGameEvent')
)(pl.base_client, game_event)


EDIT: Added <BaseClient/Player>.fire_game_event into be2de16 so the following will be possible within the next release:

Syntax: Select all

from events.manager import game_event_manager
from memory import get_function_info
from players.entity import Player

pl = Player(1)

game_event = game_event_manager.create_event('player_death', True)
game_event.set_int('userid', pl.userid)

pl.base_client.fire_game_event(game_event)


Or:

Syntax: Select all

from players.entity import Player

pl = Player(1)
pl.fire_game_event('player_death', userid=pl.userid)
User avatar
VinciT
Senior Member
Posts: 247
Joined: Thu Dec 18, 2014 2:41 am

Re: [CSGO/ANY] Firing an event to a specific client

Postby VinciT » Sat Sep 05, 2020 5:50 pm

Awesome! Thank you so much L'In20Cible!

A note though - I noticed that in SM, people usually cancel/free the event after sending it to specific clients. It has something to do with the FireEventToClient() not freeing the event handle. I'm guessing we should do the same?
ImageImageImageImageImage
User avatar
L'In20Cible
Project Leader
Posts: 1369
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CSGO/ANY] Firing an event to a specific client

Postby L'In20Cible » Sat Sep 05, 2020 10:08 pm

VinciT wrote:Awesome! Thank you so much L'In20Cible!

A note though - I noticed that in SM, people usually cancel/free the event after sending it to specific clients. It has something to do with the FireEventToClient() not freeing the event handle. I'm guessing we should do the same?

Ran some tests just now and the game event is being taken care of, unless the event failed to fire. For example, if I send too many events on the same frame, the client gets kicked with a reliable channel overflow and the server console spammed with "failed to send event" message and in such case the game event is indeed leaking. Added a free_event call to Player.fire_game_event to prevent leaks in those cases.
User avatar
VinciT
Senior Member
Posts: 247
Joined: Thu Dec 18, 2014 2:41 am

Re: [CSGO/ANY] Firing an event to a specific client

Postby VinciT » Mon Sep 07, 2020 9:16 pm

Sweet. Thank you again for adding this so quickly! :smile:
ImageImageImageImageImage

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 16 guests