Page 1 of 1
[CS:GO] Prevent team switch event
Posted: Mon Apr 23, 2018 11:09 am
by battleweaver
Syntax: Select all
from events.hooks import PreEvent, EventAction
from messages import SayText2
from players._base import Player
from players.helpers import index_from_userid
@PreEvent('player_team')
def on_player_team(event):
player = Player(index_from_userid(event['userid']))
SayText2('Detect player change team').send(player.index)
if event['isbot'] or event['disconnect']:
SayText2('Player is bot or disconnecting.').send(player.index)
return
if event['oldteam'] in [2, 3] and event['team'] in [2, 3]:
SayText2('Avoid changing team please.').send(player.index)
return EventAction.BLOCK
When I as a player press default "m", I change team. I get 'Avoid changing team please.' message in chat and team change event is commited. "teamchange_pending" and "switch_team" events are not triggered during process.
Re: [CS:GO] Prevent team switch event
Posted: Mon Apr 23, 2018 7:03 pm
by Ayuto
Is that a snippet for others to use or a question? And what exactly do you want to do? Block the player_team event or really block team changes? If it's the latter, you can use a
ClientCommandFilter.
Re: [CS:GO] Prevent team switch event
Posted: Tue Apr 24, 2018 4:16 am
by battleweaver
The snippet intends to show that I could not prevent the event of team switching.
Do you suggest filtering "teammenu" through ClientCommandFilter?
Re: [CS:GO] Prevent team switch event
Posted: Tue Apr 24, 2018 5:35 am
by Ayuto
Well, the event is blocked, but that doesn't change the actual team change. To do so you need to block the client commands jointeam and joinclass.
Re: [CS:GO] Prevent team switch event
Posted: Fri Jun 28, 2019 7:08 pm
by InvisibleSoldiers
Ayuto wrote:Is that a snippet for others to use or a question? And what exactly do you want to do? Block the player_team event or really block team changes? If it's the latter, you can use a
ClientCommandFilter.
Why do you recommend using ClientCommandFilter instead ClientCommand decorator?
Re: [CS:GO] Prevent team switch event
Posted: Fri Jun 28, 2019 8:32 pm
by L'In20Cible
InvisibleSoldiers wrote:Ayuto wrote:Is that a snippet for others to use or a question? And what exactly do you want to do? Block the player_team event or really block team changes? If it's the latter, you can use a
ClientCommandFilter.
Why do you recommend using ClientCommandFilter instead ClientCommand decorator?
Both should works, but using a filter would be the best approach here since the goal is to filter the command and not register a callback for it. I would say use a filter when you want to block existing commands, and use a command when you want to create a new command.
Re: [CS:GO] Prevent team switch event
Posted: Sat Jun 29, 2019 4:50 pm
by BackRaw
Syntax: Select all
from commands.client import ClientCommandFilter
from players.entity import Player
@ClientCommandFilter
def client_command_filter(command, index):
# Get the player entity
player = Player(index)
# Block 'jointeam'
if commmand[0] == 'jointeam':
# Get the team the player wants to join
team_choice = command[1]
if player.team in [2,3] and team_choice in ['2', '3']:
return False
Re: [CS:GO] Prevent team switch event
Posted: Sun Jun 30, 2019 4:42 pm
by Ayuto
I think you meant team_choice = int(command[1]) instead of team_choice = int(client_command[1]). However, I would simply compare it to strings instead of converting it to an integer, because otherwise a player could provoke an error using the client console. It wouldn't do any harm, but could be prevented.
Re: [CS:GO] Prevent team switch event
Posted: Fri Jul 05, 2019 3:09 pm
by BackRaw
Ayuto wrote:I think you meant team_choice = int(command[1]) instead of team_choice = int(client_command[1]). However, I would simply compare it to strings instead of converting it to an integer, because otherwise a player could provoke an error using the client console. It wouldn't do any harm, but could be prevented.
Very true. Thanks!