Fix bots
This commit is contained in:
parent
97acea9e71
commit
e373f75fca
@ -19,14 +19,10 @@ namespace bots
|
||||
{
|
||||
bool can_add()
|
||||
{
|
||||
if (party::get_client_count() < *game::mp::svs_numclients)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return party::get_client_count() < *game::mp::svs_numclients
|
||||
&& game::SV_Loaded() && !game::VirtualLobby_Loaded();
|
||||
}
|
||||
|
||||
// TODO: when scripting comes, fix this to use better notifies
|
||||
void bot_team_join(const int entity_num)
|
||||
{
|
||||
const game::scr_entref_t entref{static_cast<uint16_t>(entity_num), 0};
|
||||
@ -57,17 +53,20 @@ namespace bots
|
||||
return;
|
||||
}
|
||||
|
||||
// SV_BotGetRandomName
|
||||
const auto* const bot_name = game::SV_BotGetRandomName();
|
||||
auto* bot_ent = game::SV_AddBot(bot_name);
|
||||
static auto first_bot = true;
|
||||
|
||||
const auto bot_name = game::SV_BotGetRandomName();
|
||||
const auto bot_ent = game::SV_AddBot(bot_name);
|
||||
|
||||
if (bot_ent)
|
||||
{
|
||||
spawn_bot(bot_ent->s.entityNum);
|
||||
}
|
||||
else if (can_add()) // workaround since first bot won't ever spawn
|
||||
{
|
||||
add_bot();
|
||||
}
|
||||
// can cause a stack overflow
|
||||
// else if (can_add()) // workaround since first bot won't ever spawn
|
||||
// {
|
||||
// add_bot();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,7 +82,10 @@ namespace bots
|
||||
|
||||
command::add("spawnBot", [](const command::params& params)
|
||||
{
|
||||
if (!game::SV_Loaded() || game::VirtualLobby_Loaded()) return;
|
||||
if (!can_add())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto num_bots = 1;
|
||||
if (params.size() == 2)
|
||||
|
@ -172,8 +172,8 @@ namespace command
|
||||
|
||||
try
|
||||
{
|
||||
const auto arg = params[1];
|
||||
const scripting::entity player = scripting::call("getentbynum", {client_num}).as<scripting::entity>();
|
||||
const auto& arg = params[1];
|
||||
const auto player = scripting::entity({static_cast<uint16_t>(client_num), 0});
|
||||
auto ps = game::SV_GetPlayerstateForClientNum(client_num);
|
||||
|
||||
if (arg == "ammo")
|
||||
@ -243,7 +243,7 @@ namespace command
|
||||
{
|
||||
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");
|
||||
player.call("dropitem", {weapon});
|
||||
}
|
||||
@ -264,7 +264,7 @@ namespace command
|
||||
|
||||
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)
|
||||
{
|
||||
player.call("takeallweapons");
|
||||
@ -285,7 +285,7 @@ namespace command
|
||||
{
|
||||
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"));
|
||||
}
|
||||
catch (...)
|
||||
|
Loading…
Reference in New Issue
Block a user