How to create a TTT Traitor Equipment Menu Item?

I`m new to lua programing, and Im trying to create a item on the Traitor Equipment Menu so traitors can buy it… As the player buy this item for 1 credit on Equipment Menu, I want it to perform a action about that player, something like this:


ply:FAS2_PickUpAttachment("Example_Attachment")

How should I proceed? I dont want to put someone to do it for me, I just want to learn how to do it :). Thanks in advance.

[lua]
AddCSLuaFile()

hook.Add(“Initialize”, “InitializeCustomTTTItems”, function() – delay until gamemode is loaded
if !EquipmentItems then return end – not TTT

EQUIP_ATTACHMENT = 8 -- each item has to have a unique ID which is a multiple of 2 (1,2,4,8,16)

for role,items in pairs(EquipmentItems) do
	for _,item in pairs(items) do
		if item.id > EQUIP_ATTACHMENT then -- if the ID you picked already exists increase it
			EQUIP_ATTACHMENT = item.id*2
		end
	end
end

local tbl = { -- create the data for your item
	id = EQUIP_ATTACHMENT,
	type = "item_passive",
	material = "your icon goes here", -- path to the icon
	name = "Attachment",
	desc = "It's an attachment or something" -- description shown in menu
}

table.insert(EquipmentItems[ROLE_TRAITOR], tbl) -- Add the equipment to traitor menu
    --table.insert(EquipmentItems[ROLE_DETECTIVE], tbl) -- uncomment this line if you want it for detectives

end)

if SERVER then
hook.Add(“TTTOrderedEquipment”, “TTTAddAttachment”, function(ply, equipment, is_item) – Called when a player orders something
if equipment == EQUIP_ATTACHMENT then – if the player ordered our item
ply:FAS2_PickUpAttachment(“Example_Attachment”) – your code here
end
end)
end
[/lua]

Typed this up from scratch and it’s untested but it should work, shared lua file

Throw it in lua/entities, thats where I’ve put my equipment

OP is talking about the passive stuff, like Radar/Armor. Goz3rr gave him the solution.

Thank you Goz3rr! I will be able to do so much things right now o… It makes me sad that Garrys Mod references are so unclear to me… Im a Automation Engineer and Im still not able to understand how Gmod lua references work completely… Especially when it is about TTT scripts. Thank you all =) I love you

It usually helps looking at the original implementation, which is this case is equip_items_shd.lua which adds all the passive TTT items