How to use PlayerDictionary?

Please post any questions about developing your plugin here. Please use the search function before posting!
nergal
Member
Posts: 57
Joined: Sun Mar 15, 2015 2:58 pm

How to use PlayerDictionary?

Postby nergal » Fri Aug 03, 2018 4:46 pm

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?
User avatar
VinciT
Member
Posts: 80
Joined: Thu Dec 18, 2014 2:41 am

Re: How to use PlayerDictionary?

Postby VinciT » Fri Aug 03, 2018 5:47 pm

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()
User avatar
L'In20Cible
Project Leader
Posts: 1066
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: How to use PlayerDictionary?

Postby L'In20Cible » Sat Aug 04, 2018 1:50 am

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.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 5 guests