[CS:GO] Prevent team switch event

Please post any questions about developing your plugin here. Please use the search function before posting!
battleweaver
Member
Posts: 43
Joined: Mon Oct 02, 2017 7:57 am
Location: Moscow
Contact:

[CS:GO] Prevent team switch event

Postby battleweaver » Mon Apr 23, 2018 11:09 am

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.
User avatar
Ayuto
Project Leader
Posts: 2023
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: [CS:GO] Prevent team switch event

Postby Ayuto » Mon Apr 23, 2018 7:03 pm

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.
battleweaver
Member
Posts: 43
Joined: Mon Oct 02, 2017 7:57 am
Location: Moscow
Contact:

Re: [CS:GO] Prevent team switch event

Postby battleweaver » Tue Apr 24, 2018 4:16 am

The snippet intends to show that I could not prevent the event of team switching.
Do you suggest filtering "teammenu" through ClientCommandFilter?
User avatar
Ayuto
Project Leader
Posts: 2023
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: [CS:GO] Prevent team switch event

Postby Ayuto » Tue Apr 24, 2018 5:35 am

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.
InvisibleSoldiers
Junior Member
Posts: 2
Joined: Fri Mar 15, 2019 6:08 am

Re: [CS:GO] Prevent team switch event

Postby InvisibleSoldiers » Fri Jun 28, 2019 7:08 pm

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?
User avatar
L'In20Cible
Project Leader
Posts: 1165
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CS:GO] Prevent team switch event

Postby L'In20Cible » Fri Jun 28, 2019 8:32 pm

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.
User avatar
BackRaw
Senior Member
Posts: 527
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Re: [CS:GO] Prevent team switch event

Postby BackRaw » Sat Jun 29, 2019 4:50 pm

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
Last edited by BackRaw on Fri Jul 05, 2019 3:10 pm, edited 2 times in total.
User avatar
Ayuto
Project Leader
Posts: 2023
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: [CS:GO] Prevent team switch event

Postby Ayuto » Sun Jun 30, 2019 4:42 pm

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.
User avatar
BackRaw
Senior Member
Posts: 527
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Re: [CS:GO] Prevent team switch event

Postby BackRaw » Fri Jul 05, 2019 3:09 pm

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!

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 8 guests