Page 1 of 1

How to use PlayerDictionary?

Posted: Fri Aug 03, 2018 4:46 pm
by nergal
so there's a playerdict that let's you factory with any existing class as long as the class derives from "Player" but how does it work?

Syntax: Select all

player_dict = PlayerDictionary(factory=RTDPlayer);


is the dictionary automatically updated like when a person connects or disconnects?
is it a dictionary of player userids, player edict ptrs, or player entity indexes?

how would I access each dict value? Like a list index? by name?

Re: How to use PlayerDictionary?

Posted: Fri Aug 03, 2018 5:47 pm
by VinciT
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()

Re: How to use PlayerDictionary?

Posted: Sat Aug 04, 2018 1:50 am
by L'In20Cible
You don't have to clear the dictionary yourself. As soon as the player entities are deleted, they are removed from the dictionary and all entities are freed on new map.