Spectator List

Please post any questions about developing your plugin here. Please use the search function before posting!
decompile
Senior Member
Posts: 417
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Spectator List

Postby decompile » Tue Mar 15, 2016 11:07 pm

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
User avatar
satoon101
Project Leader
Posts: 2703
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Mar 15, 2016 11:27 pm

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

Postby Ayuto » Wed Mar 16, 2016 7:59 pm

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

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 91 guests