Skip to content

Commit 5fc73ce

Browse files
committed
Added endround, money, health & setpos admin commands
1 parent 89d77df commit 5fc73ce

File tree

2 files changed

+132
-58
lines changed

2 files changed

+132
-58
lines changed

src/adminsystem.cpp

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,138 @@ CON_COMMAND_CHAT_FLAGS(listdc, "- List recently disconnected players and their S
976976
g_pAdminSystem->ShowDisconnectedPlayers(player);
977977
}
978978

979+
CON_COMMAND_CHAT_FLAGS(endround, "- Immediately ends the round, client-side variant of endround", ADMFLAG_RCON)
980+
{
981+
g_pGameRules->TerminateRound(0.0f, CSRoundEndReason::Draw);
982+
}
983+
984+
CON_COMMAND_CHAT_FLAGS(money, "<name> <amount> - Set a player's amount of money", ADMFLAG_CHEATS)
985+
{
986+
if (args.ArgC() < 3)
987+
{
988+
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !money <name> <amount>");
989+
return;
990+
}
991+
992+
int iMoney = V_StringToInt32(args[2], -1);
993+
994+
if (iMoney < 0)
995+
{
996+
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Invalid amount specified, must be a positive number.");
997+
return;
998+
}
999+
1000+
int iNumClients = 0;
1001+
int pSlots[MAXPLAYERS];
1002+
ETargetType nType;
1003+
1004+
if (!g_playerManager->CanTargetPlayers(player, args[1], iNumClients, pSlots, NO_TARGET_BLOCKS, nType))
1005+
return;
1006+
1007+
const char* pszCommandPlayerName = player ? player->GetPlayerName() : CONSOLE_NAME;
1008+
1009+
char szAction[64];
1010+
V_snprintf(szAction, sizeof(szAction), "set $%i money on", iMoney);
1011+
1012+
for (int i = 0; i < iNumClients; i++)
1013+
{
1014+
CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlots[i]);
1015+
1016+
if (!pTarget)
1017+
continue;
1018+
1019+
pTarget->m_pInGameMoneyServices->m_iAccount = iMoney;
1020+
1021+
if (iNumClients == 1)
1022+
PrintSingleAdminAction(pszCommandPlayerName, pTarget->GetPlayerName(), szAction, "");
1023+
}
1024+
1025+
if (iNumClients > 1)
1026+
PrintMultiAdminAction(nType, pszCommandPlayerName, szAction, "");
1027+
}
1028+
1029+
CON_COMMAND_CHAT_FLAGS(health, "<name> <health> - Set a player's health", ADMFLAG_CHEATS)
1030+
{
1031+
if (args.ArgC() < 3)
1032+
{
1033+
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !health <name> <health>");
1034+
return;
1035+
}
1036+
1037+
int iHealth = V_StringToInt32(args[2], -1);
1038+
1039+
if (iHealth < 1)
1040+
{
1041+
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Invalid amount specified, must be a positive number.");
1042+
return;
1043+
}
1044+
1045+
int iNumClients = 0;
1046+
int pSlots[MAXPLAYERS];
1047+
ETargetType nType;
1048+
1049+
if (!g_playerManager->CanTargetPlayers(player, args[1], iNumClients, pSlots, NO_DEAD | NO_SPECTATOR, nType))
1050+
return;
1051+
1052+
const char* pszCommandPlayerName = player ? player->GetPlayerName() : CONSOLE_NAME;
1053+
1054+
char szAction[64];
1055+
V_snprintf(szAction, sizeof(szAction), "set %i health on", iHealth);
1056+
1057+
for (int i = 0; i < iNumClients; i++)
1058+
{
1059+
CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlots[i]);
1060+
1061+
if (!pTarget)
1062+
continue;
1063+
1064+
CCSPlayerPawn* pPawn = pTarget->GetPlayerPawn();
1065+
1066+
if (!pPawn)
1067+
continue;
1068+
1069+
if (pPawn->m_iMaxHealth < iHealth)
1070+
pPawn->m_iMaxHealth = iHealth;
1071+
1072+
pPawn->m_iHealth = iHealth;
1073+
1074+
if (iNumClients == 1)
1075+
PrintSingleAdminAction(pszCommandPlayerName, pTarget->GetPlayerName(), szAction, "");
1076+
}
1077+
1078+
if (iNumClients > 1)
1079+
PrintMultiAdminAction(nType, pszCommandPlayerName, szAction, "");
1080+
}
1081+
1082+
CON_COMMAND_CHAT_FLAGS(setpos, "<x y z> - Set your origin", ADMFLAG_CHEATS)
1083+
{
1084+
if (!player)
1085+
{
1086+
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You cannot use this command from the server console.");
1087+
return;
1088+
}
1089+
1090+
CBasePlayerPawn* pPawn = player->GetPawn();
1091+
1092+
if (!pPawn)
1093+
return;
1094+
1095+
if (pPawn->m_iTeamNum() < CS_TEAM_T || !pPawn->IsAlive())
1096+
{
1097+
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You must be alive to use this command.");
1098+
return;
1099+
}
1100+
1101+
Vector origin;
1102+
V_StringToVector(args.ArgS(), origin);
1103+
1104+
char szOrigin[64];
1105+
V_snprintf(szOrigin, sizeof(szOrigin), "%f %f %f", origin.x, origin.y, origin.z);
1106+
1107+
pPawn->Teleport(&origin, nullptr, nullptr);
1108+
PrintSingleAdminAction(player->GetPlayerName(), szOrigin, "teleported to");
1109+
}
1110+
9791111
#ifdef _DEBUG
9801112
CON_COMMAND_CHAT_FLAGS(add_dc, "<name> <SteamID 64> <IP Address> - Adds a fake player to disconnected player list for testing", ADMFLAG_GENERIC)
9811113
{

src/commands.cpp

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -804,55 +804,11 @@ CON_COMMAND_CHAT(fl, "- Flashlight")
804804
pLight->AcceptInput("SetParentAttachmentMaintainOffset", &val2);
805805
}
806806

