playeriter to count the number or pending team change

Please post any questions about developing your plugin here. Please use the search function before posting!
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

playeriter to count the number or pending team change

Postby 8guawong » Sun Oct 05, 2014 7:08 am

argh csgo is so stupid
after you choose to switch team your teamid still stay on the old team
so is it possible for playeriter to include a filter that includes the pending team change??

example: 1 T and 2 CT

1 CT decided to change team to T
len(PlayerIter('t')) == 1 --> should be 2 since one of the CT decided to join T

after next round starts
len(PlayerIter('t')) == 2
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Sun Oct 05, 2014 7:35 am

I don't think adding that to PlayerIter is a good idea cause well, while it is pending, you are "still" in your current team... Also, you can always check that yourself.

Syntax: Select all

from filters.players import PlayerIter
from players.entity import PlayerEntity

def get_players_in_or_pending_team(team_index):
# Loop through all players' index/edict instance...
for player_index, player_edict in PlayerIter(
return_types=['index', 'edict']):

# Is the player team not matching the given one?
if (player_edict.get_prop_int('m_iTeamNum') != team_index and

# Is the player pending team not matching the given one?
player_edict.get_prop_int('m_iPendingTeamNum') != team_index):

# If so, no need to go further...
continue

# Get a PlayerEntity instance from the current index and yield it...
yield PlayerEntity(player_index)
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Postby 8guawong » Sun Oct 05, 2014 8:23 am

L'In20Cible wrote:I don't think adding that to PlayerIter is a good idea cause well, while it is pending, you are "still" in your current team... Also, you can always check that yourself.

Syntax: Select all

from filters.players import PlayerIter
from players.entity import PlayerEntity

def get_players_in_or_pending_team(team_index):
# Loop through all players' index/edict instance...
for player_index, player_edict in PlayerIter(
return_types=['index', 'edict']):

# Is the player team not matching the given one?
if (player_edict.get_prop_int('m_iTeamNum') != team_index and

# Is the player pending team not matching the given one?
player_edict.get_prop_int('m_iPendingTeamNum') != team_index):

# If so, no need to go further...
continue

# Get a PlayerEntity instance from the current index and yield it...
yield PlayerEntity(player_index)


could you show me an example how i would use this in a script?
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Sun Oct 05, 2014 8:26 am

Syntax: Select all

for player in get_players_in_or_pending_team(2):
print(player.name, 'is terrorist!')

Syntax: Select all

print('There is', len(set(get_players_in_or_pending_team(3))),
'counter-terrorists!')
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Postby 8guawong » Mon Oct 06, 2014 3:30 am

L'In20Cible wrote:

Syntax: Select all

for player in get_players_in_or_pending_team(2):
print(player.name, 'is terrorist!')

Syntax: Select all

print('There is', len(set(get_players_in_or_pending_team(3))),
'counter-terrorists!')


ok thanks!

but could you comment the code? having a hard time understanding whats going on :D :p
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Mon Oct 06, 2014 3:48 am

I've added some comments.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 146 guests