How to make Custom Weapons global?

Hello everyone,

I’m trying to install a few Weapons Custom Weapons what should be able to be purchased from the gun shop or/and from a job locker it shouldn’t be just like able to access it via vMenu it should be able to be obtained via the gun shop job locker or even with the command does anyone know if there is a way to make one of them come true? Because I’m pertty interested if it would work or not

(Thanks in advance)

By C.

Hello.

If you are referring to replacing some weapons with custom models your pre existing gun store should work fine and already have them, it just depends on what weapons are available to purchase from the store.

If you are referring to add-on weapons then your pre existing gun store will not feature the weapons automatically, the add-on weapons will have a hash which can be used like standard weapon hashes to spawn them and give them to players.

In your gun store, it should have a config file or something where you can control the weapons that are in the store. You will just need to add the add-on weapons to this table.

To get the add-on weapons hash you can just use the file name, much like car spawn names.

Whenever coding or modifying scripts it can be useful to check out https://docs.fivem.net/natives/, for your needs you are looking at using:

Hopefully this answers your question :slightly_smiling_face:

Hello there,

Thanks for the quick answer yes in fact I did reference to a add-on weapon what is not a replace but I am interasted how am I gonna get that “hash” from the Weapon in example this this flashbang I am kind of new to this thing and I really tried to understand from the links you have provided to me but sadly I wasn’t able to get much out of with it but your Explanation I fully understood it theoractically but anyway…! Is by hash meant: WEAPON_FLASHBANG…?

That’s ok, ill try explain it a bit better.

So like how cars have a spawn name, weapons have spawn names. You can find both very easily, when you add vehicles to your server you have the meta files for example handling.meta, the same goes for weapons. To find the spawn name its just the text before the .ytd file, for example cara.ytd would have a spawn name of cara. For the flashbang, the spawn name would be WEAPON_FLASHBANG.

To get the hash of the weapons you should look at native GetHashKey - Natives @ Cfx.re Docs, sorry for not linking it above. So you could do something like

local weaponhash = GetHashKey(‘WEAPON_FLASHBANG’)
local ammo = 10
GiveWeaponToPed(PlayerPedId(), weaponhash, ammo, 0, false)

In the above example you would add the Flashbang to the player and they will have 10 of them.

However, you can also do

local weaponname = WEAPON_FLASHBANG
local ammo = 10
GiveWeaponToPed(PlayerPedId(), weaponname, ammo, 0, false)

Both will work, just the second way is the preferred method by some people.

Let me know how you go :slight_smile:

Hey Hey,

Thanks for the answer and sorry for the late reply but it worked! Is there a possibility that it wont get deleted from my inventory when I rejoin or is there no way to get the weapon well to stay in the inventory?

If your using a inventory you will need to create a new item similar to your other weapon items, except change the information to match the new weapon. Then just give the player the item.

Thank you so much that really helped me ^^

No problem, glad I could help :slightly_smiling_face: