Need SWEP Help for TTT

So, pretty much, I want to make the AK-47 pull itself out when purchashed from the Traitor shop.
I tried
if CLIENT then
This worked partially, but made anyone else with a 7 slot to equip it.

Someone suggested “Use the TTT hook “TTTOrderedEquipment” so when you buy it, you will use the command “use weapon_ttt_ak47”.” but I am not sure how to do this
Help me Facepunch, you’re my only hope.

if SERVER then
   AddCSLuaFile( "shared.lua" )

if CLIENT then
   SWEP.PrintName = "AK47"
   SWEP.Slot      = 6

   SWEP.ViewModelFOV  = 72
   SWEP.ViewModelFlip = true

SWEP.Base				= "weapon_tttbase"

SWEP.HoldType			= "ar2"

SWEP.Primary.Delay       = 0.10
SWEP.Primary.Recoil      = 2.6
SWEP.Primary.Automatic   = true
SWEP.Primary.Damage      = 17
SWEP.Primary.Cone        = 0.025
SWEP.Primary.Ammo        = "smg1"
SWEP.Primary.ClipSize    = 45
SWEP.Primary.ClipMax     = 90
SWEP.Primary.DefaultClip = 45
SWEP.Primary.Sound       = Sound( "Weapon_AK47.Single" )

SWEP.IronSightsPos = Vector( 6.05, -5, 2.4 )
SWEP.IronSightsAng = Vector( 2.2, -0.1, 0 )

SWEP.ViewModel  = "models/weapons/v_rif_ak47.mdl"
SWEP.WorldModel = "models/weapons/w_rif_ak47.mdl"

SWEP.AutoSpawnable = true
SWEP.AmmoEnt = "item_ammo_smg1_ttt"
SWEP.InLoadoutFor = nil
SWEP.LimitedStock = false
SWEP.AllowDrop = true
SWEP.IsSilent = false
SWEP.NoSights = false

if CLIENT then
   SWEP.Icon = "VGUI/ttt/icon_mac"
   SWEP.EquipMenuData = {
      type = "Weapon",
      desc = "Kill all sons of bitches."

Here’s some information on the hook you spoke about.

Keep in mind, this does not go in the weapon script.

Any idea of what I can do to make this work? I know it’s possible, just not sure how.

You would add the hook, and check if the equipment parameter is equal to “weapon_ttt_ak47” and then make the player equip the item.

hook.Add( “TTTOrderedEquipment”, “UniqueHookName”, YourFunction )

Where do I add the hook? I’m terrible with this.

I think the easiest way to do it is create a new lua file in your gamemode folder, and make your init.lua file include it. I don’t think TTT has a module system like DarkRP, but I wouldn’t know for sure.
Then you add the hook in the new file you created.

So make a init.lua and put in it hook.Add( “TTTOrderedEquipment”, “weapon_ttt_ak47”, YourFunction )

I’m not sure about the function. What kind of function would make the weapon pull out?

You could put it in your init file, but that could get messy.
Here’s an example that might help you out.

local function TestFunction( ply, equipment, is_item )
     if ( equipment == "classname" ) then
          ply:SelectWeapon( "classname" )
hook.Add( "TTTOrderedEquipment", "MyTTTEquipmentHook", TestFunction )

Keep in mind copy and pasting this into your code won’t work, there are still some parts you have to change.

Also you may want to look into…

You might want to have an idea of what your code is actually doing…

local function TestFunction( ply, equipment, is_item )
     if ( equipment == "weapon_ttt_ak47" ) then
          ply:SelectWeapon( "weapon_ttt_ak47" )
hook.Add( "TTTOrderedEquipment", "MyTTTEquipmentHook", TestFunction )

This will work yes? I’m not looking for clean, I’m looking for working.

Yes that looks like it should work.

I just put that in my weapon or another file that adds to my weapon?

No do not put that in your weapon, if you don’t care about the code being messy put in your init.lua file, make sure not to mess up any of the other code in there.

Any chance I can put it in a weapon’s lua/autorun/init.lua or is it required to be in the gamemode/init.lua?

Not quite sure what file you’re referring to, so I’d just stick to the gamemode’s init.lua file.

Go to where the ak47’s shared.lua is and add a file called init.lua . Add it in there.

I’ll try it. Hopefully it works. I’ve seen other servers do it, but unsure how.

[editline]24th December 2013[/editline]

Thank you, that is what I was looking for. I thought so.

Works! Thanks guys!