Implemented amb423 - Added IsClientObserver() native

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401007
This commit is contained in:
Scott Ehlert 2007-06-22 15:37:12 +00:00
parent 3e88c91ad2
commit aef5ba1d09
2 changed files with 30 additions and 1 deletions

View File

@ -18,7 +18,6 @@
#include "HalfLife2.h"
#include "sourcemod.h"
#include "ChatTriggers.h"
#include "GameConfigs.h"
#include <inetchannel.h>
#include <iclient.h>
@ -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},

View File

@ -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.
*