This commit is contained in:
Federico Cecchetto 2022-03-13 23:12:34 +01:00
parent 97acea9e71
commit e373f75fca
2 changed files with 21 additions and 19 deletions

View File

@ -19,14 +19,10 @@ namespace bots
{ {
bool can_add() bool can_add()
{ {
if (party::get_client_count() < *game::mp::svs_numclients) return party::get_client_count() < *game::mp::svs_numclients
{ && game::SV_Loaded() && !game::VirtualLobby_Loaded();
return true;
}
return false;
} }
// TODO: when scripting comes, fix this to use better notifies
void bot_team_join(const int entity_num) void bot_team_join(const int entity_num)
{ {
const game::scr_entref_t entref{static_cast<uint16_t>(entity_num), 0}; const game::scr_entref_t entref{static_cast<uint16_t>(entity_num), 0};
@ -57,17 +53,20 @@ namespace bots
return; return;
} }
// SV_BotGetRandomName static auto first_bot = true;
const auto* const bot_name = game::SV_BotGetRandomName();
auto* bot_ent = game::SV_AddBot(bot_name); const auto bot_name = game::SV_BotGetRandomName();
const auto bot_ent = game::SV_AddBot(bot_name);
if (bot_ent) if (bot_ent)
{ {
spawn_bot(bot_ent->s.entityNum); spawn_bot(bot_ent->s.entityNum);
} }
else if (can_add()) // workaround since first bot won't ever spawn // can cause a stack overflow
{ // else if (can_add()) // workaround since first bot won't ever spawn
add_bot(); // {
} // add_bot();
// }
} }
} }
@ -83,7 +82,10 @@ namespace bots
command::add("spawnBot", [](const command::params& params) command::add("spawnBot", [](const command::params& params)
{ {
if (!game::SV_Loaded() || game::VirtualLobby_Loaded()) return; if (!can_add())
{
return;
}
auto num_bots = 1; auto num_bots = 1;
if (params.size() == 2) if (params.size() == 2)

View File

@ -172,8 +172,8 @@ namespace command
try try
{ {
const auto arg = params[1]; const auto& arg = params[1];
const scripting::entity player = scripting::call("getentbynum", {client_num}).as<scripting::entity>(); const auto player = scripting::entity({static_cast<uint16_t>(client_num), 0});
auto ps = game::SV_GetPlayerstateForClientNum(client_num); auto ps = game::SV_GetPlayerstateForClientNum(client_num);
if (arg == "ammo") if (arg == "ammo")
@ -243,7 +243,7 @@ namespace command
{ {
try try
{ {
const scripting::entity player = scripting::call("getentbynum", {client_num}).as<scripting::entity>(); const auto player = scripting::entity({static_cast<uint16_t>(client_num), 0});
const auto weapon = player.call("getcurrentweapon"); const auto weapon = player.call("getcurrentweapon");
player.call("dropitem", {weapon}); player.call("dropitem", {weapon});
} }
@ -264,7 +264,7 @@ namespace command
try try
{ {
const scripting::entity player = scripting::call("getentbynum", {client_num}).as<scripting::entity>(); const auto player = scripting::entity({static_cast<uint16_t>(client_num), 0});
if (weapon == "all"s) if (weapon == "all"s)
{ {
player.call("takeallweapons"); player.call("takeallweapons");
@ -285,7 +285,7 @@ namespace command
{ {
try try
{ {
const scripting::entity player = scripting::call("getentbynum", {client_num}).as<scripting::entity>(); const auto player = scripting::entity({static_cast<uint16_t>(client_num), 0});
player.call(SELECT_VALUE("kill", "suicide")); player.call(SELECT_VALUE("kill", "suicide"));
} }
catch (...) catch (...)