The dictionary holds instances of the
Player class you specified, in this case
RTDPlayer.
You can get a Player instance either by userid or index.
Syntax: Select all
player_dict = PlayerDictionary(factory=RTDPlayer)
# Get Player instance by index.
player = player_dict[index]
# Get Player instance by userid.
player = player_dict.from_userid(userid)
A Player instance is created the first time you attempt to get a specific Player instance, and the instance is removed once the player gets deleted (disconnected).
So there's no need to manually keep track of the instances.
I think the only thing you need to do is clear the dictionary after a map change, but I'm not 100% sure about that.
Syntax: Select all
from listeners import OnLevelEnd
@OnLevelEnd
def on_level_end():
player_dict.clear()