Reading how many players are currently spectating your camera:
int GetObserverCount(CPlayer* pLocal) {
int count = 0;
for (int i = 1; i <= 64; i++) {
auto pEnt = GetEntityByIndex(i);
if (!pEnt || pEnt->IsAlive()) continue;
// Check if dead player's observer target equals local player handle
if (pEnt->m_hObserverTarget() == pLocal->GetHandle()) {
count++;
}
}
return count;
}Displays a warning indicator on HUD whenever anyone is spectating!