Hello, Guest

By registering with us, you'll be able to discuss, share and private message with other members of our community.
What's new

Fixed weapon change when emptying a magazine

Alexalsaud

Administrative
Staff member
Admin
Joined
Aug 5, 2024
Messages
337
ICoins
1,501

Fixed weapon change when emptying a magazine


All the code presented is inserted into the client_packages / Index.js

JavaScript:
mp.game.weapon.unequipEmptyWeapons = false;

for JS

JavaScript:
сonst SET_CURRENT_PED_WEAPON = '0xADF692B254977C0C';
mp.events.add("playerWeaponShot" async (targetPosition, targetEntity) => {
if (mp.players.local.getAmmoInClip(mp.players.local.weapon) == 0) {
let weapon = mp.players.local.weapon
mp.game.invoke(SET_CURRENT_PED_WEAPON, mp.players.local.handle, mp.game.joaat('weapon_unarmed') >> 0, true)
await mp.game.waitAsync(0);
mp.game.invoke(SET_CURRENT_PED_WEAPON, mp.players.local.handle, weapon >> 0, true)
})

For C#

C#:
Events.OnPlayerWeaponShot += async (Vector3 targetPos, RAGE.Elements.Player target, Events.CancelEventArgs cancel) => // фикс "застревания" оружия на последнем выстреле
{
var weapon = SDK.Utils.GetCurrentWeapon(SDK.References.LocalPlayer);
if (SDK.References.LocalPlayer.GetAmmoInWeapon((uint)weapon) == 0)
{
SDK.References.LocalPlayer.SetCurrentWeapon((uint)WeaponHash.Unarmed, true);
await RAGE.Game.Invoker.WaitAsync(0);
SDK.References.LocalPlayer.SetCurrentWeapon((uint)weapon, true);
}
};


When you use native, the advice is to somehow indicate its name.

JavaScript:
const SET_CURRENT_PED_WEAPON = '0xADF692B254977C0C';
mp.game.invoke(SET_CURRENT_PED_WEAPON, mp.players.local.handle, mp.game.joaat('weapon_unarmed') >> 0, true);
 
Back
Top