summaryrefslogtreecommitdiff
path: root/gamemode/itemsystem/items/armor.lua
blob: cf0ce40c2dd8e64e87dec753ec28682e483dfa10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
local materials = {

  "Copper",
  "Iron",
  "Tech",
  "Silver",
  "Gold",
  "Steel",
  "Platinum",
  
}

local parts = {

	"Helmet",
	"Platebody",
	"Platelegs",
	"Boots",
	
}

if(SERVER) then
	util.AddNetworkString( "gms_equip" )
end

local equip_server = function(ln,player)
	tbl = net.ReadTable()
	t = net.ReadString( 32 )
	player:DecResource( tbl.Item, 1 )
	player:SendMessage( tbl.Type.." Equipped!", 3, Color( 10, 200, 10, 255 ) )
	bool = net.ReadBool()
	sName = net.ReadString( 32 )
	if !bool then return end
	player:SendMessage( sName, 3, Color( 10, 200, 10, 255 ) )
	player:IncResource( sName, 1 )

end
net.Receive( "gms_equip", equip_server )

for k,v in pairs(parts) do
	for o,p in pairs(materials) do
		
		local ITEM = {}
		ITEM.Name = p.." "..v
		ITEM.Description = v.." that will protect you."
		ITEM.Icon = "test.png"
		ITEM.Type = v
		ITEM.UniqueData = false
		ITEM.Actions = {}
		genericMakeDroppable(ITEM)
		ITEM.Actions["Equip"] = function()
			
			local tbl = { Item = ITEM.Name, Icon = ITEM.Icon, Type = ITEM.Type, Description = ITEM.Description }
			local sName = "-"
			for g,h in pairs(GMS.Equipped) do
				if h['Type'] == tbl.Type then
					tbl2 = table.remove(GMS.Equipped,g)
					sName = tbl2.Item
					break
				end
			end
			
			table.insert( GMS.Equipped, tbl )
			net.Start("gms_equip")
			  net.WriteTable( tbl )
			  net.WriteString( v, 32 )
			  if sName != "-" then net.WriteBool( true ) else net.WriteBool( false ) end
			  net.WriteString( sName, 32 )
			  
			net.SendToServer()
			
		end
		GMS.RegisterResource(ITEM)
		
	end
end