--[[ You can call genericMakePlantable(ITEM) on items to make them have a plant option. Before genericMakePlantable get called, be sure the item has an .GrowTime =number and a .OnGrow = function(player) ]] if (SERVER) then util.AddNetworkString( "gms_plantseed" ) end local function plant(player, resourcename) if (CLIENT) then net.Start("gms_plantseed") net.WriteString(resourcename) net.SendToServer() end if (SERVER) then local tbl = GMS.Resources[resourcename] assert(tbl.GrowTime != nil,tbl.Name .. " .GrowTime is nil!") assert(isfunction(tbl.OnGrow),tbl.Name .. " .OnGrow is not a table") if(player:GetNWInt("plants") > GetConVar("gms_PlantLimit")) then player:SendMessage( "You man only have " .. GetConVar("gms_PlantLimit") .. " plants at a time.", 3, Color( 10, 200, 10, 255 ) ) return end local tr = player:GetEyeTrace() if (player:GetPos():Distance(tr.HitPos) > 180 ) then player:SendMessage( "Too far away to plant", 3, Color( 10, 200, 10, 255 ) ) return end local pent = ents.Create("gms_generic_plantable") pent:SetPos(tr.HitPos) pent.GrowTime = tbl.GrowTime pent.OnGrow = tbl.OnGrow pent:SetOwner(player) pent:Spawn() player.NumPlants += 1 player:DecResource( resourcename, 1 ) end end net.Receive( "gms_plantseed", function(len,pl) local resourcename = net.ReadString() plant(pl,resourcename) end) function genericMakePlantable( tbl ) local plantthis = function(player) plant(player,tbl.Name) end if (tbl.Actions == nil) then tbl.Actions = {} end tbl.Actions["Plant " .. tbl.Name] = plantthis end GAMEMODE = GAMEMODE or {} function GAMEMODE.MakeGenericPlantChild( ply, pos, mdl, parent ) local ent = ents.Create( "prop_physics" ) ent:SetAngles( Angle( 0, math.random( 0, 360 ) , 0 ) ) ent:SetModel( mdl ) ent:SetPos( pos ) ent:Spawn() ent.IsPlantChild = true ent:SetHealth( 99999 ) ent:Fadein() local phys = ent:GetPhysicsObject() if ( phys ) then phys:EnableMotion( false ) end ent.PlantParent = parent ent.PlantParentName = parent:GetName() parent.Children = parent.Children + 1 if ( IsValid( ply ) ) then SPropProtection.PlayerMakePropOwner( ply, ent ) else ent:SetNWString( "Owner", "World" ) end ent.PhysgunDisabled = true return ent end function GAMEMODE.MakeGenericPlant( ply, pos, mdl, isWorld ) 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 ( !isWorld && 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