summaryrefslogtreecommitdiff
path: root/gamemode
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode')
-rw-r--r--gamemode/init.lua160
-rw-r--r--gamemode/itemsystem/common_plantable.lua27
-rw-r--r--gamemode/itemsystem/loaditems.lua20
3 files changed, 110 insertions, 97 deletions
diff --git a/gamemode/init.lua b/gamemode/init.lua
index 2d15d1f..ce2cddd 100644
--- a/gamemode/init.lua
+++ b/gamemode/init.lua
@@ -167,108 +167,106 @@ 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
+ if ( GetConVarNumber( "gms_ReproduceTrees" ) != 1 ) then return end
+ 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 ( #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 ( num != 1 ) then continue end
+ 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
+ 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
+ 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 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
+ local seed = ents.Create( "gms_seed" )
+ seed:SetPos( pos )
+ seed:DropToGround()
+ seed:Setup( "tree", 180 )
+ seed:SetNetworkedString( "Owner", "World" )
+ seed:Spawn()
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
+ 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 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
+ --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 )
+ local groundtrace = util.TraceLine( trace )
- --Assure space
- local nearby = ents.FindInSphere( groundtrace.HitPos, 200 )
- info.HasSpace = true
+ --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
+ 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
+ --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
- timer.Simple( math.random( 1, 3 ) * 60, function() GM.ReproduceTrees() end )
+ timer.Adjust("GMS_ReproduceTreesTimer", math.random(1, 3)*60, 0, GM.ReproduceTrees)
end
-timer.Simple( 60, function() GAMEMODE.ReproduceTrees() end )
+timer.Create("GMS_ReproduceTreesTimer",60,0,GM.ReproduceTrees)
/* ----------------------------------------------------------------------------------------------------
Admin commands
diff --git a/gamemode/itemsystem/common_plantable.lua b/gamemode/itemsystem/common_plantable.lua
index 5e3ad55..2728b9a 100644
--- a/gamemode/itemsystem/common_plantable.lua
+++ b/gamemode/itemsystem/common_plantable.lua
@@ -82,3 +82,30 @@ function GAMEMODE.MakeGenericPlantChild( ply, pos, mdl, parent )
return ent
end
+
+function GAMEMODE.MakeGenericPlant( ply, pos, mdl, isTree )
+ local ent = ents.Create( "prop_dynamic" )
+ ent:SetAngles( Angle( 0, math.random( 0, 360 ), 0 ) )
+ ent:SetSolid( SOLID_VPHYSICS )
+ ent:SetModel( mdl )
+ ent:SetPos( pos )
+ ent:Spawn()
+ ent.IsPlant = true
+ ent:SetName( "gms_plant" .. ent:EntIndex() )
+
+ ent:Fadein()
+ ent:RiseFromGround( 1, 50 )
+
+ if ( !isTree && IsValid( ply ) ) then
+ ent:SetNWEntity( "plantowner", ply )
+ SPropProtection.PlayerMakePropOwner( ply, ent )
+ else
+ ent:SetNWString( "Owner", "World" )
+ end
+
+ local phys = ent:GetPhysicsObject()
+ if ( IsValid( phys ) ) then phys:EnableMotion( false ) end
+ ent.PhysgunDisabled = true
+
+ return ent
+end
diff --git a/gamemode/itemsystem/loaditems.lua b/gamemode/itemsystem/loaditems.lua
index a77ffb3..225e56d 100644
--- a/gamemode/itemsystem/loaditems.lua
+++ b/gamemode/itemsystem/loaditems.lua
@@ -5,29 +5,17 @@
GMS.Resources = {}
function GMS.RegisterResource( tbl )
- if(tbl == nil) then
- print("/gamemode/itemsystem/loaditems.lua: Attempted to register a nil entity! This might be a bug!")
- return
- end
- if(tbl.Name == nil) then
- print("/gamemode/itemsystem/loaditems.lua: Attempted to register an item with no name:")
- PrintTable(tbl)
- print("This might be a bug!")
- return
- end
+ assert(tbl != nil,"Attempted to register a nil entity! This might be a bug!")
+ assert(tbl.Name != nil,"Attempted to register an item with no name:")
if(tbl.UniqueData) then
tbl.UniqueDataID = -1
end
- print("Registering item:" .. tbl.Name)
GMS.Resources[tbl.Name] = tbl
end
function GMS.GetResourceByName(name)
- if(GMS.Resources[name]) then
- return GMS.Resources[name]
- else
- print("Resource " .. name .. " does not exist! This might be a bug!")
- end
+ assert(GMS.Resources[name] != nil, "Resource " .. name .. " does not exist! This might be a bug!")
+ return GMS.Resources[name]
end
concommand.Add("gms_printrestable",function(ply,cmd,args)