diff --git a/core/smn_player.cpp b/core/smn_player.cpp index f260b3d5..0345a12e 100644 --- a/core/smn_player.cpp +++ b/core/smn_player.cpp @@ -18,7 +18,6 @@ #include "HalfLife2.h" #include "sourcemod.h" #include "ChatTriggers.h" -#include "GameConfigs.h" #include #include @@ -168,6 +167,27 @@ static cell_t sm_IsClientFakeClient(IPluginContext *pCtx, const cell_t *params) return (pPlayer->IsFakeClient()) ? 1 : 0; } +static cell_t IsClientObserver(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } else if (!pPlayer->IsInGame()) { + return pContext->ThrowNativeError("Client %d is not in game", client); + } + + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); + if (!pInfo) + { + return pContext->ThrowNativeError("IPlayerInfo not supported by game"); + } + + return pInfo->IsObserver() ? 1 : 0; +} + static cell_t sm_GetClientInfo(IPluginContext *pContext, const cell_t *params) { int client = params[1]; @@ -970,6 +990,7 @@ REGISTER_NATIVES(playernatives) {"IsFakeClient", sm_IsClientFakeClient}, {"IsPlayerInGame", sm_IsClientInGame}, /* Backwards compat shim */ {"IsClientInGame", sm_IsClientInGame}, + {"IsClientObserver", IsClientObserver}, {"RemoveUserFlags", RemoveUserFlags}, {"SetUserAdmin", SetUserAdmin}, {"SetUserFlagBits", SetUserFlagBits}, diff --git a/plugins/include/clients.inc b/plugins/include/clients.inc index 6860c6cd..df81bafa 100644 --- a/plugins/include/clients.inc +++ b/plugins/include/clients.inc @@ -187,6 +187,14 @@ native bool:IsClientAuthorized(client); */ native bool:IsFakeClient(client); +/** + * Returns if a certain player is an observer/spectator. + * + * @param client Player index. + * @return True if player is an obverser, false otherwise. + */ +native bool:IsClientObserver(client); + /** * Retrieves values from client replicated keys. *