New function GiveAmmoToWeapon()

Started by [TDA]Speed, Mar 27, 2025, 08:07 PM

Previous topic - Next topic

[TDA]Speed

what this function used for ?
this function used to give the player ammo or weapon without changing his current weapon

GiveAmmoToWeapon(player, WeaponID, ammo);


place this function anywhere
function GiveAmmoToWeapon(player, weapon, amount)
{
local currentwep = player.Weapon;
local currentammo = player.GetAmmoAtSlot(player.Slot);
local weapon = weapon;
amount = amount;
player.GiveWeapon(weapon,amount);
if (currentwep != weapon ) player.SetWeapon(currentwep,currentammo);
}


example usage

if (player.GetWeaponAtslot(6) == 26) GiveAmmoToWeapon(player, 26, 30);

if player holding shotgun and picked m4 it will not change his weapon and will give him ammo for m4 without changing his weapon