[DiscordArchive] is there a way to get the player object from a players name?
[DiscordArchive] is there a way to get the player object from a players name?
Archived author: Pandaros • Posted: 2022-08-14T17:37:35.525000+00:00
Original source
is there a way to get the player object from a players name?
Archived author: Pandaros • Posted: 2022-08-14T17:42:16.936000+00:00
Original source
```
Player* World::FindPlayerInZone(uint32 zone)
{
///- circle through active sessions and return the first player found in the zone
SessionMap::const_iterator itr;
for (itr = m_sessions.begin(); itr != m_sessions.end(); ++itr)
{
if (!itr->second)
continue;
Player* player = itr->second->GetPlayer();
if (!player)
continue;
if (player->IsInWorld() && player->GetZoneId() == zone)
return player;
}
return nullptr;
}
```
Why is there code that loops over everything rather than maintaining a map? what if theres 1000s of players?
Archived author: Pandaros • Posted: 2022-08-14T17:42:48.730000+00:00
Original source
the would be much more efficient with indexing
Archived author: Revision • Posted: 2022-08-14T17:42:49.710000+00:00
Original source
It stops at the first one it finds
Archived author: Nyeriah • Posted: 2022-08-14T18:32:34.669000+00:00
Original source
why'd you need to find it by name specifically? you can find them by guid
Archived author: Nyeriah • Posted: 2022-08-14T18:32:46.373000+00:00
Original source
you can get their guid through their name