[Weapon]: PlayerCmd_initialWeaponRaise (#803)

This commit is contained in:
Edo
2023-03-03 23:35:30 +00:00
committed by GitHub
parent 538705c04d
commit 3a3cf77b06
10 changed files with 95 additions and 28 deletions

View File

@ -19,7 +19,7 @@ namespace Components
// Probably a macro 'originally' but this is fine
static Game::gentity_s* Scr_GetPlayerEntity(Game::scr_entref_t entref)
{
if (entref.classnum != 0)
if (entref.classnum)
{
Game::Scr_ObjectError("not an entity");
return nullptr;

View File

@ -548,6 +548,35 @@ namespace Components
}
}
void Weapon::PlayerCmd_initialWeaponRaise(Game::scr_entref_t entref)
{
auto* ent = Script::Scr_GetPlayerEntity(entref);
const auto* weapon = Game::Scr_GetString(0);
const auto index = Game::G_GetWeaponIndexForName(weapon);
auto* ps = &ent->client->ps;
if (!Game::BG_IsWeaponValid(ps, index))
{
return;
}
assert(ps);
if (!index)
{
return;
}
auto* equippedWeapon = Game::BG_GetEquippedWeaponState(ps, index);
if (!equippedWeapon)
{
return;
}
equippedWeapon->usedBefore = false;
Game::Player_SwitchToWeapon(ent);
}
void Weapon::AddScriptMethods()
{
Script::AddMethod("DisableWeaponPickup", [](Game::scr_entref_t entref)
@ -563,6 +592,8 @@ namespace Components
ent->client->ps.weapCommon.weapFlags &= ~Game::PWF_DISABLE_WEAPON_PICKUP;
});
Script::AddMethod("InitialWeaponRaise", PlayerCmd_initialWeaponRaise);
}
Weapon::Weapon()

View File

@ -34,6 +34,9 @@ namespace Components
static void JavelinResetHook_Stub();
static void WeaponEntCanBeGrabbed_Stub();
static void PlayerCmd_initialWeaponRaise(Game::scr_entref_t entref);
static void AddScriptMethods();
};
}