summaryrefslogtreecommitdiff
path: root/gamemode/server/admin_commands.lua
blob: 284792c86637615fddf5027a2146333e30e18d24 (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
concommand.Add( "gms_admin_maketree", function( ply )
	if ( IsValid( ply ) && !ply:IsAdmin() ) then ply:SendMessage( "You need admin rights for this!", 3, Color( 200, 0, 0, 255 ) ) return end
	local tr = ply:TraceFromEyes( 10000 )
	GAMEMODE.MakeTree( tr.HitPos )
end )

concommand.Add( "gms_admin_makerock", function( ply )
	if ( IsValid( ply ) && !ply:IsAdmin() ) then ply:SendMessage( "You need admin rights for this!", 3, Color( 200, 0, 0, 255 ) ) return end
	local tr = ply:TraceFromEyes( 10000 )
	GAMEMODE.MakeGenericPlant( ply, tr.HitPos, GMS.RockModels[ math.random( 1, #GMS.RockModels ) ], true )
end )

concommand.Add( "gms_admin_makefood", function( ply )
	if ( IsValid( ply ) && !ply:IsAdmin() ) then ply:SendMessage( "You need admin rights for this!", 3, Color( 200, 0, 0, 255 ) ) return end
	local tr = ply:TraceFromEyes( 10000 )
	local ent = ents.Create( "prop_physics" )
	ent:SetAngles( Angle( 0, math.random( 1, 360 ), 0 ) )
	ent:SetModel( GMS.EdibleModels[math.random( 1, #GMS.EdibleModels )] )
	ent:SetPos( tr.HitPos + Vector( 0, 0, 10 ) )
	ent:Spawn()
	SPropProtection.PlayerMakePropOwner( ply, ent )
end )

concommand.Add( "gms_admin_makeantlionbarrow", function( ply, cmd, args )
	if ( IsValid( ply ) && !ply:IsAdmin() ) then ply:SendMessage( "You need admin rights for this!", 3, Color( 200, 0, 0, 255 ) ) return end
	if ( !args[1] ) then ply:SendMessage( "Specify max antlions!", 3, Color( 200, 0, 0, 255 ) ) return end
	local tr = ply:TraceFromEyes( 10000 )
	local ent = ents.Create( "gms_antlionbarrow" )
	ent:SetPos( tr.HitPos )
	ent:Spawn()
	ent:SetNetworkedString( "Owner", "World" )
	ent:SetKeyValue( "MaxAntlions", args[1] )
end )

concommand.Add( "gms_admin_makeplant", function( ply, cmd, args )
	if ( IsValid( ply ) && !ply:IsAdmin() ) then ply:SendMessage( "You need admin rights for this!", 3, Color( 200, 0, 0, 255 ) ) return end

	local tr = ply:TraceFromEyes( 10000 )
	local typ = tonumber( args[ 1 ] ) or math.random( 1, 5 )
	local pos = tr.HitPos

	if ( typ == 1 ) then
		GAMEMODE.MakeMelon( pos, math.random( 1, 3 ), ply )
	elseif ( typ == 2 ) then
		GAMEMODE.MakeBanana( pos, math.random( 1, 3 ), ply )
	elseif ( typ == 3 ) then
		GAMEMODE.MakeOrange( pos, math.random( 1, 3 ), ply )
	elseif ( typ == 4 ) then
		GAMEMODE.MakeBush( pos, ply )
	elseif ( typ == 5 ) then
		GAMEMODE.MakeGrain( pos, ply )
	end
end )

concommand.Add( "gms_admin_populatearea", function( ply, cmd, args )
	if ( IsValid( ply ) && !ply:IsAdmin() ) then ply:SendMessage( "You need admin rights for this!", 3, Color( 200, 0, 0, 255 ) ) return end
	if ( !args[1] or !args[2] or !args[3] ) then ply:SendMessage( "You need to specify <type> <amount> <radius>", 3, Color( 200, 0, 0, 255 ) ) return end

	for k, v in pairs( player.GetAll() ) do
		v:SendMessage( "Populating area...", 3, Color( 255, 255, 255, 255 ) )
	end

	--Population time
	local Amount = tonumber( args[2] ) or 10
	local info = {}
	info.Amount = Amount

	if ( Amount > 200 ) then
		ply:SendMessage( "Auto-capped at 200 props.", 3, Color( 200, 0, 0, 255 ) )
		info.Amount = 200
	end

	local Type = args[1]
	local Amount = info.Amount
	local Radius = tonumber( args[3] ) or 1000

	--Find playertrace
	local plytrace = ply:TraceFromEyes( 10000 )

	for i = 1, Amount do
		info.pos = plytrace.HitPos + Vector( math.random( -Radius, Radius ), math.random( -Radius, Radius ), 1000 )
		info.Retries = 50

		--Find pos in world
		while ( util.IsInWorld( info.pos ) == false and info.Retries > 0 ) do
			info.pos = plytrace.HitPos + Vector( math.random( -Radius, Radius ), math.random( -Radius, Radius ), 1000 )
			info.Retries = info.Retries - 1
		end

		--Find ground
		local trace = {}
		trace.start = info.pos
		trace.endpos = trace.start + Vector( 0, 0, -100000 )
		trace.mask = MASK_SOLID_BRUSHONLY

		local groundtrace = util.TraceLine( trace )

		--Assure space
		local nearby = ents.FindInSphere( groundtrace.HitPos, 200 )
		info.HasSpace = true

		for k, v in pairs( nearby ) do
			if ( v:IsProp() ) then
				info.HasSpace = false
			end
		end

		--Find sky
		local trace = {}
		trace.start = groundtrace.HitPos
		trace.endpos = trace.start + Vector( 0, 0, 100000 )

		local skytrace = util.TraceLine( trace )

		--Find water?
		local trace = {}
		trace.start = groundtrace.HitPos
		trace.endpos = trace.start + Vector( 0, 0, 1 )
		trace.mask = MASK_WATER

		local watertrace = util.TraceLine( trace )

		--All a go, make entity
		if ( Type == "Trees" ) then
			if ( info.HasSpace and skytrace.HitSky and !watertrace.Hit and ( groundtrace.MatType == MAT_DIRT or groundtrace.MatType == MAT_GRASS or groundtrace.MatType == MAT_SAND ) ) then
				GAMEMODE.MakeTree( groundtrace.HitPos )
			end
		elseif ( Type == "Rocks" ) then
			if ( !watertrace.Hit and ( groundtrace.MatType == MAT_DIRT or groundtrace.MatType == MAT_GRASS or groundtrace.MatType == MAT_SAND ) ) then
				local ent = ents.Create( "prop_physics" )
				ent:SetAngles( Angle( 0, math.random( 1, 360 ), 0 ) )
				ent:SetModel( GMS.RockModels[math.random( 1, #GMS.RockModels )] )
				ent:SetPos( groundtrace.HitPos )
				ent:Spawn()
				ent:SetNetworkedString( "Owner", "World" )
				ent:Fadein()
				ent.PhysgunDisabled = true
				ent:GetPhysicsObject():EnableMotion( false )
			end
		elseif ( Type == "Random_Plant" and info.HasSpace ) then
			if ( !watertrace.Hit and ( groundtrace.MatType == MAT_DIRT or groundtrace.MatType == MAT_GRASS or groundtrace.MatType == MAT_SAND ) ) then
				local typ = math.random( 1, 5 )
				local pos = groundtrace.HitPos

				if ( typ == 1 ) then
					GAMEMODE.MakeMelon( pos,math.random( 1, 2 ), ply )
				elseif ( typ == 2 ) then
					GAMEMODE.MakeBanana( pos,math.random( 1, 2 ), ply )
				elseif ( typ == 3 ) then
					GAMEMODE.MakeOrange( pos,math.random( 1, 2 ), ply )
				elseif ( typ == 4 ) then
					GAMEMODE.MakeBush( pos, ply )
				elseif ( typ == 5 ) then
					GAMEMODE.MakeGrain( pos, ply )
				end
			end
		end
	end

	--Finished
	for k, v in pairs( player.GetAll() ) do
		v:SendMessage( "Done!", 3, Color( 255, 255, 255, 255 ) )
	end
end )

concommand.Add( "gms_admin_clearmap", function( ply )
	if ( IsValid( ply ) && !ply:IsAdmin() ) then ply:SendMessage( "You need admin rights for this!", 3, Color( 200, 0, 0, 255 ) ) return end

	for k, v in pairs( ents.GetAll() ) do
		if ( v:IsRockModel() or v:IsTreeModel() ) then
			for k, tbl in pairs( GAMEMODE.RisingProps ) do
				if ( tbl.Entity == v ) then
					table.remove( GAMEMODE.RisingProps, k )
				end
			end
			for k, tbl in pairs( GAMEMODE.SinkingProps ) do
				if ( tbl.Entity == v ) then
					table.remove( GAMEMODE.SinkingProps, k )
				end
			end
			for k, ent in pairs( GAMEMODE.FadingInProps ) do
				if ( ent == v ) then
					table.remove( GAMEMODE.FadingInProps, k )
				end
			end
			v:Fadeout()
		end
	end

	for k, v in pairs( player.GetAll() ) do v:SendMessage( "Cleared map.", 3, Color( 255, 255, 255, 255 ) ) end
end )

concommand.Add( "gms_admin_saveallcharacters", function( ply )
	if ( IsValid( ply ) && !ply:IsAdmin() ) then ply:SendMessage( "You need admin rights for this!", 3, Color( 200, 0, 0, 255 ) ) return end

	for k, v in pairs( player.GetAll() ) do
		v:SaveCharacter()
	end

	ply:SendMessage( "Saved characters on all current players.", 3, Color( 255, 255, 255, 255 ) )
end )

function GM.ADropResource( ply, cmd, args )
	if ( IsValid( ply ) && !ply:IsAdmin() ) then ply:SendMessage( "You need admin rights for this!", 3, Color( 200, 0, 0, 255 ) ) return end
	if ( args == nil or args[1] == nil ) then ply:SendMessage( "You need to at least give a resource type!", 3, Color( 200, 0, 0, 255 ) ) return end

	args[1] = string.Capitalize( args[1] )
	if ( args[2] == nil or string.lower( args[2] ) == "all" ) then args[2] = tostring( ply:GetResource( args[1] ) ) end
	if ( tonumber( args[2] ) <= 0 ) then ply:SendMessage( "No zeros/negatives!", 3, Color( 200, 0, 0, 255 ) ) return end

	local int = tonumber( args[2] )
	local Type = args[1]

	ply:DropResource( Type, int )
	ply:SendMessage( "Dropped " .. string.Replace( Type, "_", " " ) .. " ( " .. int .. "x )", 3, Color( 10, 200, 10, 255 ) )
end
concommand.Add( "gms_ADropResources", GM.ADropResource )