[HELP] How to create script like weapon case

How to create script like weapon case (it must be item and it should give weapon (it can be pistol) and 100 ammo) if any one can send me code foe that i really appreciate it.

1 Like

This is a base function to add a weapon to the source.

function giveWeapon(gunhash)
    GiveWeaponToPed(GetPlayerPed(-1), GetHashKey(gunhash), AMMO INT HERE, false, true) -- Obviously change the apparent text to the desired amount of ammo 
end

Example Usage:

RegisterCommand("gun", function(source, args, raw)
  gun = args[1] -- Gets the first "word" argument in the command
  giveWeapon("weapon_pistol") -- weapon name you want added.
end)

Full weapon name docs can be found here

Hope this helps

and this should work as item? (i’m using esx_extraitems and i want to put this weapon box in to this esx because i want to use it as item (i’m not to advanced because this is my first FiveM server))

this is 1 of items from this esx and i want to put this line u send to me to this script and i don’t know how to use it in this script i if u can send me line i can paste in to this script i rely appreciate it ( line of code from this scrpt : RegisterNetEvent(‘esx_extraitems:weaclip’)
AddEventHandler(‘esx_extraitems:weaclip’, function()
local playerPed = GetPlayerPed(-1)

if IsPedArmed(playerPed, 4) then
	hash = GetSelectedPedWeapon(playerPed)
	ammo = Config.WeaponClipAmmo
	if hash ~= nil then
		AddAmmoToPed(GetPlayerPed(-1), hash, ammo)
		TriggerServerEvent('esx_extraitems:removeweaclip')
		ESX.ShowNotification(_U('used_weaclip'))
	else
		ESX.ShowNotification(_U('no_weapon'))
	end
else
	ESX.ShowNotification(_U('not_suitable'))
end

end)

end of line from this script )

Thanks to @nathangladney, try adding this in your extra items server.lua.

ESX.RegisterUsableItem('guncase', function(source) --Change to your desired weapon e.g. uzicase and add it as an item in your db

    local xPlayer = ESX.GetPlayerFromId(source)

    xPlayer.removeInventoryItem('guncase', 1) --Change it to the desired weapon

    giveWeapon("weapon_pistol") -- weapon name you want added.

end)

Also dont forget to add your item to your database

P.S. I’m not so much into coding, this might be wrong but worth trying :smiley:

i can’t use this item (i have it in inventory and is i click on it i don’t have use option)

now i have use option but when i press it server don’t give me weapon (don’t give me anything and i still have guncase)

xPlayer.giveWeapon("weapon_pistol") -- weapon name you want added.

Try replacing last line with this