summaryrefslogtreecommitdiff
path: root/gamemode/cl_init.lua
blob: a2a4b665cf22dc6df96654a4a685b0ad44a5797b (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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
print("Included cl_init.lua")
include( "configure_me.lua")
include( "utility.lua")
includeFolder("craftablesystem",true)
includeFolder("itemsystem",true)
includeFolder("client",true)
includeFolder("shared",true)

include( "shared.lua" )

--include( "cl_qmenu.lua" )
include( "cl_scoreboard.lua" )
include( "cl_panels.lua" )
include( "cl_hud.lua" )
include( "cl_deathmenu.lua" )



-- HUD Theme
StrandedColorTheme = Color( 0, 0, 0, 240 )
StrandedBorderTheme = Color( 0, 0, 0, 180 )

StrandedBackgroundColor = Color( 0, 0, 0, 180 )
StrandedForegroundColor = Color( 0, 128, 176, 220 )
StrandedBorderColor = Color( 0, 0, 0, 150 )
StrandedTextColor = color_white
StrandedTextShadowColor = Color( 100, 100, 100, 140 )

StrandedHealthColor = Color( 176, 0, 0, 240 )
StrandedHungerColor = Color( 0, 176, 0, 240 )
StrandedThirstColor = Color( 0, 0, 176, 240 )
StrandedFatigueColor = Color( 176, 0, 176, 240 )
StrandedOxygenColor = Color( 0, 200, 200, 220 )
StrandedPowerColor = Color( 200, 200, 0, 220 )

-- Clientside player variables
Tribes = Tribes or {}
Skills = Skills or {}
Resources = Resources or {}
Experience = Experience or {}
FeatureUnlocks = FeatureUnlocks or {}
MaxResources = MaxResources or 25
CampFires = CampFires or {}

Sleepiness = Sleepiness or 1000
Hunger = Hunger or 1000
Thirst = Thirst or 1000
Oxygen = Oxygen or 1000
Power = Power or 50

/* Language */
language.Add( "gms_stonefurnace", "Stone Furnace" )
language.Add( "gms_stoneworkbench", "Stone Workbench" )
language.Add( "gms_copperfurnace", "Copper Furnace" )
language.Add( "gms_copperworkbench", "Copper Workbench" )
language.Add( "gms_ironfurnace", "Iron Furnace" )
language.Add( "gms_ironworkbench", "Iron Workbench" )
language.Add( "gms_techfurnace", "Tech Furnace" )
language.Add( "gms_techworkbench", "Tech Workbench" )
language.Add( "gms_silverfurnace", "Silver Furnace" )
language.Add( "gms_silverworkbench", "Silver Workbench" )
language.Add( "gms_goldfurnace", "Gold Furnace" )
language.Add( "gms_goldworkbench", "Gold Workbench" )
language.Add( "gms_steelfurnace", "Steel Furnace" )
language.Add( "gms_steelworkbench", "Steel Workbench" )
language.Add( "gms_platinumfurnace", "Platinum Furnace" )
language.Add( "gms_platinumworkbench", "Platinum Workbench" )
language.Add( "gms_factory", "Factory" )
language.Add( "gms_fridge", "Fridge" )
language.Add( "gms_pistolgunlab", "Pistol Gun Lab" )
language.Add( "gms_smggunlab", "SMG Gun Lab" )
language.Add( "gms_hightechgunlab", "High Tech Gun Lab" )
language.Add( "gms_transmutator", "Transmutator" )
language.Add( "gms_advancedtransmutator", "Advanced Transmutator" )
language.Add( "gms_gunchunks", "Gun Chunks" )
language.Add( "gms_resourcepack", "Resource Pack" )
language.Add( "gms_grindingstone", "Grinding Stone" )
language.Add( "gms_waterfountain", "Water Fountain" )
language.Add( "gms_stove", "Stove" )
language.Add( "gms_renbuyshop", "Ren Buy Shop" )
language.Add( "gms_rensellshop", "Ren Sell Shop" )
language.Add( "gms_obelisk", "Obelisk")
language.Add( "gms_mithrilfactory", "Mithril Factory")
language.Add( "gms_mithrilworkbench", "Mithril WorkBench" )
language.Add( "gms_runealtar", "Rune Altar" )
language.Add( "gms_runicinfuser", "Runic Infuser")

/* The chat hints */
HintsRus = {
	"Держите Ваши ресурсы в ресурс паке, чтобы их не украли ночью.",
	"А знаете ли Вы, что ресурсы в меню ресурсов ( F2 ) нажимаемы мышью?",
	"Храните Вашу еду в холодильнике, чтобы она не портилась.",
	"Чтобы племя могло использовать вещи друг друга, это племя должно иметь пароль.",
	"Чтобы использовать фонарь, Вам нужно его сделать.",
	"Чем больше у Вас батареек, тем больше у Вас энергии для фонаря.",
	"Шанс поймать что-то без наживки ( Baits ) в 4 раза ниже, чем с наживкой.",
	"Чтобы добыть железо ( Iron ) или медь ( Copper ) вам нужна кирка.",
	"Проблемы? Прочтите !help для получения базовой информации об этом игровом режиме.",
	"Чтобы пригласить игрока в племя, напишите !invite <имя игрока>"
}

HintsEng = {
	"Store your resources in resource pack, so they wont get stolen at night.",
	"Did you know that resources in Resources menu ( F2 ) are clickable?",
	"Keep your food in fridge, so it does not spoil.",
	"In order to share items within a tribe, the tribe must have a password.",
	"In order to use flashlight, you need to craft it.",
	"The more batteries you have, the more flashlight power you have.",
	"Chance to catch something without Baits is 4 times lower, then with Baits.",
	"In order to get Iron or Copper you need a pickaxe.",
	"Having trouble? Read !help to learn the basics of this gamemode.",
	"In order to invite a player into a tribe, type !invite <player name>"
}

timer.Create( "Client.HINTS", 360, 0, function()
	if ( GetConVarString( "gmod_language" ) == "ru" ) then
		chat.AddText( Color( 50, 255, 50 ), "[HINT] ", Color( 255, 255, 255 ), HintsRus[ math.random( 1, #HintsRus ) ] )
	else
		chat.AddText( Color( 50, 255, 50 ), "[HINT] ", Color( 255, 255, 255 ), HintsEng[ math.random( 1, #HintsEng ) ] )
	end
end )

function GM.FindTribeByID( Tid )
	for id, tabl in pairs( Tribes ) do
		if ( tabl.id == Tid ) then return tabl end
	end
	return false
end

concommand.Add( "gms_resetcharacter_verify", function( ply, cmd, args )
	Derma_StringRequest( "Character Reset", "WARNING! This will reset all your skills and resources back to where you started.\nIf you are sure you want to do this, type 'I agree' into box below:", "", function( text )
		RunConsoleCommand( "gms_resetcharacter", text )
	end )
end )

/* Resource pack GUI */

GM.ResourcePackFrame = nil

concommand.Add( "gms_openrespackmenu", function( ply, cmd, args )
	local resPack = ply:GetEyeTrace().Entity

	if ( !IsValid( resPack ) ) then return end

	local frame = vgui.Create( "DFrame" )
	frame:SetSize( ScrW() / 1.5, ScrH() / 2 )
	frame:MakePopup()
	frame:Center()
	function frame:Update()
		// Left side
		for id, item in pairs( self.Resources:GetItems() ) do item:Remove() end
		for res, num in SortedPairs( self.ResourcePack.Resources or {} ) do
			local reso = vgui.Create( "gms_resourceLine" )
			if ( self.ResourcePack:GetClass() == "gms_fridge" ) then
				reso:SetRes( res, num, false )
			else
				reso:SetRes( res, num, true )
			end
			self.Resources:AddItem( reso )
		end

		// Right side
		if ( self.ResourcePack:GetClass() == "gms_fridge" || !IsValid( self.Inventory ) ) then return end
		timer.Simple( 0, function()
			if ( !IsValid( self.Inventory ) ) then return end
			for id, item in pairs( self.Inventory:GetItems() ) do item:Remove() end
			for res, num in SortedPairs( Resources or {} ) do
				if ( num <= 0 ) then continue end
				local reso = vgui.Create( "gms_resourceLineStore" )
				reso:SetRes( res, num )
				self.Inventory:AddItem( reso )
			end
		end )
	end

	local panelList = vgui.Create( "DPanelList", frame )
	panelList:SetPos( 5, 30 )
	panelList:SetSpacing( 5 )
	panelList:SetPadding( 5 )
	panelList:EnableHorizontal( false )
	panelList:EnableVerticalScrollbar( true )
	function panelList:Paint( w, h )
		draw.RoundedBox( 2, 0, 0, w, h, Color( 80, 80, 80 ) )
	end

	if ( resPack:GetClass() == "gms_fridge" ) then
		frame:SetSize( ScrW() / 2, ScrH() / 2 )
		frame:SetTitle( "Fridge" )
		frame:Center()
		panelList:SetSize( frame:GetWide() - 10, frame:GetTall() - 35 )
	else
		frame:SetTitle( "Resource pack" )
		panelList:SetSize( frame:GetWide() - 15 - ScrW() / 4, frame:GetTall() - 35 )
	end

	frame.Resources = panelList
	frame.ResourcePack = resPack

	if ( resPack:GetClass() != "gms_fridge" ) then
		local panelListInv = vgui.Create( "DPanelList", frame )
		panelListInv:SetPos( frame:GetWide() - 10 - ScrW() / 4 + 5, 30 )
		panelListInv:SetSize( ScrW() / 4, frame:GetTall() - 35 )
		panelListInv:SetSpacing( 5 )
		panelListInv:SetPadding( 5 )
		panelListInv:EnableHorizontal( false )
		panelListInv:EnableVerticalScrollbar( true )
		function panelListInv:Paint( w, h )
			draw.RoundedBox( 2, 0, 0, w, h, Color( 80, 128, 80 ) )
		end
		frame.Inventory = panelListInv
	end

	GAMEMODE.ResourcePackFrame = frame
	frame:Update()
end )

hook.Add( "Think", "CampFireLight", function()
	for id, e in pairs( ents.FindByClass("prop_p*") ) do
		if ( !e:IsOnFire() ) then continue end
		local campfire = DynamicLight( e:EntIndex() )
		if ( campfire ) then
			campfire.Pos = e:GetPos()
			campfire.r = math.random( 224, 255 )
			campfire.g = math.random( 128, 150 )
			campfire.b = 0
			campfire.Brightness = 2.4

			if ( !e.campfireSize ) then
				local min, max = e:OBBMins(), e:OBBMaxs()
				local vol = math.abs( max.x - min.x ) * math.abs( max.y - min.y ) * math.abs( max.z - min.z )
				e.campfireSize = vol / 5
			end

			campfire.Size = e.campfireSize
			campfire.Decay = 0
			campfire.DieTime = CurTime() + 0.25
		end
	end
end )

/* ----------------------------------------------------------------------------------------------------
	Hooks
---------------------------------------------------------------------------------------------------- */

function GM:Initialize()
	if ( !IsValid( self.SkillsHud ) ) then self.SkillsHud = vgui.Create( "gms_SkillsHud" ) end
	if ( !IsValid( self.ResourcesHud ) ) then self.ResourcesHud = vgui.Create( "gms_ResourcesHud" ) end
	if ( !IsValid( self.CommandsHud ) ) then self.CommandsHud = vgui.Create( "gms_CommandsHud" ) end
	if ( !IsValid( self.LoadingBar ) ) then self.LoadingBar = vgui.Create( "gms_LoadingBar" ) self.LoadingBar:SetVisible( false ) end
	if ( !IsValid( self.SavingBar ) ) then self.SavingBar = vgui.Create( "gms_SavingBar" ) self.SavingBar:SetVisible( false ) end
end

/* ----------------------------------------------------------------------------------------------------
	Skills, Resources & Experience
---------------------------------------------------------------------------------------------------- */

usermessage.Hook( "gms_MakeProcessBar", function( um )
	CurrentProcess = um:ReadString()
	ProcessStart = CurTime()
	ProcessCompleteTime = um:ReadShort()
	ProcessCancelAble = um:ReadBool()
end )

usermessage.Hook( "gms_ResetPlayer", function()
	Tribes = {}
	Skills = {}
	Skills[ "Survival" ] = 0
	Resources = {}
	Experience = {}
	Experience[ "Survival" ] = 0
	FeatureUnlocks = {}
	MaxResources = 25

	GAMEMODE.ResourcesHud:RefreshResources()
	GAMEMODE.SkillsHud:RefreshSkills()
end )

usermessage.Hook( "gms_StopProcessBar", function()
	ProcessCompleteTime = false
end )

usermessage.Hook( "gms_MakeLoadingBar", function( um )
	GAMEMODE.LoadingBar:Show( um:ReadString() )
end )

usermessage.Hook( "gms_StopLoadingBar", function( um )
	GAMEMODE.LoadingBar:Hide()
end )

usermessage.Hook( "gms_MakeSavingBar", function( um )
	GAMEMODE.SavingBar:Show( um:ReadString() )
end )

usermessage.Hook( "gms_StopSavingBar", function( um )
	GAMEMODE.SavingBar:Hide()
end )

usermessage.Hook( "gms_SetSkill", function( um )
	Skills[ um:ReadString() ] = um:ReadShort()
	MaxResources = 25 + ( GetSkill( "Survival" ) * 5 )
	GAMEMODE.SkillsHud:RefreshSkills()
end )

usermessage.Hook( "gms_SetXP", function( um )
	Experience[ um:ReadString() ] = um:ReadShort()
end )

usermessage.Hook( "gms_SetResource", function( um )
	local res = um:ReadString()
	local amount = um:ReadShort()

	Resources[res] = amount
	GAMEMODE.ResourcesHud:RefreshResources()
end )

usermessage.Hook( "gms_SetMaxResources", function( um )
	MaxResources = um:ReadShort()
	GAMEMODE.ResourcesHud:RefreshResources()
end )

usermessage.Hook( "gms_OpenCombiMenu", function( um )

	if ( GAMEMODE.CombiMenu ) then GAMEMODE.CombiMenu:Remove() end
	GAMEMODE.CombiMenu = vgui.Create( "GMS_CombinationWindow" )
	GAMEMODE.CombiMenu:SetTable( um:ReadString() )
end )

function GM:PlayerBindPress( ply, bind, pressed )
	if ( string.find( bind, "gm_showhelp" ) ) then GAMEMODE.SkillsHud:ToggleExtend() end
	if ( string.find( bind, "gm_showteam" ) ) then GAMEMODE.ResourcesHud:ToggleExtend() end
end

/* ----------------------------------------------------------------------------------------------------
	Functions
---------------------------------------------------------------------------------------------------- */

function GetSkill( skill )
	return Skills[ skill ] or 0
end

function GetXP( skill )
	return Experience[ skill ] or 0
end

function GetResource( res )
	return Resources[ res ] or 0
end

function TraceFromEyes( dist )
	local trace = {}
	trace.start = self:GetShootPos()
	trace.endpos = trace.start + ( self:GetAimVector() * dist )
	trace.filter = self

	return util.TraceLine( trace )
end

/* ----------------------------------------------------------------------------------------------------
	Messages
---------------------------------------------------------------------------------------------------- */

GM.InfoMessages = {}
GM.InfoMessageLine = 0

usermessage.Hook( "gms_sendmessage", function( um )
	local text = um:ReadString()
	local dur = um:ReadShort()
	local col = um:ReadString()
	local str = string.Explode( ",", col )
	local col = Color( tonumber( str[1] ), tonumber( str[2] ), tonumber( str[3] ), tonumber( str[4] ) )

	for k,v in pairs( GAMEMODE.InfoMessages ) do
		v.drawline = v.drawline + 1
	end

	local message = {}
	message.Text = text
	message.Col = col
	message.Tab = 5
	message.drawline = 1

	GAMEMODE.InfoMessages[#GAMEMODE.InfoMessages + 1] = message
	GAMEMODE.InfoMessageLine = GAMEMODE.InfoMessageLine + 1

	timer.Simple( dur, function() GAMEMODE.DropMessage( message ) end )
end )

hook.Add( "HUDPaint", "gms_drawmessages", function()
	for k,msg in pairs( GAMEMODE.InfoMessages ) do
		local txt = msg.Text
		local line = ScrH() / 2 + ( msg.drawline * 20 )
		local tab = msg.Tab
		local col = msg.Col
		draw.SimpleTextOutlined( txt, "ScoreboardText", tab, line, col, 0, 0, 0.5, Color( 100, 100, 100, 150 ) )

		if ( msg.Fading ) then
			msg.Tab = msg.Tab - ( msg.InitTab - msg.Tab - 0.05 )

			if ( msg.Tab > ScrW() + 10 ) then
				GAMEMODE.RemoveMessage( msg )
			end
		end
	end
end )

function GM.DropMessage( msg )
	msg.InitTab = msg.Tab
	msg.Fading = true
end

function GM.RemoveMessage( msg )
	for k, v in pairs( GAMEMODE.InfoMessages ) do
		if ( v == msg ) then
			GAMEMODE.InfoMessages[k] = nil
			GAMEMODE.InfoMessageLine = GAMEMODE.InfoMessageLine - 1
			table.remove( GAMEMODE.InfoMessages, k )
		end
	end
end

/* ----------------------------------------------------------------------------------------------------
	Prop Fading
---------------------------------------------------------------------------------------------------- */

GM.FadingProps = {}

usermessage.Hook( "gms_CreateFadingProp", function( um )
	local mdl = um:ReadString()
	local pos = um:ReadVector()
	local dir = um:ReadVector()
	local col = um:ReadVector()
	local speed = um:ReadShort()

	if ( !mdl or !pos or !dir or !speed ) then return end

	local ent = ents.CreateClientProp( mdl )
	ent:SetPos( pos )
	ent:SetColor( Color( col.x, col.y, col.z) )
	ent:SetAngles( Angle( dir.x, dir.y, dir.z ) )
	ent:Spawn()

	ent.Alpha = 255
	ent.Speed = speed

	table.insert( GAMEMODE.FadingProps, ent )
end )

hook.Add( "Think", "gms_FadeFadingPropsHook", function()
	for k, v in pairs( GAMEMODE.FadingProps ) do
		if ( v.Alpha ) then
			if ( v.Alpha <= 0 ) then
				v:Remove()
				table.remove( GAMEMODE.FadingProps, k )
			else
				v.Alpha = v.Alpha - v.Speed

				v:SetRenderMode( RENDERMODE_TRANSALPHA )
				local oldColor = v:GetColor()
				v:SetColor( Color( oldColor.r, oldColor.g, oldColor.b, math.min( math.max( v.Alpha, 0 ), 255 ) ) )
			end
		end
	end
end )

/* ----------------------------------------------------------------------------------------------------
	Achievement Messages
---------------------------------------------------------------------------------------------------- */

GM.AchievementMessages = {}

usermessage.Hook( "gms_sendachievement", function( um )
	local tbl = {}
	tbl.Text = um:ReadString()
	tbl.Alpha = 255

	table.insert( GAMEMODE.AchievementMessages, tbl )
end )

hook.Add( "HUDPaint", "gms_drawachievementmessages", function()
	for k, msg in pairs( GAMEMODE.AchievementMessages ) do
		msg.Alpha = msg.Alpha - 1
		draw.SimpleTextOutlined( msg.Text, "ScoreboardHead", ScrW() / 2, ScrH() / 2, Color( 255, 255, 255, msg.Alpha ), 1, 1, 0.5, Color( 100, 100, 100, msg.Alpha ) )

		if ( msg.Alpha <= 0 ) then
			table.remove( GAMEMODE.AchievementMessages, k )
		end
	end
end )

/* ----------------------------------------------------------------------------------------------------
	Needs
---------------------------------------------------------------------------------------------------- */

usermessage.Hook( "gms_setneeds", function( um )
	Sleepiness = um:ReadShort()
	Hunger = um:ReadShort()
	Thirst = um:ReadShort()
	Oxygen = um:ReadShort()
	Power = um:ReadShort()
	Time = um:ReadShort()
end )

/* ----------------------------------------------------------------------------------------------------
	Help menu
---------------------------------------------------------------------------------------------------- */

concommand.Add( "gms_help", function()
	if ( !LocalPlayer():GetNWBool( "AFK" ) ) then RunConsoleCommand( "gms_afk" ) end

	local HelpMenu = vgui.Create( "DFrame" )
	HelpMenu:MakePopup()
	HelpMenu:SetSize( ScrW() - 100, ScrH() - 100 )
	HelpMenu:Center()
	HelpMenu:SetTitle( "Garry's Mod Stranded Help" )
	function HelpMenu:OnClose()
		if ( LocalPlayer():GetNWBool( "AFK" ) ) then RunConsoleCommand( "gms_afk" ) end
	end

	HelpMenu.HTML = vgui.Create( "HTML", HelpMenu )
	HelpMenu.HTML:SetSize( HelpMenu:GetWide() - 10, HelpMenu:GetTall() - 30 )
	HelpMenu.HTML:SetPos( 5, 25 )
	HelpMenu.HTML:OpenURL( "http://steamcommunity.com/sharedfiles/filedetails/?id=135129872" )
	//HelpMenu.HTML:SetHTML( file.Read( "help/helpnew.htm", "GAME" ) )
end )

/* ----------------------------------------------------------------------------------------------------
	Sleep
---------------------------------------------------------------------------------------------------- */

local SleepFade = 0
hook.Add( "HUDPaint", "gms_sleepoverlay", function()
	if ( LocalPlayer():GetNWBool( "Sleeping" ) ) then
		SleepFade = math.min( SleepFade + 3, 254 )
	else
		SleepFade = math.max( SleepFade - 6, 0 )
	end

	if ( SleepFade == 0 ) then return end

	surface.SetDrawColor( 0, 0, 0, SleepFade )
	surface.DrawRect( 0, 0, ScrW(), ScrH() )

	draw.SimpleText( "Use the command \"!wakeup\" or press F4 to wake up.", "ScoreboardSub", ScrW() / 2, ScrH() / 1.5, Color( 255, 255, 255, SleepFade ), 1, 1 )
end )

/* ----------------------------------------------------------------------------------------------------
	AFK
---------------------------------------------------------------------------------------------------- */

local AFKFade = 0
hook.Add( "HUDPaint", "gms_afkoverlay", function()
	if ( LocalPlayer():GetNWBool( "AFK" ) ) then
		AFKFade = math.min( AFKFade + 3, 254 )
	else
		AFKFade = math.max( AFKFade - 6, 0 )
	end

	if ( AFKFade == 0 ) then return end

	surface.SetDrawColor( 0, 0, 0, AFKFade )
	surface.DrawRect( 0, 0, ScrW(), ScrH() )

	draw.SimpleText( "Use the command \"!afk\" or press F4 to stop being afk.", "ScoreboardSub", ScrW() / 2, ScrH() / 1.5, Color( 255, 255, 255, AFKFade ), 1, 1 )
end )

/* ----------------------------------------------------------------------------------------------------
	Unlocks
---------------------------------------------------------------------------------------------------- */

usermessage.Hook( "gms_AddUnlock", function( um )
	local UnlockWindow = vgui.Create( "GMS_UnlockWindow" )
	UnlockWindow:SetMouseInputEnabled( true )
	UnlockWindow:SetUnlock( um:ReadString() )
end )

/* ----------------------------------------------------------------------------------------------------
	Tribes
---------------------------------------------------------------------------------------------------- */

concommand.Add( "gms_tribemenu", function()
	if ( !GAMEMODE.TribeMenu ) then
		GAMEMODE.TribeMenu = vgui.Create( "GMS_TribeMenu" )
		GAMEMODE.TribeMenu:SetDeleteOnClose( false )
		GAMEMODE.TribeMenu:SetVisible( false )
	end

	GAMEMODE.TribeMenu:SetVisible( !GAMEMODE.TribeMenu:IsVisible() )
end )

concommand.Add( "gms_tribes", function()
	if ( #Tribes <= 0 ) then chat.AddText( Color( 255, 255, 255 ), "No tribes created so far. Why not create one?" ) return end
	local TribesMenu = vgui.Create( "GMS_TribesList" )
end )

usermessage.Hook( "gms_invite", function( data )
	local tn = data:ReadString()
	local p = data:ReadString()
	Derma_Query( "You are being invited to " .. tn .. ".\nChoose action below.", "Invitation",
		"Join", function() RunConsoleCommand( "gms_join", tn, p ) end,
		"Decline", function() RunConsoleCommand( "say", "I don't want to join " .. tn .. "." ) end
	)
end )

usermessage.Hook( "sendTribe", function( data )

	local id = data:ReadShort()
	local name = data:ReadString()
	local color = data:ReadVector()
	local hazpass = data:ReadBool()

	team.SetUp( id, name, Color( color.r, color.g, color.b ) )

	table.insert( Tribes, { name = name, pass = hazpass, id = id, color = Color( color.r, color.g, color.b ) } )

end )