Page 1 of 1

Spectator List

Posted: Tue Mar 15, 2016 11:07 pm
by decompile
Hello,

How can I make a list of the players spectators with their playernames?

Lets say Player1 is alive and Player 2 and Player 3 are spectating him, so how can you return ["Player 2", "Player 3"]?

Sorry Mobilecorrector

Posted: Tue Mar 15, 2016 11:27 pm
by satoon101

Syntax: Select all

from filters.players import PlayerIter
from players.entity import Player


def get_spectators(index):
"""Return a list of names of all players observing the given player."""
player = Player(index)
observer_list = list()
for other in PlayerIter('dead'):
if player.inthandle == other.observer_target:
observer_list.append(other.name)
return observer_list

Posted: Wed Mar 16, 2016 7:59 pm
by Ayuto
I have added a "spectators" property to the player class based on your implementation:
https://github.com/Source-Python-Dev-Team/Source.Python/commit/dee963986abb17d83c1d091c0e80fb448e842a12