Skip to content

Commit

Permalink
Add BotMeleeParams builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
ineed bots committed Dec 10, 2023
1 parent e9debbd commit d3f49d2
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Components/Modules/Bots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace Components
std::int8_t right;
std::uint16_t weapon;
std::uint16_t lastAltWeapon;
std::uint8_t meleeDist;
float meleeYaw;
bool active;
};

Expand Down Expand Up @@ -292,6 +294,23 @@ namespace Components
g_botai[entref.entnum].right = static_cast<int8_t>(rightInt);
g_botai[entref.entnum].active = true;
});

GSC::Script::AddMethod("BotMeleeParams", [](const Game::scr_entref_t entref) // Usage: <bot> BotMeleeParams(<float>, <float>);
{
const auto* ent = GSC::Script::Scr_GetPlayerEntity(entref);
if (!Game::SV_IsTestClient(ent->s.number))
{
Game::Scr_Error("BotMeleeParams: Can only call on a bot!");
return;
}

const auto yaw = Game::Scr_GetFloat(0);
const auto dist = std::clamp<int>(static_cast<int>(Game::Scr_GetFloat(1)), std::numeric_limits<unsigned char>::min(), std::numeric_limits<unsigned char>::max());

g_botai[entref.entnum].meleeYaw = yaw;
g_botai[entref.entnum].meleeDist = static_cast<int8_t>(dist);
g_botai[entref.entnum].active = true;
});
}

void Bots::BotAiAction(Game::client_s* cl)
Expand Down Expand Up @@ -320,6 +339,8 @@ namespace Components
userCmd.rightmove = g_botai[clientNum].right;
userCmd.weapon = g_botai[clientNum].weapon;
userCmd.primaryWeaponForAltMode = g_botai[clientNum].lastAltWeapon;
userCmd.meleeChargeYaw = g_botai[clientNum].meleeYaw;
userCmd.meleeChargeDist = g_botai[clientNum].meleeDist;

userCmd.angles[0] = ANGLE2SHORT((cl->gentity->client->ps.viewangles[0] - cl->gentity->client->ps.delta_angles[0]));
userCmd.angles[1] = ANGLE2SHORT((cl->gentity->client->ps.viewangles[1] - cl->gentity->client->ps.delta_angles[1]));
Expand Down

0 comments on commit d3f49d2

Please sign in to comment.