From 31a40cca9772b62baea8bb3a2a3a872e128ec9d9 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 16 Apr 2016 12:37:24 -0400 Subject: Moved admin commands from init.lua to admin_commands.lua --- gamemode/server/admin_commands.lua | 217 +++++++++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 gamemode/server/admin_commands.lua (limited to 'gamemode/server') diff --git a/gamemode/server/admin_commands.lua b/gamemode/server/admin_commands.lua new file mode 100644 index 0000000..284792c --- /dev/null +++ b/gamemode/server/admin_commands.lua @@ -0,0 +1,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 ", 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 ) -- cgit v1.2.3-70-g09d2