diff --git a/extensions/sdktools/vnatives.cpp b/extensions/sdktools/vnatives.cpp index 0c3e7e0a..622b506d 100644 --- a/extensions/sdktools/vnatives.cpp +++ b/extensions/sdktools/vnatives.cpp @@ -274,6 +274,29 @@ static cell_t TeleportPlayer(IPluginContext *pContext, const cell_t *params) return 1; } +static cell_t SetClientViewEntity(IPluginContext *pContext, const cell_t *params) +{ + IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]); + if (player == NULL) + { + return pContext->ThrowNativeError("Invalid client index %d", params[1]); + } + if (!player->IsInGame()) + { + return pContext->ThrowNativeError("Client %d is not in game", params[1]); + } + + edict_t *pEdict = engine->PEntityOfEntIndex(params[2]); + if (!pEdict || pEdict->IsFree()) + { + return pContext->ThrowNativeError("Entity %d is not valid", params[2]); + } + + engine->SetView(player->GetEdict(), pEdict); + + return 1; +} + sp_nativeinfo_t g_Natives[] = { {"ExtinguishPlayer", ExtinguishPlayer}, @@ -285,6 +308,7 @@ sp_nativeinfo_t g_Natives[] = {"RemovePlayerItem", RemovePlayerItem}, {"TeleportPlayer", TeleportPlayer}, {"TeleportEntity", TeleportPlayer}, + {"SetClientViewEntity", SetClientViewEntity}, {NULL, NULL}, }; diff --git a/plugins/include/sdktools.inc b/plugins/include/sdktools.inc index 8ec2be01..223bbf3a 100644 --- a/plugins/include/sdktools.inc +++ b/plugins/include/sdktools.inc @@ -19,6 +19,7 @@ #define _sdktools_included #include +#include #include #include #include diff --git a/plugins/include/sdktools_engine.inc b/plugins/include/sdktools_engine.inc new file mode 100644 index 00000000..b06dc8c1 --- /dev/null +++ b/plugins/include/sdktools_engine.inc @@ -0,0 +1,30 @@ +/** + * vim: set ts=4 : + * =============================================================== + * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. + * =============================================================== + * + * This file is part of the SourceMod/SourcePawn SDK. This file may only be used + * or modified under the Terms and Conditions of its License Agreement, which is found + * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins + * may change at any time. To view the latest information, see: + * http://www.sourcemod.net/license.php + * + * Version: $Id$ + */ + +#if defined _sdktools_engine_included + #endinput +#endif +#define _sdktools_engine_included + +/** + * Sets a client's "viewing entity." + * + * @param client Client index. + * @param entity Entity index. + * @noreturn + * @error Invalid client or entity, lack of mod support, or client not in + * game. + */ +native SetClientViewEntity(client, entity);