[Bots] Spawn models delayed

This commit is contained in:
momo5502 2017-04-24 21:14:08 +02:00
parent 1e617dc299
commit 91c9cda59f
2 changed files with 32 additions and 38 deletions

View File

@ -38,38 +38,36 @@ namespace Components
strncpy_s(buffer, 0x400, Utils::String::VA(connectString, num, Bots::BotNames[botId++].data(), protocol, checksum, statVer, statStuff, port), 0x400);
}
unsigned int Bots::Spawn(unsigned int count)
void Bots::Spawn(unsigned int count)
{
int error = 0;
std::vector<Game::gentity_t*> entRefs;
for (unsigned int i = 0; i < count; ++i)
{
std::this_thread::sleep_for(10ms);
Game::gentity_t* entRef = Game::SV_AddTestClient();
if (entRef) entRefs.push_back(entRef);
else if (++error == 3) break;
}
for (auto& entRef : entRefs)
{
Renderer::OnDelay([entRef]()
Renderer::OnDelay([]()
{
Game::Scr_AddString("autoassign");
Game::Scr_AddString("team_marinesopfor");
Game::Scr_Notify(entRef, Game::SL_GetString("menuresponse", 0), 2);
Renderer::OnDelay([entRef]()
for (int i = 0; i < 3; ++i)
{
Game::Scr_AddString(Utils::String::VA("class%d", Utils::Cryptography::Rand::GenerateInt() % 5));
Game::Scr_AddString("changeclass");
Game::Scr_Notify(entRef, Game::SL_GetString("menuresponse", 0), 2);
}, 1s);
}, 1s);
}
Game::gentity_t* entRef = Game::SV_AddTestClient();
if (entRef)
{
Renderer::OnDelay([entRef]()
{
Game::Scr_AddString("autoassign");
Game::Scr_AddString("team_marinesopfor");
Game::Scr_Notify(entRef, Game::SL_GetString("menuresponse", 0), 2);
return entRefs.size();
Renderer::OnDelay([entRef]()
{
Game::Scr_AddString(Utils::String::VA("class%d", Utils::Cryptography::Rand::GenerateInt() % 5));
Game::Scr_AddString("changeclass");
Game::Scr_Notify(entRef, Game::SL_GetString("menuresponse", 0), 2);
}, 1s);
}, 1s);
break;
}
}
}, 500ms * (i + 1));
}
}
Bots::Bots()
@ -90,24 +88,20 @@ namespace Components
else count = atoi(params->get(1));
}
count = std::min(18u, count);
// Check if ingame and host
if (!Game::SV_Loaded())
{
Toast::Show("cardicon_headshot", "^1Error", "You need to be host to spawn bots!", 3000);
Logger::Print("You need to be host to spawn bots!\n");
return;
}
count = Bots::Spawn(count);
if (count)
{
Toast::Show("cardicon_headshot", "^2Success", Utils::String::VA("%d %s spawned", count, (count == 1 ? "bot" : "bots")), 3000);
Logger::Print("%d %s spawned successfully!\n", count, (count == 1 ? "bot" : "bots"));
}
else
{
Toast::Show("cardicon_headshot", "^1Error", "Unable to spawn new bots!", 3000);
Logger::Print("Unable to spawn new bots!");
}
Toast::Show("cardicon_headshot", "^2Success", Utils::String::VA("Spawning %d %s...", count, (count == 1 ? "bot" : "bots")), 3000);
Logger::Print("Spawning %d %s...\n", count, (count == 1 ? "bot" : "bots"));
Bots::Spawn(count);
});
}

View File

@ -17,6 +17,6 @@ namespace Components
static void BuildConnectString(char* buffer, const char* connectString, int num, int, int protocol, int checksum, int statVer, int statStuff, int port);
static unsigned int Spawn(unsigned int count);
static void Spawn(unsigned int count);
};
}