diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2016-05-01 09:30:17 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2016-05-01 09:30:17 -0400 |
| commit | dc10ffe19c42aba8e365e2651c8368f5300531e9 (patch) | |
| tree | d0cc8d316de62400a2434c1e2aec8402a25e3252 /gamemode | |
| parent | 052d3aad1a4b3e13a6c4f50095fdc9803701c857 (diff) | |
| download | gmstranded-dc10ffe19c42aba8e365e2651c8368f5300531e9.tar.gz gmstranded-dc10ffe19c42aba8e365e2651c8368f5300531e9.tar.bz2 gmstranded-dc10ffe19c42aba8e365e2651c8368f5300531e9.zip | |
Moved item planting code into it's own file
Diffstat (limited to 'gamemode')
| -rw-r--r-- | gamemode/client/cl_syncronize.lua | 4 | ||||
| -rw-r--r-- | gamemode/itemsystem/common.lua | 79 | ||||
| -rw-r--r-- | gamemode/itemsystem/common_plantable.lua | 85 |
3 files changed, 84 insertions, 84 deletions
diff --git a/gamemode/client/cl_syncronize.lua b/gamemode/client/cl_syncronize.lua index 189dd08..fa60de0 100644 --- a/gamemode/client/cl_syncronize.lua +++ b/gamemode/client/cl_syncronize.lua @@ -23,7 +23,3 @@ net.Receive( "gms_SetResource", function( length, pl) print("Finished resource get") GAMEMODE:ReloadSpawnMenu() end) - -concommand.Add("gms_cl_printresources",function(ply,cmd,args) - PrintTable(Resources) -end) diff --git a/gamemode/itemsystem/common.lua b/gamemode/itemsystem/common.lua index 114340b..512bec5 100644 --- a/gamemode/itemsystem/common.lua +++ b/gamemode/itemsystem/common.lua @@ -16,82 +16,3 @@ function startProcessGeneric(player, string, time, ondone) ondone(player) end) end - -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 - print("Planting " .. resourcename) - local tbl = GMS.Resources[resourcename] - print("Plant table:") - PrintTable(tbl) - if(tbl.GrowTime == nil) then - print(tbl.Name .. " .GrowTime is nil, this might be a bug!") - return - end - if(tbl.OnGrow == nil) then - print(tbl.Name .. " .OnGrow is nil, this might be a bug!") - return - end - - local tr = player:GetEyeTrace() - local pent = ents.Create("gms_generic_plantable") - pent:SetPos(tr.HitPos) - pent.GrowTime = tbl.GrowTime - pent.OnGrow = tbl.OnGrow - print("Setting seed's owner to:") - print(player) - pent:SetOwner(player) - pent:Spawn() - end -end -net.Receive( "gms_plantseed", function(len,pl) - local resourcename = net.ReadString() - plant(pl,resourcename) -end) - -function genericMakePlantable( tbl ) - local plant = function(player) - plant(player,tbl.Name) - end - if(tbl.Actions == nil) then - tbl.Actions = {} - end - tbl.Actions["Plant " .. tbl.Name] = plant -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 diff --git a/gamemode/itemsystem/common_plantable.lua b/gamemode/itemsystem/common_plantable.lua index 383d8d2..5e3ad55 100644 --- a/gamemode/itemsystem/common_plantable.lua +++ b/gamemode/itemsystem/common_plantable.lua @@ -1 +1,84 @@ -print("Hello from common_plantable.lua!") +--[[ +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 + print("Planting " .. resourcename) + local tbl = GMS.Resources[resourcename] + print("Plant table:") + PrintTable(tbl) + if(tbl.GrowTime == nil) then + print(tbl.Name .. " .GrowTime is nil, this might be a bug!") + return + end + if(tbl.OnGrow == nil) then + print(tbl.Name .. " .OnGrow is nil, this might be a bug!") + return + end + + local tr = player:GetEyeTrace() + local pent = ents.Create("gms_generic_plantable") + pent:SetPos(tr.HitPos) + pent.GrowTime = tbl.GrowTime + pent.OnGrow = tbl.OnGrow + print("Setting seed's owner to:") + print(player) + pent:SetOwner(player) + pent:Spawn() + end +end +net.Receive( "gms_plantseed", function(len,pl) + local resourcename = net.ReadString() + plant(pl,resourcename) +end) + +function genericMakePlantable( tbl ) + local plant = function(player) + plant(player,tbl.Name) + end + if(tbl.Actions == nil) then + tbl.Actions = {} + end + tbl.Actions["Plant " .. tbl.Name] = plant +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 |
