FAS Permanent Attachments per Player System

Hey,
How would I do this:
I want users to be able to buy fas2 attachments in the pointshop.
After pourchase, they should have them permanently.
This is my current plan: A Table in the PData with all the Attachments that the user bought inside.
Now I need something that gives the player the fas attachments every join/round (I dont know if fas attachments are removed after round end?)
Gamemode is TTT
Any idea?

Here is some code to give players FAS2 attachments


			ply:FAS2_PickUpAttachment("compm4")
			ply:FAS2_PickUpAttachment("foregrip")
			ply:FAS2_PickUpAttachment("acog")
			ply:FAS2_PickUpAttachment("c79")
			ply:FAS2_PickUpAttachment("eotech")
			ply:FAS2_PickUpAttachment("harrisbipod")
			ply:FAS2_PickUpAttachment("leupold")
			ply:FAS2_PickUpAttachment("m2120mag")
			ply:FAS2_PickUpAttachment("mp5k30mag")
			ply:FAS2_PickUpAttachment("sg55x30mag")
			ply:FAS2_PickUpAttachment("sks30mag")
			ply:FAS2_PickUpAttachment("sks20mag")
			ply:FAS2_PickUpAttachment("suppressor")
			ply:FAS2_PickUpAttachment("tritiumsights")
			ply:FAS2_PickUpAttachment("uziwoodenstock")

Not sure if this helped you but you may need it (this is all attachments)

That helped me a lot, thanks! :slight_smile:
The only thing left I need to know is when FAS Attachments are removed (every round or just after dc)?

The attachment should despawn when the person dies.

Thanks for the info! :slight_smile:
I’ll just give them on PlayerSpawn then.
I hope I can manage to finish this project (Currently learning glua).
If I have any other questions I will post them here! :slight_smile:

[editline]14th August 2015[/editline]

I want to have an entry in the PData named fas2_perma_attachments.
This should be a table containing all the attachments the player has bought.
I never did this before so could anybody give me an example on how to add something to a table in the PData?
This is what I got until now:
ply:SetPData( “fas2_perma_attachments”, { } )


local fasAttachment = "suppressor"
local newAttachments
	
function ITEM:CanBeUsed( )	
	local ply = self:GetOwner()
	local currentAttachments = ply:GetPData( "fas_permanent_attachments", {} )
	
	if table.HasValue( currentAttachments, fasAttachment ) then 
		return false, "Du hast bereits dieses Attachment"
	end
	return true
end

function ITEM:OnUse( )
	local ply = self:GetOwner()
	local currentAttachments = ply:GetPData( "fas_permanent_attachments", {} )
	if not table.HasValue( currentAttachments, fasAttachment ) then
		print( currentAttachments )
		print( fasAttachment )
		table.Insert( currentAttachments, fasAttachment )
	end
	ply:SetPData( "fas_permanent_attachments", newAttachments )
end

This is my code for the item itself atm. I’m getting this error:


[ERROR] Item KInventory.Items.item_attachment_suppressor Use failed: addons/fas_perma_attachments/lua/kinv/items/pointshop/single_use/sh_item_attachment_suppressor.lua:29: attempt to call field 'Insert' (a nil value)

[editline]14th August 2015[/editline]

The prints are just for debugging.
Results are the following:
table: 0x20d8e758
suppressor

[editline]14th August 2015[/editline]

Found the issue:
It needs to be table.insert instead of table.Insert :3

Why are you setting the pdata by newattachments value if you are not doing nothing with it

I allready fixed this issue. I don’t know why I used this new var :3