From 95bf646ef4610252f0899948d5999bc4988732b3 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 16 Apr 2016 12:22:52 -0400 Subject: Moved ReproduceTrees() back into init.lua --- gamemode/init.lua | 105 +++++++++++++++++++++++++++++++++++ gamemode/server/entity_functions.lua | 105 ----------------------------------- 2 files changed, 105 insertions(+), 105 deletions(-) (limited to 'gamemode') 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 ---------------------------------------------------------------------------------------------------- */ diff --git a/gamemode/server/entity_functions.lua b/gamemode/server/entity_functions.lua index 89fced9..3f9d6a4 100644 --- a/gamemode/server/entity_functions.lua +++ b/gamemode/server/entity_functions.lua @@ -51,111 +51,6 @@ function EntityMeta:DropToGround() self:SetPos( tr.HitPos ) end -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 ) - GMS.LootableNPCs = { "npc_antlion", "npc_antlionguard", "npc_crow", "npc_seagull", "npc_pigeon", "npc_zombie" } function EntityMeta:IsLootableNPC() -- cgit v1.2.3-70-g09d2