Get rid of direct checks of bistestclient

This commit is contained in:
FutureRave 2022-05-07 00:49:29 +01:00
parent d75a5a71e5
commit 849b890a96
No known key found for this signature in database
GPG Key ID: E883E2BC9657D955

View File

@ -111,9 +111,7 @@ namespace Components
void Bots::GScr_isTestClient(Game::scr_entref_t entref)
{
const auto* ent = Game::GetPlayerEntity(entref);
const auto* client = Script::GetClient(ent);
Game::Scr_AddBool(client->bIsTestClient == 1);
Game::Scr_AddBool(Game::SV_IsTestClient(ent->s.number) != 0);
}
void Bots::AddMethods()
@ -130,7 +128,7 @@ namespace Components
const auto* ent = Game::GetPlayerEntity(entref);
auto* client = Script::GetClient(ent);
if (!client->bIsTestClient)
if (Game::SV_IsTestClient(ent->s.number) == 0)
{
Game::Scr_Error("^1SetPing: Can only call on a bot!\n");
return;
@ -142,9 +140,8 @@ namespace Components
Script::AddMethod("BotStop", [](Game::scr_entref_t entref) // Usage: <bot> BotStop();
{
const auto* ent = Game::GetPlayerEntity(entref);
const auto* client = Script::GetClient(ent);
if (!client->bIsTestClient)
if (Game::SV_IsTestClient(ent->s.number) == 0)
{
Game::Scr_Error("^1BotStop: Can only call on a bot!\n");
return;
@ -157,17 +154,16 @@ namespace Components
Script::AddMethod("BotWeapon", [](Game::scr_entref_t entref) // Usage: <bot> BotWeapon(<str>);
{
const auto* weapon = Game::Scr_GetString(0);
const auto* ent = Game::GetPlayerEntity(entref);
const auto* client = Script::GetClient(ent);
if (!client->bIsTestClient)
if (Game::SV_IsTestClient(ent->s.number) == 0)
{
Game::Scr_Error("^1BotWeapon: Can only call on a bot!\n");
return;
}
const auto* weapon = Game::Scr_GetString(0);
if (weapon == nullptr || weapon[0] == '\0')
{
g_botai[entref.entnum].weapon = 1;
@ -181,6 +177,14 @@ namespace Components
Script::AddMethod("BotAction", [](Game::scr_entref_t entref) // Usage: <bot> BotAction(<str action>);
{
const auto* ent = Game::GetPlayerEntity(entref);
if (Game::SV_IsTestClient(ent->s.number) == 0)
{
Game::Scr_Error("^1BotAction: Can only call on a bot!\n");
return;
}
const auto* action = Game::Scr_GetString(0);
if (action == nullptr)
@ -189,15 +193,6 @@ namespace Components
return;
}
const auto* ent = Game::GetPlayerEntity(entref);
const auto* client = Script::GetClient(ent);
if (!client->bIsTestClient)
{
Game::Scr_Error("^1BotAction: Can only call on a bot!\n");
return;
}
if (action[0] != '+' && action[0] != '-')
{
Game::Scr_ParamError(0, "^1BotAction: Sign for action must be '+' or '-'.\n");
@ -223,20 +218,16 @@ namespace Components
Script::AddMethod("BotMovement", [](Game::scr_entref_t entref) // Usage: <bot> BotMovement(<int>, <int>);
{
auto forwardInt = Game::Scr_GetInt(0);
auto rightInt = Game::Scr_GetInt(1);
const auto* ent = Game::GetPlayerEntity(entref);
const auto* client = Script::GetClient(ent);
if (!client->bIsTestClient)
if (Game::SV_IsTestClient(ent->s.number) == 0)
{
Game::Scr_Error("^1BotMovement: Can only call on a bot!\n");
return;
}
forwardInt = std::clamp<int>(forwardInt, std::numeric_limits<char>::min(), std::numeric_limits<char>::max());
rightInt = std::clamp<int>(rightInt, std::numeric_limits<char>::min(), std::numeric_limits<char>::max());
const auto forwardInt = std::clamp<int>(Game::Scr_GetInt(0), std::numeric_limits<char>::min(), std::numeric_limits<char>::max());
const auto rightInt = std::clamp<int>(Game::Scr_GetInt(1), std::numeric_limits<char>::min(), std::numeric_limits<char>::max());
g_botai[entref.entnum].forward = static_cast<int8_t>(forwardInt);
g_botai[entref.entnum].right = static_cast<int8_t>(rightInt);