Skip to content

Commit

Permalink
Merge pull request #230 from Cyberschorsch/feature/225-extend-bot-setup
Browse files Browse the repository at this point in the history
#225: Allow additional bot setups as new files
  • Loading branch information
splewis authored Mar 13, 2022
2 parents 94de6c4 + 1ea3bfa commit cffd0d1
Showing 1 changed file with 62 additions and 23 deletions.
85 changes: 62 additions & 23 deletions scripting/practicemode/bots.sp
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,29 @@ public Action Command_SaveBots(int client, int args) {
char mapName[PLATFORM_MAX_PATH];
GetCleanMapName(mapName, sizeof(mapName));
char path[PLATFORM_MAX_PATH];
BuildPath(Path_SM, path, sizeof(path), "data/practicemode/bots/%s.cfg", mapName);
KeyValues botsKv = new KeyValues("Bots");

// If there is an argument for this command, we load the bots from a specific file.
if (args >= 1) {
char filename[128];
for (int i = 1; i <= args; i++)
{
GetCmdArg(i, filename, sizeof(filename));
}
// Custom bot placements are in a subdirectory.
BuildPath(Path_SM, path, sizeof(path), "data/practicemode/bots/%s/%s.cfg", mapName, filename);
char dir[PLATFORM_MAX_PATH];
BuildPath(Path_SM, dir, sizeof(dir), "data/practicemode/bots/%s", mapName);
if (!DirExists(dir)) {
if (!CreateDirectory(dir, 511))
LogError("Failed to create directory %s", dir);
}
}
// Use the default legacy path if no argument has been provided to the command.
else {
BuildPath(Path_SM, path, sizeof(path), "data/practicemode/bots/%s.cfg", mapName);
}

KeyValues botsKv = new KeyValues("Bots");
int output_index = 0;
for (int i = 1; i <= MaxClients; i++) {
if (IsPMBot(i)) {
Expand Down Expand Up @@ -533,31 +553,50 @@ public Action Command_LoadBots(int client, int args) {
char mapName[PLATFORM_MAX_PATH];
GetCleanMapName(mapName, sizeof(mapName));
char path[PLATFORM_MAX_PATH];
BuildPath(Path_SM, path, sizeof(path), "data/practicemode/bots/%s.cfg", mapName);

KeyValues botsKv = new KeyValues("Bots");
botsKv.ImportFromFile(path);
botsKv.GotoFirstSubKey();
// If there is an argument for this command, we load the bots from a specific file.
if (args >= 1) {
char filename[128];
for (int i = 1; i <= args; i++)
{
GetCmdArg(i, filename, sizeof(filename));
}
// Custom bot placements are in a subdirectory.
BuildPath(Path_SM, path, sizeof(path), "data/practicemode/bots/%s/%s.cfg", mapName, filename);
}
// Use the default legacy path if no argument has been provided to the command.
else {
BuildPath(Path_SM, path, sizeof(path), "data/practicemode/bots/%s.cfg", mapName);
}

do {
char name[MAX_NAME_LENGTH + 1];
botsKv.GetString("name", name, sizeof(name));
bool crouching = !!botsKv.GetNum("crouching");
// Check if the file exist on the server and try to load bots from the file.
if (FileExists(path)) {
KeyValues botsKv = new KeyValues("Bots");
botsKv.ImportFromFile(path);
botsKv.GotoFirstSubKey();

int bot = CreateBot(client, crouching, name);
if (bot <= 0) {
return Plugin_Handled;
}
botsKv.GetVector("origin", g_BotSpawnOrigin[bot], NULL_VECTOR);
botsKv.GetVector("angle", g_BotSpawnAngles[bot], NULL_VECTOR);
botsKv.GetString("weapon", g_BotSpawnWeapon[bot], 64);
g_BotCrouching[bot] = crouching;
GiveBotParams(bot);
} while (botsKv.GotoNextKey());
do {
char name[MAX_NAME_LENGTH + 1];
botsKv.GetString("name", name, sizeof(name));
bool crouching = !!botsKv.GetNum("crouching");

delete botsKv;
PM_MessageToAll("Loaded bot spawns.");
return Plugin_Handled;
int bot = CreateBot(client, crouching, name);
if (bot <= 0) {
return Plugin_Handled;
}
botsKv.GetVector("origin", g_BotSpawnOrigin[bot], NULL_VECTOR);
botsKv.GetVector("angle", g_BotSpawnAngles[bot], NULL_VECTOR);
botsKv.GetString("weapon", g_BotSpawnWeapon[bot], 64);
g_BotCrouching[bot] = crouching;
GiveBotParams(bot);
} while (botsKv.GotoNextKey());
delete botsKv;
PM_MessageToAll("Loaded bot spawns.");
return Plugin_Handled;
} else {
PM_Message(client, "No botfile found.");
return Plugin_Handled;
}
}

public Action Command_SwapBot(int client, int args) {
Expand Down

0 comments on commit cffd0d1

Please sign in to comment.