Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#225: Allow additional bot setups as new files #230

Merged
merged 2 commits into from
Mar 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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