summaryrefslogtreecommitdiff
path: root/gamemode/init.lua
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2016-04-16 12:22:52 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2016-04-16 12:22:52 -0400
commit95bf646ef4610252f0899948d5999bc4988732b3 (patch)
tree3ea1a0fe4f2c618f85cf2dc8818295273b399c35 /gamemode/init.lua
parentb24ba036889a644bb9505f61e3feeda370299c98 (diff)
downloadgmstranded-95bf646ef4610252f0899948d5999bc4988732b3.tar.gz
gmstranded-95bf646ef4610252f0899948d5999bc4988732b3.tar.bz2
gmstranded-95bf646ef4610252f0899948d5999bc4988732b3.zip
Moved ReproduceTrees() back into init.lua
Diffstat (limited to 'gamemode/init.lua')
-rw-r--r--gamemode/init.lua105
1 files changed, 105 insertions, 0 deletions
diff --git a/gamemode/init.lua b/gamemode/init.lua
index 339c2ab..06d7d8c 100644
--- a/gamemode/init.lua
+++ b/gamemode/init.lua
@@ -208,6 +208,111 @@ end
//Moved to entity_functions.lua
+function GM.ReproduceTrees()
+ local GM = GAMEMODE
+ if ( GetConVarNumber( "gms_ReproduceTrees" ) == 1 ) then
+ local trees = {}
+ for k, v in pairs( ents.GetAll() ) do
+ if ( v:IsTreeModel() ) then
+ table.insert( trees, v )
+ end
+ end
+
+ if ( #trees < GetConVarNumber( "gms_MaxReproducedTrees" ) ) then
+ for k, ent in pairs( trees ) do
+ local num = math.random( 1, 3 )
+
+ if ( num == 1 ) then
+ local nearby = {}
+ for k, v in pairs( ents.FindInSphere( ent:GetPos(), 50 ) ) do
+ if ( v:GetClass() == "gms_seed" or v:IsProp() ) then
+ table.insert( nearby, v )
+ end
+ end
+
+ if ( #nearby < 3 ) then
+ local pos = ent:GetPos() + Vector( math.random( -500, 500 ), math.random( -500, 500 ), 0 )
+ local retries = 50
+
+ while ( ( pos:Distance( ent:GetPos() ) < 200 or GMS.ClassIsNearby( pos, "prop_physics", 100 ) ) and retries > 0 ) do
+ pos = ent:GetPos() + Vector( math.random( -300, 300 ),math.random( -300, 300 ), 0 )
+ retries = retries - 1
+ end
+
+ local pos = pos + Vector( 0, 0, 500 )
+
+ local seed = ents.Create( "gms_seed" )
+ seed:SetPos( pos )
+ seed:DropToGround()
+ seed:Setup( "tree", 180 )
+ seed:SetNetworkedString( "Owner", "World" )
+ seed:Spawn()
+ end
+ end
+ end
+ end
+ if ( #trees == 0 ) then
+ local info = {}
+ for i = 1, 20 do
+ info.pos = Vector( math.random( -10000, 10000 ), math.random( -10000, 10000 ), 1000 )
+ info.Retries = 50
+
+ --Find pos in world
+ while ( util.IsInWorld( info.pos ) == false and info.Retries > 0 ) do
+ info.pos = Vector( math.random( -10000, 10000 ),math.random( -10000, 10000 ), 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 ( info.HasSpace and skytrace.HitSky and !watertrace.Hit and ( groundtrace.MatType == MAT_DIRT or groundtrace.MatType == MAT_GRASS or groundtrace.MatType == MAT_SAND ) ) then
+ local seed = ents.Create( "gms_seed" )
+ seed:SetPos( groundtrace.HitPos )
+ seed:DropToGround()
+ seed:Setup( "tree", 180 + math.random( -20, 20 ) )
+ seed:SetNetworkedString( "Owner", "World" )
+ seed:Spawn()
+ end
+ end
+ end
+ end
+
+ timer.Simple( math.random( 1, 3 ) * 60, function() GM.ReproduceTrees() end )
+end
+timer.Simple( 60, function() GAMEMODE.ReproduceTrees() end )
+
/* ----------------------------------------------------------------------------------------------------
Admin commands
---------------------------------------------------------------------------------------------------- */