25.03.2013, 19:06
Quote:
Is there any vector or any way to access all Player class objects?
I would like to extend Player class and access those objects using the object and not the playerid parameter. |
pawn Код:
class Players {
public:
....
static MyPlayer *GetPlayer(int playerid) {
// Retrieve the existing Player object from players or add a new one.
}
...
private:
// A comparison function for std::set - compares two players using on their IDs.
static int ComparePlayers(const MyPlayer *p, const MyPlayer *q) {
return p->GetId() - q->GetId();
}
static std::set<MyPlayer*, ComparePlayers> players;
};
pawn Код:
bool OnPlayerConnect(int playerid) {
MyPlayer *player = Players::GetPlayer(playerid);
// Do stuff with player
}