Skip to content

Commit

Permalink
Waypoint Controller Player defaults to first real player
Browse files Browse the repository at this point in the history
  • Loading branch information
pongo1231 committed Aug 11, 2019
1 parent 3bfdadf commit e9d539e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
12 changes: 11 additions & 1 deletion Pongbot/TF2/Entity/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,20 @@ bool Player::IsReloading() const

bool Player::IsDead() const
{
return _IIPlayerInfo->IsDead();
return Exists() ? _IIPlayerInfo->IsDead() : true;
}

bool Player::Exists() const
{
return Entity::Exists() && IsPlayer();
}

bool Player::IsBot() const
{
return Exists() ? _IIPlayerInfo->IsFakeClient() : false;
}

IPlayerInfo* Player::GetPlayerInfo() const
{
return _IIPlayerInfo;
}
2 changes: 2 additions & 0 deletions Pongbot/TF2/Entity/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Player : public Entity
bool IsReloading() const;
bool IsDead() const;
bool Exists() const;
bool IsBot() const;
IPlayerInfo* GetPlayerInfo() const;

private:
IPlayerInfo* _IIPlayerInfo;
Expand Down
15 changes: 11 additions & 4 deletions Pongbot/Waypoint/WaypointManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,19 @@ void WaypointManager::OnGameFrame()

static IPlayerInfo* _CheckCommandTargetPlayerExists()
{
edict_t* playerEdict = Engine->PEntityOfEntIndex(1);
IPlayerInfo* playerInfo = IIPlayerInfoManager->GetPlayerInfo(playerEdict);
if (!playerEdict || !playerInfo || !playerInfo->IsPlayer())
IPlayerInfo* playerInfo = nullptr;
for (Player player : Util::GetAllPlayers())
{
if (player.Exists())
{
playerInfo = player.GetPlayerInfo();
break;
}
}

if (!playerInfo)
{
Util::Log("No player found!");
return nullptr;
}
return playerInfo;
}
Expand Down

0 comments on commit e9d539e

Please sign in to comment.