807-
CON_COMMAND_CHAT(message, "<id> <message> - Message someone")
808-
{
809-
if (!player)
810-
return;
811-
812-
// Note that the engine will treat this as a player slot number, not an entity index
813-
int uid = atoi(args[1]);
814-
815-
CCSPlayerController* pTarget = CCSPlayerController::FromSlot(uid);
816-
817-
if (!pTarget)
818-
return;
819-
820-
// skipping the id and space, it's dumb but w/e
821-
const char *pMessage = args.ArgS() + V_strlen(args[1]) + 1;
822-
823-
ClientPrint(pTarget, HUD_PRINTTALK, CHAT_PREFIX "Private message from %s to %s: \5%s", player->GetPlayerName(), pTarget->GetPlayerName(), pMessage);
824-
}
825-
826807
CON_COMMAND_CHAT(say, "<message> - Say something using console")
827808
{
828809
ClientPrintAll(HUD_PRINTTALK, "%s", args.ArgS());
829810
}
830811

831-
CON_COMMAND_CHAT(takemoney, "<amount> - Take your money")
832-
{
833-
if (!player)
834-
return;
835-
836-
int amount = atoi(args[1]);
837-
int money = player->m_pInGameMoneyServices->m_iAccount;
838-
839-
player->m_pInGameMoneyServices->m_iAccount = money - amount;
840-
}
841-
842-
CON_COMMAND_CHAT(sethealth, "<health> - Set your health")
843-
{
844-
if (!player)
845-
return;
846-
847-
int health = atoi(args[1]);
848-
849-
CBaseEntity *pEnt = (CBaseEntity *)player->GetPawn();
850-
851-
pEnt->m_iHealth = health;
852-
853-
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Your health is now %d", health);
854-
}
855-
856812
CON_COMMAND_CHAT(test_target, "<name> [blocked flag] [...] - Test string targetting")
857813
{
858814
if (!player)
@@ -907,20 +863,6 @@ CON_COMMAND_CHAT(test_target, "<name> [blocked flag] [...] - Test string targett
907863
}
908864
}
909865

910-
CON_COMMAND_CHAT(setorigin, "<vector> - Set your origin")
911-
{
912-
if (!player)
913-
return;
914-
915-
CBasePlayerPawn *pPawn = player->GetPawn();
916-
Vector vecNewOrigin;
917-
V_StringToVector(args.ArgS(), vecNewOrigin);
918-
919-
pPawn->Teleport(&vecNewOrigin, nullptr, nullptr);
920-
921-
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Your origin is now %f %f %f", vecNewOrigin.x, vecNewOrigin.y, vecNewOrigin.z);
922-
}
923-
924866
CON_COMMAND_CHAT(particle, "- Spawn a particle")
925867
{
926868
if (!player)

0 commit comments

Comments
 (0)