Page 1 of 1

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

Posted: Mon Aug 31, 2020 2:11 am
by VinciT
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.

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

Posted: Thu Sep 03, 2020 12:38 am
by L'In20Cible

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)

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

Posted: Sat Sep 05, 2020 5:50 pm
by VinciT
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?

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

Posted: Sat Sep 05, 2020 10:08 pm
by L'In20Cible
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.

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

Posted: Mon Sep 07, 2020 9:16 pm
by VinciT
Sweet. Thank you again for adding this so quickly! :smile: