Added @spec target (bug 2718, r=fyren).
This commit is contained in:
parent
97be0ff22a
commit
3bf5edc2b3
@ -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()
|
||||
|
@ -128,6 +128,8 @@ extern ICallWrapper *g_pAcceptInput;
|
||||
extern SourceHook::CallClass<IVEngineServer> *enginePatch;
|
||||
extern SourceHook::CallClass<IEngineSound> *enginesoundPatch;
|
||||
|
||||
extern const char *tools_GetTeamName(int team);
|
||||
|
||||
#include <compat_wrappers.h>
|
||||
|
||||
#define ENGINE_CALL(func) SH_CALL(enginePatch, &IVEngineServer::func)
|
||||
|
@ -60,6 +60,7 @@
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="BINARY_NAME=\"$(TargetFileName)\""
|
||||
AdditionalIncludeDirectories="..\..\..\public"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
|
@ -110,33 +110,39 @@ static cell_t GetTeamCount(IPluginContext *pContext, const cell_t *params)
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
|
||||
|
@ -50,6 +50,11 @@
|
||||
"en" "all alive players"
|
||||
}
|
||||
|
||||
"all spectators"
|
||||
{
|
||||
"en" "all spectators"
|
||||
}
|
||||
|
||||
"Vote Count"
|
||||
{
|
||||
"#format" "{1:i},{2:i},{3:i}"
|
||||
|
Loading…
Reference in New Issue
Block a user