From 5322c9c6534054c0e2da6441e477d0b2166fbe97 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Fri, 6 May 2016 20:20:56 -0400 Subject: Did some refactoring --- gamemode/itemsystem/common_plantable.lua | 27 +++++++++++++++++++++++++++ gamemode/itemsystem/loaditems.lua | 20 ++++---------------- 2 files changed, 31 insertions(+), 16 deletions(-) (limited to 'gamemode/itemsystem') 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) -- cgit v1.2.3-70-g09d2