summaryrefslogtreecommitdiff
path: root/gamemode/chatcommands.lua
blob: 54d4bba49ae172df8f610fb8a834ddb5e7199147 (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
function GM:PlayerSay( ply, text, teamonly )
	local args = string.Explode( " ", text )
	if ( args == nil ) then args = {} end

	if ( teamonly ) then
		if ( GMS.RunChatCmd( ply, args ) != "" ) then
			for k, v in pairs( player.GetAll() ) do
				if ( IsValid( v ) && v:IsPlayer() && v:Team() == ply:Team() ) then
					v:PrintMessage( 3, "[TRIBE] " .. ply:Nick() .. ": " .. text )
				end
			end
		end
		return ""
	else
		return GMS.RunChatCmd( ply, args ) or text
	end
end

GMS.ChatCommands = {}
function GMS.RegisterChatCmd( tbl )
	GMS.ChatCommands[ tbl.Command ] = tbl
end

function GMS.RunChatCmd( ply, arg )
	if ( #arg > 0 && ( string.Left( arg[ 1 ], 1 ) == "/" or string.Left( arg[1], 1 ) == "!" ) ) then
		local cmd = string.sub( arg[ 1 ], 2, string.len( arg[ 1 ] ) )
		table.remove( arg, 1 )

		if ( ply:GetNWBool( "AFK" ) && cmd != "afk" ) then
			ply:SendMessage( "You can't do this while afk.", 3, Color( 200, 0, 0, 255 ) )
		elseif ( ply:GetNWBool( "Sleeping" ) && cmd != "wakeup" ) then
			ply:SendMessage( "You can't do this while sleeping.", 3, Color( 200, 0, 0, 255 ) )
		end

		if ( GMS.ChatCommands[ cmd ] != nil ) then
			GMS.ChatCommands[cmd]:Run( ply, arg )
			return ""
		end
	end
end

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "commands"
CHATCMD.Desc = "Prints all possible commands"

function CHATCMD:Run( ply )
	ply:PrintMessage( HUD_PRINTCONSOLE, "\n\n\nGarry's Mod Stranded chat commands:\n\n" )
	for _, v in pairs( GMS.ChatCommands ) do
		if ( v.Command != nil ) then
			local desc = v.Desc or "No description given."
			local syntax = v.Syntax or ""
			if ( syntax != "" ) then syntax = syntax .. " " end
			ply:PrintMessage( HUD_PRINTCONSOLE, v.Command .. " " .. syntax .. "- " .. v.Desc )
		end
	end
	ply:PrintMessage( HUD_PRINTCONSOLE, "\n<arg> - Required argument, [arg] - Optional argument\n" )
	ply:PrintMessage( HUD_PRINTCONSOLE, "All commands start with '!' or '/'." )
	ply:PrintMessage( HUD_PRINTCONSOLE, "For item names with spaces use '_', for example !drop Water_Bottles 5\n\n" )
	ply:PrintMessage( HUD_PRINTTALK, "All commands were printed into console (~)" )
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "help"
CHATCMD.Desc = "Open help menu"
CHATCMD.CCName = "gms_help"

function CHATCMD:Run( ply, args )
	ply:ConCommand( self.CCName )
end 

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "drop"
CHATCMD.Desc = "No amount will drop all"
CHATCMD.Syntax = "<Resource Type> [Amount]"
CHATCMD.CCName = "gms_dropresources"

function CHATCMD:Run( ply, args )
	GAMEMODE.DropResource( ply, self.CCName, args )
end 

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "sleep"
CHATCMD.Desc = "Goto sleep"
CHATCMD.CCName = "gms_sleep"

function CHATCMD:Run( ply )
	ply:Sleep()
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "stuck"
CHATCMD.Desc = "In case you are stuck"
CHATCMD.CCName = "gms_stuck"

function CHATCMD:Run( ply )
	GAMEMODE.PlayerStuck( ply )
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "adrop"
CHATCMD.Desc = "Drops a specified of resources out of nowhere. Admin only."
CHATCMD.Syntax = "<Resource Type> <Amount>"
CHATCMD.CCName = "gms_adropresources"

function CHATCMD:Run( ply, args )
	GAMEMODE.ADropResource( ply, self.CCName, args )
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "wakeup"
CHATCMD.Desc = "Wakeup from sleep."
CHATCMD.CCName = "gms_wakeup"

function CHATCMD:Run( ply )
	ply:Wakeup()
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}
CHATCMD.Command = "campfire"
CHATCMD.Desc = "Make a camp fire."
CHATCMD.CCName = "gms_makefire"

function CHATCMD:Run( ply )
	GAMEMODE.MakeCampfire( ply )
end
GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "drink"
CHATCMD.Desc = "Drink a water bottle."
CHATCMD.CCName = "gms_drinkbottle"

function CHATCMD:Run( ply )
	GAMEMODE.DrinkFromBottle( ply )
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "melon"
CHATCMD.Desc = "Plant a watermelon."
CHATCMD.CCName = "gms_plantmelon"

function CHATCMD:Run( ply )
	GAMEMODE.PlantMelon( ply )
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "banana"
CHATCMD.Desc = "Plant a banana."
CHATCMD.CCName = "gms_plantbanana"

function CHATCMD:Run( ply )
	GAMEMODE.PlantBanana( ply )
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "orange"
CHATCMD.Desc = "Plant an orange."
CHATCMD.CCName = "gms_plantorange"

function CHATCMD:Run( ply )
	GAMEMODE.PlantOrange( ply )
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "grain"
CHATCMD.Desc = "Plant grain."
CHATCMD.CCName = "gms_plantgrain"

function CHATCMD:Run( ply )
	GAMEMODE.PlantGrain( ply )
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "berrybush"
CHATCMD.Desc = "Plant berry bush."
CHATCMD.CCName = "gms_plantbush"

function CHATCMD:Run( ply )
	GAMEMODE.PlantBush( ply )
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "tree"
CHATCMD.Desc = "Plant a tree."
CHATCMD.CCName = "gms_planttree"

function CHATCMD:Run( ply )
	GAMEMODE.PlantTree( ply )
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "dropweapon"
CHATCMD.Desc = "Drop your current weapon."
CHATCMD.CCName = "gms_dropweapon"

function CHATCMD:Run( ply )
	GAMEMODE.DropWeapon( ply )
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "take"
CHATCMD.Desc = "Take resources out of Resource Pack/Box."
CHATCMD.Syntax = "[Resource Type] [Amount]"
CHATCMD.CCName = "gms_takeresources"
function CHATCMD:Run( ply, args )
	GAMEMODE.TakeResource( ply, self.CCName, args )
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "medicine"
CHATCMD.Desc = "Take a Medicine."
CHATCMD.CCName = "gms_takemedicine"

function CHATCMD:Run( ply )
	GAMEMODE.TakeAMedicine( ply )
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "afk"
CHATCMD.Desc = "Go away from keyboard. ( Doesn't reduce your needs )"
CHATCMD.CCName = "gms_afk"

function CHATCMD:Run( ply, args )
	GAMEMODE.AFK( ply, self.CCName, args )
	ply:ConCommand("-menu")
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "rn"
CHATCMD.Syntax = "[Player]"
CHATCMD.Desc = "Reset your / someone's needs. Admin Only."

function CHATCMD:Run( ply, args )
	if ( !ply:IsAdmin() ) then return end
	if ( args && #args > 0 ) then
		pl = player.FindByName( args[ 1 ] )
		if ( !pl ) then ply:SendMessage( "Player not found!", 3, Color( 200, 10, 10, 255 ) ) return end
		pl.Hunger = 1000
		pl.Thirst = 1000
		pl.Sleepiness = 1000
		pl:UpdateNeeds()
	else
		ply.Hunger = 1000
		ply.Thirst = 1000
		ply.Sleepiness = 1000
		ply:UpdateNeeds()
	end
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "finish"
CHATCMD.Desc = "Finish the structure you are looking at."

function CHATCMD:Run( ply, args )
	if ( !ply:IsAdmin() || ply:GetEyeTrace().Entity:GetClass() != "gms_buildsite" ) then return end
	ply:GetEyeTrace().Entity:Finish()
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "r"
CHATCMD.Desc = "Give resources to yourself / someone"
CHATCMD.Syntax = "[player] <Resource> <Amount>"

function CHATCMD:Run(ply, arg)
	if ( !ply:IsAdmin() || !arg ) then return end
	if ( #arg > 2 ) then
		local pl = player.FindByName( arg[ 1 ] )
		if ( !pl ) then ply:SendMessage( "Player not found!", 3, Color( 200, 10, 10, 255 ) ) return end
		pl:IncResource( arg[ 2 ], tonumber( arg[ 3 ] ) )
	elseif ( #arg == 2 ) then
		ply:IncResource( arg[ 1 ], tonumber( arg[ 2 ] ) )
	end
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "steal"
CHATCMD.Desc = "Steal a prop."
CHATCMD.CCName = "gms_steal"

function CHATCMD:Run( ply )
	ply.ConCommand( ply, "gms_steal" )
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "createtribe"
CHATCMD.Desc = "Opens create tribe menu."
CHATCMD.CCName = "gms_tribemenu"

function CHATCMD:Run( ply, args )
	ply:ConCommand( self.CCName )
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "invite"
CHATCMD.Desc = "Invite someone to your tribe"
CHATCMD.Syntax = "<player>"

function CHATCMD:Run( ply, args )
	local him = player.FindByName( args[ 1 ] )
	if ( !him ) then ply:SendMessage( "Player not found!", 3, Color( 200, 10, 10, 255 ) ) return end
	if ( him == ply ) then ply:SendMessage( "Why invite yourself?", 3, Color( 200, 64, 10, 255 ) ) return end
	if ( him.LastInvite && him.LastInvite > CurTime() ) then ply:SendMessage( "Too much invitations to " .. him:Name() .. "! Wait " .. ( CurTime() - him.LastInvite)  .. " seconds.", 3, Color( 200, 10, 10, 255 ) ) return end
	local mahTribe = GAMEMODE.FindTribeByID( ply:Team() )

	him.LastInvite = CurTime() + 30

	if ( !mahTribe ) then ply:SendMessage( "Something went wrong! Report this to admins: " .. ply:Team(), 3, Color( 200, 10, 10, 255 ) ) return end

	ply:SendMessage( "Invitation sent!", 3, Color( 200, 200, 200, 255 ) ) 

	umsg.Start( "gms_invite", him )
		umsg.String( mahTribe.name )
		umsg.String( tostring( mahTribe.password ) )
	umsg.End()
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "join"
CHATCMD.Desc = "Opens join tribe menu."
CHATCMD.CCName = "gms_tribes"

function CHATCMD:Run( ply, args )
	ply:ConCommand( self.CCName )
end

GMS.RegisterChatCmd( CHATCMD )

----------------------------------------------------------------------------------------------------

local CHATCMD = {}

CHATCMD.Command = "leave"
CHATCMD.Desc = "Leave a tribe."
CHATCMD.CCName = "gms_leave"

function CHATCMD:Run( ply, args )
	GAMEMODE.LeaveTribeCmd( ply, self.CCName, args )
end

GMS.RegisterChatCmd( CHATCMD )