TF2 - Event when team empty.
TF2 - Event when team empty.
I've looked for ages for a way to detect when RED team is empty, but to no avail. Is there any way I could do this, maybe through an event?
Re: TF2 - Event when team empty.
Try a combination of 2 events:
1) player_team - because a team might become empty due to somebody switching to another team
2) player_disconnect - because a team might become empty due to somebody disconnecting
This is the simpliest I could think of. Can be optimized by getting team len from team manager instead of iterating over PlayerIter. Also this guarantees to happen when team becomes empty, but can also happen when team is already empty!
1) player_team - because a team might become empty due to somebody switching to another team
2) player_disconnect - because a team might become empty due to somebody disconnecting
Syntax: Select all
from events import Event
from filters.players import PlayerIter
def check_teams():
if len(list(PlayerIter('red'))) == 0:
print("RED team is empty!!!")
@Event('player_disconnect')
def on_player_disconnect(game_event):
check_teams()
@Event('player_team')
def on_player_team(game_event):
check_teams()
This is the simpliest I could think of. Can be optimized by getting team len from team manager instead of iterating over PlayerIter. Also this guarantees to happen when team becomes empty, but can also happen when team is already empty!

My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam
Hail, Companion. [...] Hands to yourself, sneak thief.

Re: TF2 - Event when team empty.
If I remember correctly, player_team is fired when a player disconnects. In fact, there should be a 'disconnect' boolean event variable in player_team.
Re: TF2 - Event when team empty.
Yes, I guess you're right. Then it all simplifies to
Or, if you only need to fire it once,
Syntax: Select all
from events import Event
from filters.players import PlayerIter
@Event('player_team')
def on_player_team(game_event):
if len(list(PlayerIter('red'))) == 0:
print("RED team is empty!!!")
Or, if you only need to fire it once,
Syntax: Select all
from events import Event
from filters.players import PlayerIter
_was_non_zero = True
@Event('player_team')
def on_player_team(game_event):
global _was_non_zero
if len(list(PlayerIter('red'))) == 0:
if _was_non_zero:
print("RED team is empty!!!")
_was_non_zero = False
else:
_was_non_zero = True

My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam
Hail, Companion. [...] Hands to yourself, sneak thief.

Re: TF2 - Event when team empty.
thnx guys, this'll be helpful!
- L'In20Cible
- Project Leader
- Posts: 1536
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
Re: TF2 - Event when team empty.
Instead of counting the player everytime a switch occurs, we could simply make sure the player is leaving the RED team (which optimize quite a bit, imo):
However, I'm quite unsure if that event is called before or after m_iTeamNum has been updated for the player so this code may not works.
As a side note, you don't have to cast PlayerIter as a list in order to get its length since this is handled internally into _IterObject.__len__. So, len(PlayerIter('red')) should works just fine.
Syntax: Select all
from events import Event
@Event('player_team')
def player_team(game_event):
# If the player is not coming from the red team, that means the count
# didn't change...
if game_event.get_int('oldteam') != 2:
return
# Make sure he was the last player into the RED team...
if len(PlayerIter('red')):
return
print('RED team is empty!!!')
However, I'm quite unsure if that event is called before or after m_iTeamNum has been updated for the player so this code may not works.
As a side note, you don't have to cast PlayerIter as a list in order to get its length since this is handled internally into _IterObject.__len__. So, len(PlayerIter('red')) should works just fine.
Re: TF2 - Event when team empty.
As a side note, you don't have to cast PlayerIter as a list in order to get its length since this is handled internally into _IterObject.__len__
Yeah, wasn't sure if __len__ was implemented, so used list() to make sure.
Also, there's an entity with a classname team_manager, it might occur to be faster than counting players manually.

My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam
Hail, Companion. [...] Hands to yourself, sneak thief.

- L'In20Cible
- Project Leader
- Posts: 1536
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
Re: TF2 - Event when team empty.
Yes, I know about the cs_/tf_team_manager (CTeam instances) entities. But the offset where the length is stored is not mapped into the ServerClass nor the DataMap and I still prefer users to use a bit more CPU than having to constantly update the data files to keep it updated. 

- L'In20Cible
- Project Leader
- Posts: 1536
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
Re: TF2 - Event when team empty.
Actually, the players are mapped into an array which is networkable, wrapping it may give us the ability to count the element. However, our implementation doesn't allow for this currently and last time I checked, the bits/flags/etc of the SendProp needed to be verified as a case-by-case basis. I will put that on my to-do list, as we definitely have to get array implemented for entities (not just for temp entities).
Return to “Plugin Development Support”
Who is online
Users browsing this forum: No registered users and 123 guests