Adding weapons to an addon?

I have an addon that requires a custom weapon I made. How do I go about adding the weapon to the addon, so when I call " ply:Give("<weapon_name>") " it actually recognizes the weapon, and gives the player the weapon?

Any help is appreciated :smiley:

  • FP


local function gibstuff(ply)
    ply:Give("weapon_smg1")
end

hook.Add("PlayerSpawn", "OnSpawn", gibstuff)


in this example, when someone spawns, it gives him SMG1. So just use it.

The problem is not giving players the weapon. The problem is for the game to recognize my custom weapon. I have the weapon (a folder with all the appropriate lua files inside), I just need to place it the right place. That’s what I don’t know.

place the folder (for example “edited_crowbar”) to lua/weapons

Thanks! :smiley:

Use the PlayerLoadout hook instead because giving items on PlayerSpawn gives varying results.

Oh really, can you give an example? Don’t recall having any issues before

GM/PlayerLoadout
I noticed it when coding a mini game last night. When hosting a local game my friend wouldn’t get the chainsaw and instead spawn with his default loadout. It might work well for the local host or in singleplayer but it will fail in multiplayer.

Probably because when you add the hook it overwrites it and therefore stops the player receiving their default loadout.
Try adding a PlayerLoadout hook that returns zero weapons and then use PlayerSpawn to give weapons.

Why would anyone do that? How is adding another hook and using the first one incorrectly a better option?

It isn’t.
I was just pointing it out.
I tried using PlayerLoadout once with ply:SetArmor and it never set the armour for some reason.