From b1aa7a1ed28671fe03ad4fbdfffc8a1c8e354c9e Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 22 Oct 2007 03:27:22 +0000 Subject: [PATCH] added @aim target to sdktools --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401634 --- extensions/sdktools/extension.cpp | 34 +++++++++++- extensions/sdktools/extension.h | 5 +- extensions/sdktools/vhelpers.cpp | 77 ++++++++++++++++++++++++++ extensions/sdktools/vhelpers.h | 2 + extensions/sdktools/vnatives.cpp | 79 +------------------------- translations/basecomm.phrases.txt | 92 +++++++++++++------------------ 6 files changed, 156 insertions(+), 133 deletions(-) diff --git a/extensions/sdktools/extension.cpp b/extensions/sdktools/extension.cpp index 7afefba0..bf8e63b5 100644 --- a/extensions/sdktools/extension.cpp +++ b/extensions/sdktools/extension.cpp @@ -108,6 +108,8 @@ bool SDKTools::SDK_OnLoad(char *error, size_t maxlength, bool late) SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SDKTools::LevelInit, true); SH_ADD_HOOK_MEMFUNC(IServerGameDLL, ServerActivate, gamedll, this, &SDKTools::OnServerActivate, false); + playerhelpers->RegisterCommandTargetProcessor(this); + MathLib_Init(2.2f, 2.2f, 0.0f, 2); return true; @@ -119,7 +121,9 @@ void SDKTools::OnHandleDestroy(HandleType_t type, void *object) { ValveCall *v = (ValveCall *)object; delete v; - } else if (type == g_TraceHandle) { + } + else if (type == g_TraceHandle) + { trace_t *tr = (trace_t *)object; delete tr; } @@ -148,6 +152,7 @@ void SDKTools::SDK_OnUnload() gameconfs->CloseGameConfigFile(g_pGameConf); playerhelpers->RemoveClientListener(&g_SdkTools); + playerhelpers->UnregisterCommandTargetProcessor(this); SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SDKTools::LevelInit, true); SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, ServerActivate, gamedll, this, &SDKTools::OnServerActivate, false); @@ -250,3 +255,30 @@ bool SDKTools::LevelInit(char const *pMapName, char const *pMapEntities, char co RETURN_META_VALUE(MRES_IGNORED, true); } + +bool SDKTools::ProcessCommandTarget(cmd_target_info_t *info) +{ + IGamePlayer *pAdmin = info->admin ? playerhelpers->GetGamePlayer(info->admin) : NULL; + + /* The server can't aim, of course. */ + if (pAdmin == NULL) + { + return false; + } + + int player_index; + if ((player_index = GetClientAimTarget(pAdmin->GetEdict(), true)) < 1) + { + return false; + } + + IGamePlayer *pTarget = playerhelpers->GetGamePlayer(info->admin); + + info->targets[0] = player_index; + info->num_targets = 1; + info->reason = COMMAND_TARGET_VALID; + info->target_name_style = COMMAND_TARGETNAME_RAW; + snprintf(info->target_name, info->target_name_maxlength, "%s", pTarget->GetName()); + + return true; +} diff --git a/extensions/sdktools/extension.h b/extensions/sdktools/extension.h index 2556a01f..79fcc0ab 100644 --- a/extensions/sdktools/extension.h +++ b/extensions/sdktools/extension.h @@ -56,7 +56,8 @@ class SDKTools : public SDKExtension, public IHandleTypeDispatch, public IConCommandBaseAccessor, - public IClientListener + public IClientListener, + public ICommandTargetProcessor { public: //public IHandleTypeDispatch void OnHandleDestroy(HandleType_t type, void *object); @@ -80,6 +81,8 @@ public: //IClientListner void OnClientDisconnecting(int client); public: // IVoiceServer bool OnSetClientListening(int iReceiver, int iSender, bool bListen); +public: //ICommandTargetProcessor + bool ProcessCommandTarget(cmd_target_info_t *info); public: bool LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background); void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax); diff --git a/extensions/sdktools/vhelpers.cpp b/extensions/sdktools/vhelpers.cpp index 41b6ae73..e8d43565 100644 --- a/extensions/sdktools/vhelpers.cpp +++ b/extensions/sdktools/vhelpers.cpp @@ -36,6 +36,24 @@ CallHelper s_Teleport; CallHelper s_GetVelocity; CallHelper s_EyeAngles; +class CTraceFilterSimple : public CTraceFilterEntitiesOnly +{ +public: + CTraceFilterSimple(const IHandleEntity *passentity): m_pPassEnt(passentity) + { + } + virtual bool ShouldHitEntity(IHandleEntity *pServerEntity, int contentsMask) + { + if (pServerEntity == m_pPassEnt) + { + return false; + } + return true; + } +private: + const IHandleEntity *m_pPassEnt; +}; + bool SetupTeleport() { if (s_Teleport.setup) @@ -185,6 +203,65 @@ bool GetEyeAngles(CBaseEntity *pEntity, QAngle *pAngles) return true; } +int GetClientAimTarget(edict_t *pEdict, bool only_players) +{ + CBaseEntity *pEntity = pEdict->GetUnknown() ? pEdict->GetUnknown()->GetBaseEntity() : NULL; + + if (pEntity == NULL) + { + return -1; + } + + Vector eye_position; + QAngle eye_angles; + + /* Get the private information we need */ + serverClients->ClientEarPosition(pEdict, &eye_position); + if (!GetEyeAngles(pEntity, &eye_angles)) + { + return -2; + } + + Vector aim_dir; + AngleVectors(eye_angles, &aim_dir); + VectorNormalize(aim_dir); + + Vector vec_end = eye_position + aim_dir * 8000; + + Ray_t ray; + ray.Init(eye_position, vec_end); + + trace_t tr; + CTraceFilterSimple simple(pEdict->GetIServerEntity()); + + enginetrace->TraceRay(ray, MASK_SOLID|CONTENTS_DEBRIS|CONTENTS_HITBOX, &simple, &tr); + + if (tr.fraction == 1.0f || tr.m_pEnt == NULL) + { + return -1; + } + + edict_t *pTarget = gameents->BaseEntityToEdict(tr.m_pEnt); + if (pTarget == NULL) + { + return -1; + } + + int ent_index = engine->IndexOfEdict(pTarget); + + IGamePlayer *pTargetPlayer = playerhelpers->GetGamePlayer(ent_index); + if (pTargetPlayer != NULL && !pTargetPlayer->IsInGame()) + { + return -1; + } + else if (only_players && pTargetPlayer == NULL) + { + return -1; + } + + return ent_index; +} + bool IsEyeAnglesSupported() { return SetupGetEyeAngles(); diff --git a/extensions/sdktools/vhelpers.h b/extensions/sdktools/vhelpers.h index 573dac34..cae47a29 100644 --- a/extensions/sdktools/vhelpers.h +++ b/extensions/sdktools/vhelpers.h @@ -66,6 +66,8 @@ bool IsGetVelocitySupported(); bool GetEyeAngles(CBaseEntity *pEntity, QAngle *pAngles); bool IsEyeAnglesSupported(); +int GetClientAimTarget(edict_t *pEdict, bool only_players); + void ShutdownHelpers(); #endif //_INCLUDE_SDKTOOLS_VHELPERS_H_ diff --git a/extensions/sdktools/vnatives.cpp b/extensions/sdktools/vnatives.cpp index ecd02c9c..017084ee 100644 --- a/extensions/sdktools/vnatives.cpp +++ b/extensions/sdktools/vnatives.cpp @@ -113,24 +113,6 @@ bool CreateBaseCall(const char *name, return false; } -class CTraceFilterSimple : public CTraceFilterEntitiesOnly -{ -public: - CTraceFilterSimple(const IHandleEntity *passentity): m_pPassEnt(passentity) - { - } - virtual bool ShouldHitEntity(IHandleEntity *pServerEntity, int contentsMask) - { - if (pServerEntity == m_pPassEnt) - { - return false; - } - return true; - } -private: - const IHandleEntity *m_pPassEnt; -}; - static cell_t RemovePlayerItem(IPluginContext *pContext, const cell_t *params) { static ValveCall *pCall = NULL; @@ -803,7 +785,7 @@ static cell_t DispatchKeyValueVector(IPluginContext *pContext, const cell_t *par return (ret) ? 1 : 0; } -static cell_t GetClientAimTarget(IPluginContext *pContext, const cell_t *params) +static cell_t sm_GetClientAimTarget(IPluginContext *pContext, const cell_t *params) { int client = params[1]; IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); @@ -817,62 +799,7 @@ static cell_t GetClientAimTarget(IPluginContext *pContext, const cell_t *params) return pContext->ThrowNativeError("Client %d is not in game", client); } - edict_t *pEdict = pPlayer->GetEdict(); - CBaseEntity *pEntity = pEdict->GetUnknown() ? pEdict->GetUnknown()->GetBaseEntity() : NULL; - - if (pEntity == NULL) - { - return -1; - } - - Vector eye_position; - QAngle eye_angles; - - /* Get the private information we need */ - serverClients->ClientEarPosition(pEdict, &eye_position); - if (!GetEyeAngles(pEntity, &eye_angles)) - { - return -2; - } - - Vector aim_dir; - AngleVectors(eye_angles, &aim_dir); - VectorNormalize(aim_dir); - - Vector vec_end = eye_position + aim_dir * 8000; - - Ray_t ray; - ray.Init(eye_position, vec_end); - - trace_t tr; - CTraceFilterSimple simple(pEdict->GetIServerEntity()); - - enginetrace->TraceRay(ray, MASK_SOLID|CONTENTS_DEBRIS|CONTENTS_HITBOX, &simple, &tr); - - if (tr.fraction == 1.0f || tr.m_pEnt == NULL) - { - return -1; - } - - edict_t *pTarget = gameents->BaseEntityToEdict(tr.m_pEnt); - if (pTarget == NULL) - { - return -1; - } - - int ent_index = engine->IndexOfEdict(pTarget); - - IGamePlayer *pTargetPlayer = playerhelpers->GetGamePlayer(ent_index); - if (pTargetPlayer != NULL && !pTargetPlayer->IsInGame()) - { - return -1; - } - else if (params[2] && pTargetPlayer == NULL) - { - return -1; - } - - return ent_index; + return GetClientAimTarget(pPlayer->GetEdict(), params[2] ? true : false); } sp_nativeinfo_t g_Natives[] = @@ -898,6 +825,6 @@ sp_nativeinfo_t g_Natives[] = {"DispatchKeyValue", DispatchKeyValue}, {"DispatchKeyValueFloat", DispatchKeyValueFloat}, {"DispatchKeyValueVector", DispatchKeyValueVector}, - {"GetClientAimTarget", GetClientAimTarget}, + {"GetClientAimTarget", sm_GetClientAimTarget}, {NULL, NULL}, }; diff --git a/translations/basecomm.phrases.txt b/translations/basecomm.phrases.txt index 857beef0..21df36b2 100644 --- a/translations/basecomm.phrases.txt +++ b/translations/basecomm.phrases.txt @@ -1,59 +1,5 @@ "Phrases" { - "Already Muted" - { - "en" "Target player is already muted." - } - - "Player Muted" - { - "#format" "{1:s}" - "en" "{1} has been muted." - } - - "Player Not Muted" - { - "en" "Target player is not muted." - } - - "Player Unmuted" - { - "#format" "{1:s}" - "en" "{1} has been unmuted." - } - - "Already Gagged" - { - "en" "Target player is already gagged." - } - - "Player Gagged" - { - "#format" "{1:s}" - "en" "{1} has been gagged." - } - - "Player Not Gagged" - { - "en" "Target player is not gagged." - } - - "Player Ungagged" - { - "#format" "{1:s}" - "en" "{1} has been ungagged." - } - - "Already Silenced" - { - "en" "Target player is already silenced." - } - - "Player Not Silenced" - { - "en" "Target player is not silenced." - } - "Gag/Mute player" { "en" "Gag/Mute player" @@ -63,4 +9,40 @@ { "en" "Choose Type" } -} \ No newline at end of file + + "Gagged target" + { + "#format" "{1:t}" + "en" "Gagged {1}." + } + + "Ungagged target" + { + "#format" "{1:t}" + "en" "Ungagged {1}." + } + + "Muted target" + { + "#format" "{1:t}" + "en" "Muted {1}." + } + + "Unmuted target" + { + "#format" "{1:t}" + "en" "Unmuted {1}." + } + + "Silenced target" + { + "#format" "{1:t}" + "en" "Silenced {1}." + } + + "Unsilenced target" + { + "#format" "{1:t}" + "en" "Unsilenced {1}." + } +}