summaryrefslogtreecommitdiff
path: root/ftp_gmstranded/entities/weapons/gms_inventory.lua
blob: 15aaa278272bf40337cd45fba022456adcc7bee4 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
AddCSLuaFile()

SWEP.Slot = 2
SWEP.SlotPos = 5

SWEP.Base = "gms_base_weapon"
SWEP.PrintName = "Inventory"
SWEP.ViewModel = "models/Weapons/v_hands.mdl"
SWEP.WorldModel = "models/props_c17/tools_wrench01a.mdl"

SWEP.Purpose = "Lets the user keep structures on them for a certain amount of time."
SWEP.Instructions = "Left click on a structure to pick up a structure."

SWEP.HoldType = "knife"

SWEP.Structures = {}
SWEP.StructureModels = {}

local active = false

// setting time to 0 will make it unlimited

local dSlot = 4
local dTime = 24

group = {

	{
	
		rank = "superadmin",
		slot = 8,
		time = 0,
	},
	
	{
	
		rank = "admin",
		slot = 8,
		time = 0,
	
	},


}

SWEP.FixWorldModel = true
SWEP.FixWorldModelPos = Vector( -1.5, 1, -3 )
SWEP.FixWorldModelAng = Angle( 90, 90, 0 )
SWEP.FixWorldModelScale = 1

local strTBL = {}
local mdlTBL = {}

if (SERVER) then

util.AddNetworkString('invStructures')
util.AddNetworkString('createEntity')

net.Receive('createEntity', function(len, pl)
	
	strTBL = net.ReadTable()
	local slot = net.ReadInt(32)
	mdlTBL = net.ReadTable()
	
	local tr = pl:TraceFromEyes( 200 )
	local loc = tr.HitPos + Vector( 0, 0, 10 )
	
	
	
	
	mbEnt=ents.Create(strTBL[slot])
	
	if ( strTBL[slot] == "gms_fridge" ) then loc = loc + (mbEnt:GetUp() * 50) else mbEnt:DropToGround()  end
	
	mbEnt:SetModel(mdlTBL[slot])
	mbEnt:SetPos(loc)
	mbEnt:Spawn()
	SPropProtection.PlayerMakePropOwner( pl, mbEnt )
	
	pl:PrintMessage(HUD_PRINTTALK, strTBL[slot])
	pl:PrintMessage(HUD_PRINTTALK, slot)
	pl:PrintMessage(HUD_PRINTTALK, mdlTBL[slot])
	
	table.remove(strTBL,slot)
	table.remove(mdlTBL, slot)

	
	
end)

function SWEP:Think()

	self.Structures = strTBL
	self.StructureModels = mdlTBL
	
end

function SWEP:PrimaryAttack()

	self.Structures = strTBL

	local ent = self.Owner:GetEyeTrace().Entity
	if ( SPropProtection.PlayerIsPropOwner( self.Owner, ent ) ) then 
		table.insert(self.Structures, ent:GetClass())
		table.insert(self.StructureModels, ent:GetModel())
		ent:Remove()
		
		net.Start('invStructures')
		
			net.WriteTable(self.Structures)
			net.WriteTable(self.StructureModels)
		
		net.Send(self.Owner)
		
	end
	
end


end



if (CLIENT) then

local StructuresTbl = strTBL
local StructureModelsTbl = mdlTBL

function SWEP:SecondaryAttack()
	
	net.Receive('invStructures', function(len, pl)
			StructuresTbl = net.ReadTable()
			StructureModelsTbl = net.ReadTable()
			//PrintTable(StructuresTbl)
	end)
	
	if ( active == false ) then
		local df = vgui.Create("invPanel")
		active = true
	end
	
end



local PANEL = {}

function PANEL:Init()
	self:SetTitle("")
	
	rowAmount = 1
	
	for k,v in pairs( group ) do
		if (LocalPlayer():IsUserGroup(v['rank'])) then
			dSlot = v['slot']
			dTime = v['time']
		end
		
	end
	
	for i=1,dSlot do
		if (i % 5 == 0) then rowAmount=rowAmount+1 end
	end
	
	OffSet = 5
	
	self:SetSize(400 + (OffSet*5),(rowAmount*100) + (OffSet*(rowAmount+1)) + 20)
	self:SetPos((ScrW()/2)-(self:GetWide()/2),ScrH()-self:GetTall())
	self:ShowCloseButton(true)
	gui.EnableScreenClicker(true)
	
	
	row = 1
	col = 1
	
	
	
	for i=1,dSlot do
		local button = vgui.Create("slotPanel", self)
		
		print(StructuresTbl[i])
		
		if (StructuresTbl[i] != nil and StructureModelsTbl[i] != nil)  then
			
			
			local icon = vgui.Create( "DModelPanel", button )
			icon:SetSize( 100, 150 );
			icon:SetCamPos( Vector( 50,50,50 ) );
			icon:SetLookAt( Vector( 0, 0, -40 ) );
			//icon:SetLookAt( Vector( right, left, up/down ) );
			icon:SetModel( StructureModelsTbl[i] )
			icon:SetText(tostring(StructuresTbl[i]))
			
			icon.DoClick = function()
				
				local mb = DermaMenu()
	
				mb:AddOption("Drop", function()
					
					net.Start('createEntity')
						
						net.WriteTable( StructuresTbl )
						net.WriteInt( i, 32 )
						net.WriteTable( StructureModelsTbl )
						
					net.SendToServer()
					
					table.remove( StructuresTbl, i )
					table.remove( StructureModelsTbl, i )
					
					self:Close()
					local df = vgui.Create("invPanel")
					active = true
				
				end)
				
				mb:Open()
				
			end
		end
		
		
		if (i/4 <= col) then
			
			button:SetPos((row-1)*button:GetWide() + (OffSet*row),(col-1)*button:GetTall() + (OffSet*col) + 20)
			row=row+1
			
		else
			
			row=1
			col=col+1
			button:SetPos((row-1)*button:GetWide() + (OffSet*row),(col-1)*button:GetTall() + (OffSet*col) + 20)
			row=row+1
			
		end
	end
	
end

function PANEL:Paint(w,h)
	if (!LocalPlayer():HasWeapon("gms_inventory")) then return end
	if (LocalPlayer():GetActiveWeapon():GetClass() != "gms_inventory") then
		self:Close()
	end

	draw.RoundedBox( 0, 0, 0, w, h, Color( 48, 48, 48, 255 ) )
	
end

function PANEL:Close()
	active = false
	gui.EnableScreenClicker( false )
	self:Remove()
end

vgui.Register("invPanel", PANEL, "DFrame")

local PANEL = {}

function PANEL:Init()
	
	self:SetSize(100,100)
	self:SetPos(0,0)
	self:SetText("")
	
end

function PANEL:Paint(w,h)
	if (!LocalPlayer():HasWeapon("gms_inventory")) then return end
	draw.RoundedBox( 0, 0, 0, w, h, Color( 24, 24, 24, 255 ) )
	
end

vgui.Register("slotPanel", PANEL, "DButton")

end