Skip to content

Commit

Permalink
Add !selfpawn targeting and player entfire commands
Browse files Browse the repository at this point in the history
  • Loading branch information
xen-000 committed Oct 28, 2023
1 parent fd61dc1 commit b448f4e
Showing 1 changed file with 92 additions and 1 deletion.
93 changes: 92 additions & 1 deletion src/adminsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ CON_COMMAND_CHAT_FLAGS(entfire, "fire outputs at entities", ADMFLAG_RCON)

// The idea here is to only use one of the targeting modes at once, prioritizing !picker then targetname/!self then classname
// Try picker first, FindEntityByName can also take !picker but it always uses player 0 so we have to do this ourselves
if (!V_strcmp("!picker", args[1]))
if (player && !V_strcmp("!picker", args[1]))
{
pTarget = UTIL_FindPickerEntity(player);

Expand All @@ -671,6 +671,18 @@ CON_COMMAND_CHAT_FLAGS(entfire, "fire outputs at entities", ADMFLAG_RCON)
iFoundEnts++;
}
}

// !self would resolve to the player controller, so here's a convenient alias to get the pawn instead
if (player && !V_strcmp("!selfpawn", args[1]))
{
pTarget = player->GetPawn();

if (pTarget)
{
pTarget->AcceptInput(args[2], player, player, &value);
iFoundEnts++;
}
}

if (!iFoundEnts)
{
Expand All @@ -696,6 +708,85 @@ CON_COMMAND_CHAT_FLAGS(entfire, "fire outputs at entities", ADMFLAG_RCON)
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Input successful on %i entities.", iFoundEnts);
}

CON_COMMAND_CHAT_FLAGS(entfirepawn, "fire outputs at player pawns", ADMFLAG_RCON)
{
if (args.ArgC() < 3)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !entfirepawn <name> <input> <optional parameter>");
return;
}

int iCommandPlayer = player ? player->GetPlayerSlot() : -1;
int iNumClients = 0;
int pSlots[MAXPLAYERS];

ETargetType nType = g_playerManager->TargetPlayerString(iCommandPlayer, args[1], iNumClients, pSlots);

if (!iNumClients)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Target not found.");
return;
}

const char *pszCommandPlayerName = player ? player->GetPlayerName() : "Console";

variant_string_t value(args[3]);

int iFoundEnts = 0;

for (int i = 0; i < iNumClients; i++)
{
CCSPlayerController *pTarget = CCSPlayerController::FromSlot(pSlots[i]);

if (!pTarget || !pTarget->GetPawn())
continue;

pTarget->GetPawn()->AcceptInput(args[2], player, player, &value);
}

ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Input successful on %i player pawns.", iFoundEnts);
}

CON_COMMAND_CHAT_FLAGS(entfirecontroller, "fire outputs at player controllers", ADMFLAG_RCON)
{
if (args.ArgC() < 3)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !entfirecontroller <name> <input> <optional parameter>");
return;
}

int iCommandPlayer = player ? player->GetPlayerSlot() : -1;
int iNumClients = 0;
int pSlots[MAXPLAYERS];

ETargetType nType = g_playerManager->TargetPlayerString(iCommandPlayer, args[1], iNumClients, pSlots);

if (!iNumClients)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Target not found.");
return;
}

const char *pszCommandPlayerName = player ? player->GetPlayerName() : "Console";

variant_string_t value(args[3]);

int iFoundEnts = 0;

for (int i = 0; i < iNumClients; i++)
{
CCSPlayerController *pTarget = CCSPlayerController::FromSlot(pSlots[i]);

if (!pTarget)
continue;

pTarget->AcceptInput(args[2], player, player, &value);
iFoundEnts++;
}

ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Input successful on %i player controllers.", iFoundEnts);
}

CON_COMMAND_CHAT_FLAGS(map, "change map", ADMFLAG_CHANGEMAP)
{
if (args.ArgC() < 2)
Expand Down

0 comments on commit b448f4e

Please sign in to comment.