Added @spec target (bug 2718, r=fyren).

This commit is contained in:
David Anderson 2009-10-27 03:41:36 -07:00
parent 97be0ff22a
commit 3bf5edc2b3
5 changed files with 92 additions and 53 deletions

View File

@ -337,13 +337,10 @@ bool SDKTools::LevelInit(char const *pMapName, char const *pMapEntities, char co
bool SDKTools::ProcessCommandTarget(cmd_target_info_t *info) 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; IGamePlayer *pAdmin = info->admin ? playerhelpers->GetGamePlayer(info->admin) : NULL;
if (strcmp(info->pattern, "@aim") == 0)
{
/* The server can't aim, of course. */ /* The server can't aim, of course. */
if (pAdmin == NULL) if (pAdmin == NULL)
{ {
@ -379,8 +376,36 @@ bool SDKTools::ProcessCommandTarget(cmd_target_info_t *info)
info->reason = COMMAND_TARGET_VALID; info->reason = COMMAND_TARGET_VALID;
info->target_name_style = COMMAND_TARGETNAME_RAW; info->target_name_style = COMMAND_TARGETNAME_RAW;
snprintf(info->target_name, info->target_name_maxlength, "%s", pTarget->GetName()); snprintf(info->target_name, info->target_name_maxlength, "%s", pTarget->GetName());
return true; return true;
}
else if (strcmp(info->pattern, "@spec") == 0)
{
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;
}
return false;
} }
const char *SDKTools::GetExtensionVerString() const char *SDKTools::GetExtensionVerString()

View File

@ -128,6 +128,8 @@ extern ICallWrapper *g_pAcceptInput;
extern SourceHook::CallClass<IVEngineServer> *enginePatch; extern SourceHook::CallClass<IVEngineServer> *enginePatch;
extern SourceHook::CallClass<IEngineSound> *enginesoundPatch; extern SourceHook::CallClass<IEngineSound> *enginesoundPatch;
extern const char *tools_GetTeamName(int team);
#include <compat_wrappers.h> #include <compat_wrappers.h>
#define ENGINE_CALL(func) SH_CALL(enginePatch, &IVEngineServer::func) #define ENGINE_CALL(func) SH_CALL(enginePatch, &IVEngineServer::func)

View File

@ -60,6 +60,7 @@
<Tool <Tool
Name="VCResourceCompilerTool" Name="VCResourceCompilerTool"
PreprocessorDefinitions="BINARY_NAME=\&quot;$(TargetFileName)\&quot;" PreprocessorDefinitions="BINARY_NAME=\&quot;$(TargetFileName)\&quot;"
AdditionalIncludeDirectories="..\..\..\public"
/> />
<Tool <Tool
Name="VCPreLinkEventTool" Name="VCPreLinkEventTool"

View File

@ -110,33 +110,39 @@ static cell_t GetTeamCount(IPluginContext *pContext, const cell_t *params)
} }
static int g_teamname_offset = -1; static int g_teamname_offset = -1;
const char *tools_GetTeamName(int team)
{
if (size_t(team) >= 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) static cell_t GetTeamName(IPluginContext *pContext, const cell_t *params)
{ {
int teamindex = params[1]; int teamindex = params[1];
if (teamindex >= (int)g_Teams.size() || !g_Teams[teamindex].ClassName) if (teamindex >= (int)g_Teams.size() || !g_Teams[teamindex].ClassName)
{
return pContext->ThrowNativeError("Team index %d is invalid", teamindex); return pContext->ThrowNativeError("Team index %d is invalid", teamindex);
}
if (g_teamname_offset == 0) if (g_teamname_offset == 0)
{
return pContext->ThrowNativeError("Team names are not available on this game."); return pContext->ThrowNativeError("Team names are not available on this game.");
}
if (g_teamname_offset == -1) const char *name = tools_GetTeamName(teamindex);
{ if (name == NULL)
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."); 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);
pContext->StringToLocalUTF8(params[2], params[3], name, NULL); pContext->StringToLocalUTF8(params[2], params[3], name, NULL);

View File

@ -50,6 +50,11 @@
"en" "all alive players" "en" "all alive players"
} }
"all spectators"
{
"en" "all spectators"
}
"Vote Count" "Vote Count"
{ {
"#format" "{1:i},{2:i},{3:i}" "#format" "{1:i},{2:i},{3:i}"