diff --git a/extensions/sdktools/extension.cpp b/extensions/sdktools/extension.cpp index 557e4b72..59d31d2b 100644 --- a/extensions/sdktools/extension.cpp +++ b/extensions/sdktools/extension.cpp @@ -337,50 +337,75 @@ bool SDKTools::LevelInit(char const *pMapName, char const *pMapEntities, char co bool SDKTools::ProcessCommandTarget(cmd_target_info_t *info) { - if (strcmp(info->pattern, "@aim") != 0) - { - return false; - } - IGamePlayer *pAdmin = info->admin ? playerhelpers->GetGamePlayer(info->admin) : NULL; - /* The server can't aim, of course. */ - if (pAdmin == NULL) + if (strcmp(info->pattern, "@aim") == 0) { - return false; - } + /* The server can't aim, of course. */ + if (pAdmin == NULL) + { + return false; + } - int player_index; - if ((player_index = GetClientAimTarget(pAdmin->GetEdict(), true)) < 1) + int player_index; + if ((player_index = GetClientAimTarget(pAdmin->GetEdict(), true)) < 1) + { + info->reason = COMMAND_TARGET_NONE; + info->num_targets = 0; + return true; + } + + IGamePlayer *pTarget = playerhelpers->GetGamePlayer(player_index); + + if (pTarget == NULL) + { + info->reason = COMMAND_TARGET_NONE; + info->num_targets = 0; + return true; + } + + info->reason = playerhelpers->FilterCommandTarget(pAdmin, pTarget, info->flags); + if (info->reason != COMMAND_TARGET_VALID) + { + info->num_targets = 0; + return true; + } + + 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; + } + else if (strcmp(info->pattern, "@spec") == 0) { - info->reason = COMMAND_TARGET_NONE; + const char *teamname = tools_GetTeamName(1); + if (strcasecmp(teamname, "spectator") != 0) + return false; info->num_targets = 0; + for (int i = 1; i <= playerhelpers->GetMaxClients(); i++) + { + IGamePlayer *player = playerhelpers->GetGamePlayer(i); + if (player == NULL || !player->IsInGame()) + continue; + IPlayerInfo *plinfo = player->GetPlayerInfo(); + if (plinfo == NULL) + continue; + if (plinfo->GetTeamIndex() == 1 && + playerhelpers->FilterCommandTarget(pAdmin, player, info->flags) == + COMMAND_TARGET_VALID) + { + info->targets[info->num_targets++] = i; + } + } + info->reason = info->num_targets > 0 ? COMMAND_TARGET_VALID : COMMAND_TARGET_EMPTY_FILTER; + info->target_name_style = COMMAND_TARGETNAME_ML; + snprintf(info->target_name, info->target_name_maxlength, "all spectators"); return true; } - IGamePlayer *pTarget = playerhelpers->GetGamePlayer(player_index); - - if (pTarget == NULL) - { - info->reason = COMMAND_TARGET_NONE; - info->num_targets = 0; - return true; - } - - info->reason = playerhelpers->FilterCommandTarget(pAdmin, pTarget, info->flags); - if (info->reason != COMMAND_TARGET_VALID) - { - info->num_targets = 0; - return true; - } - - 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; + return false; } const char *SDKTools::GetExtensionVerString() diff --git a/extensions/sdktools/extension.h b/extensions/sdktools/extension.h index 4febd841..a6e3036b 100644 --- a/extensions/sdktools/extension.h +++ b/extensions/sdktools/extension.h @@ -128,6 +128,8 @@ extern ICallWrapper *g_pAcceptInput; extern SourceHook::CallClass *enginePatch; extern SourceHook::CallClass *enginesoundPatch; +extern const char *tools_GetTeamName(int team); + #include #define ENGINE_CALL(func) SH_CALL(enginePatch, &IVEngineServer::func) diff --git a/extensions/sdktools/msvc9/sdktools.vcproj b/extensions/sdktools/msvc9/sdktools.vcproj index fb36af14..c2c52353 100644 --- a/extensions/sdktools/msvc9/sdktools.vcproj +++ b/extensions/sdktools/msvc9/sdktools.vcproj @@ -60,6 +60,7 @@ = g_Teams.size()) + return NULL; + if (g_teamname_offset == 0) + return NULL; + if (g_teamname_offset == -1) + { + SendProp *prop = g_pGameHelpers->FindInSendTable(g_Teams[team].ClassName, "m_szTeamname"); + if (prop == NULL) + { + g_teamname_offset = 0; + return NULL; + } + g_teamname_offset = prop->GetOffset(); + } + + return (const char *)((unsigned char *)g_Teams[team].pEnt + g_teamname_offset); +} + static cell_t GetTeamName(IPluginContext *pContext, const cell_t *params) { int teamindex = params[1]; if (teamindex >= (int)g_Teams.size() || !g_Teams[teamindex].ClassName) - { return pContext->ThrowNativeError("Team index %d is invalid", teamindex); - } if (g_teamname_offset == 0) - { return pContext->ThrowNativeError("Team names are not available on this game."); - } - if (g_teamname_offset == -1) - { - SendProp *prop = g_pGameHelpers->FindInSendTable(g_Teams[teamindex].ClassName, "m_szTeamname"); - - if (prop == NULL) - { - g_teamname_offset = 0; - return pContext->ThrowNativeError("Team names are not available on this game."); - } - - g_teamname_offset = prop->GetOffset(); - } - - char *name = (char *)((unsigned char *)g_Teams[teamindex].pEnt + g_teamname_offset); + const char *name = tools_GetTeamName(teamindex); + if (name == NULL) + return pContext->ThrowNativeError("Team names are not available on this game."); pContext->StringToLocalUTF8(params[2], params[3], name, NULL); diff --git a/translations/core.phrases.txt b/translations/core.phrases.txt index af74ca88..cea22c50 100644 --- a/translations/core.phrases.txt +++ b/translations/core.phrases.txt @@ -50,6 +50,11 @@ "en" "all alive players" } + "all spectators" + { + "en" "all spectators" + } + "Vote Count" { "#format" "{1:i},{2:i},{3:i}"