How do I make a TTT weapon into an addon?

I want to change all of my TTT weapons into addons, if possible. For instance, I have an MP7 for traitors that has materials to download:


addons\weapon_ttt_mp7\addon.txt
addons\weapon_ttt_mp7\lua
addons\weapon_ttt_mp7\models
addons\weapon_ttt_mp7\lua\autorun
addons\weapon_ttt_mp7\lua\weapons
addons\weapon_ttt_mp7\lua\autorun\weapon_ttt_mp7.lua
addons\weapon_ttt_mp7\lua\weapons\weapon_ttt_mp7
addons\weapon_ttt_mp7\lua\weapons\weapon_ttt_mp7\shared.lua
addons\weapon_ttt_mp7\models\weapons
addons\weapon_ttt_mp7\models\weapons\v_mp7_silenced.dx80.vtx
addons\weapon_ttt_mp7\models\weapons\v_mp7_silenced.dx80.vtx.bz2
addons\weapon_ttt_mp7\models\weapons\v_mp7_silenced.dx90.vtx
addons\weapon_ttt_mp7\models\weapons\v_mp7_silenced.dx90.vtx.bz2
addons\weapon_ttt_mp7\models\weapons\v_mp7_silenced.mdl
addons\weapon_ttt_mp7\models\weapons\v_mp7_silenced.mdl.bz2
addons\weapon_ttt_mp7\models\weapons\v_mp7_silenced.sw.vtx
addons\weapon_ttt_mp7\models\weapons\v_mp7_silenced.sw.vtx.bz2
addons\weapon_ttt_mp7\models\weapons\v_mp7_silenced.vvd
addons\weapon_ttt_mp7\models\weapons\v_mp7_silenced.vvd.bz2
addons\weapon_ttt_mp7\models\weapons\v_mp7_silenced.xbox.vtx
addons\weapon_ttt_mp7\models\weapons\v_mp7_silenced.xbox.vtx.bz2
addons\weapon_ttt_mp7\models\weapons\w_mp7_silenced.dx80.vtx
addons\weapon_ttt_mp7\models\weapons\w_mp7_silenced.dx80.vtx.bz2
addons\weapon_ttt_mp7\models\weapons\w_mp7_silenced.dx90.vtx
addons\weapon_ttt_mp7\models\weapons\w_mp7_silenced.dx90.vtx.bz2
addons\weapon_ttt_mp7\models\weapons\w_mp7_silenced.mdl
addons\weapon_ttt_mp7\models\weapons\w_mp7_silenced.mdl.bz2
addons\weapon_ttt_mp7\models\weapons\w_mp7_silenced.phy
addons\weapon_ttt_mp7\models\weapons\w_mp7_silenced.phy.bz2
addons\weapon_ttt_mp7\models\weapons\w_mp7_silenced.sw.vtx
addons\weapon_ttt_mp7\models\weapons\w_mp7_silenced.sw.vtx.bz2
addons\weapon_ttt_mp7\models\weapons\w_mp7_silenced.vvd
addons\weapon_ttt_mp7\models\weapons\w_mp7_silenced.vvd.bz2
addons\weapon_ttt_mp7\models\weapons\w_mp7_silenced.xbox.vtx
addons\weapon_ttt_mp7\models\weapons\w_mp7_silenced.xbox.vtx.bz2

wepaon_ttt_mp7.lua:


AddCSLUA("autorun/weapon_ttt_mp7.lua")

include("weapons/weapon_ttt_mp7/shared.lua")

if SERVER then
	resource.AddFile("models/weapons/v_mp7_silenced.dx80.vtx")
	resource.AddFile("models/weapons/v_mp7_silenced.dx90.vtx")
	resource.AddFile("models/weapons/v_mp7_silenced.mdl")
	resource.AddFile("models/weapons/v_mp7_silenced.sw.vtx")
	resource.AddFile("models/weapons/v_mp7_silenced.vvd")
	resource.AddFile("models/weapons/v_mp7_silenced.xbox.vtx")
	resource.AddFile("models/weapons/w_mp7_silenced.dx80.vtx")
	resource.AddFile("models/weapons/w_mp7_silenced.dx90.vtx")
	resource.AddFile("models/weapons/w_mp7_silenced.mdl")
	resource.AddFile("models/weapons/w_mp7_silenced.phy")
	resource.AddFile("models/weapons/w_mp7_silenced.sw.vtx")
	resource.AddFile("models/weapons/w_mp7_silenced.vvd")
	resource.AddFile("models/weapons/w_mp7_silenced.xbox.vtx")
end

shared.lua has all of the SWEP logic. As you can tell, I’m just throwing code against the wall to see if it will stick. Any help is more than appreciated.

That autorun lua code was a really bad idea:


[Lelouch Lamperouge|18|] Lua Error:

[ERROR] addons/weapon_ttt_ak47/lua/weapons/weapon_ttt_ak47/shared.lua:9: attempt to index global 'SWEP' (a nil value)
  1. unknown - addons/weapon_ttt_ak47/lua/weapons/weapon_ttt_ak47/shared.lua:9
   2. include - [C]:-1
    3. unknown - addons/weapon_ttt_ak47/lua/autorun/weapon_ttt_ak47.lua:3


[Lelouch Lamperouge|18|] Lua Error:

[ERROR] addons/weapon_ttt_mp7/lua/weapons/weapon_ttt_mp7/shared.lua:6: attempt to index global 'SWEP' (a nil value)
  1. unknown - addons/weapon_ttt_mp7/lua/weapons/weapon_ttt_mp7/shared.lua:6
   2. include - [C]:-1
    3. unknown - addons/weapon_ttt_mp7/lua/autorun/weapon_ttt_mp7.lua:1


[Lelouch Lamperouge|18|] Lua Error:

[ERROR] addons/weapon_ttt_sg552/lua/weapons/weapon_ttt_sg552/shared.lua:10: attempt to index global 'SWEP' (a nil value)
  1. unknown - addons/weapon_ttt_sg552/lua/weapons/weapon_ttt_sg552/shared.lua:10
   2. include - [C]:-1
    3. unknown - addons/weapon_ttt_sg552/lua/autorun/weapon_ttt_sg552.lua:1

In any case, I restarted the server twice and the weapons seem to be working…

I don’t really understand what you’re trying to do. Can you be more descriptive?

Trying to make it an add-on? If so make a new folder in gmod/addons and split it into the relevant folders. So anything in “terrortown/” would be split under folders in “addons/mp7/lua/”. FOr example:


addons/mp7/lua/weapons/weapon_ttt_mp7.lua 
         addons/mp7/materials/ 
         addons/mp7/models

Edited:

In the case of the AK47 there really isn’t a need be if you really want to all you need to do is get the shared.lua from terrotown/entities/weapons and put in gmod/addons/ak47/lua/weapons but really addons for TTT are really only needed for something with custom models/particles etc as CSS content is already mounted.

okay, please get this Fox warriors resource generator

click file>manage file extensions> make sure the following file types are added
.mdl, .vmt, .vtf, .wav, .mp3, .png

then use that tool to make your lua files.

to make it into an addon you can usually just put it in one folder(like other addons) and drop it in the addons folder (it requires a server restart not a map change though)

His resource.AddFile’s are fine.

Sorry for the late reply guys. It’s working now. I don’t know how I fixed it but all of my weapons are loading now.