diff options
| author | Scott <scotth0828@gmail.com> | 2016-04-30 20:34:42 -0400 |
|---|---|---|
| committer | Scott <scotth0828@gmail.com> | 2016-04-30 20:34:42 -0400 |
| commit | bdf6cacc1fe7af364b93604253f3229d842d6170 (patch) | |
| tree | 21015081b4d66d45390ba625c09fb84d143f63db /gamemode/itemsystem/common.lua | |
| parent | e8fc8b5bf824ed3283dede946e66f5fd843d54ff (diff) | |
| parent | c6b56a911622f9a52fd92293074192d1f13d3e96 (diff) | |
| download | gmstranded-bdf6cacc1fe7af364b93604253f3229d842d6170.tar.gz gmstranded-bdf6cacc1fe7af364b93604253f3229d842d6170.tar.bz2 gmstranded-bdf6cacc1fe7af364b93604253f3229d842d6170.zip | |
Merge branch 'master' of ssh://cogarr.net:43/home/git/gmsurvival
Diffstat (limited to 'gamemode/itemsystem/common.lua')
| -rw-r--r-- | gamemode/itemsystem/common.lua | 81 |
1 files changed, 66 insertions, 15 deletions
diff --git a/gamemode/itemsystem/common.lua b/gamemode/itemsystem/common.lua index f7d6c72..b002a43 100644 --- a/gamemode/itemsystem/common.lua +++ b/gamemode/itemsystem/common.lua @@ -18,29 +18,80 @@ function startProcessGeneric(player, string, time, ondone) end if(SERVER) then - util.AddNetworkString( "gms_dropresources" ) + util.AddNetworkString( "gms_plantseed" ) end -function genericDropResource(player, resource, ammount) +local function plant(player, resourcename) if(CLIENT) then - net.Start("gms_dropresources") - net.WriteString(resource) - net.WriteInt(ammount,GMS.NETINT_BITCOUNT) + net.Start("gms_plantseed") + net.WriteString(resourcename) net.SendToServer() end if(SERVER) then - if(player.Resources[resource] <= ammount) then - player:SendMessage("You don't have that many to drop!", 3, Color(255, 255, 255, 255)) + 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 - local res = ply:GetResource( Type ) - - if ( ammount > res ) then - ammount = res + if(tbl.OnGrow == nil) then + print(tbl.Name .. " .OnGrow is nil, this might be a bug!") + return end - ply:DropResource( Type, int ) - ply:DecResource( Type, int ) + + 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_dropresources", function(len,pl) - genericDropResource(pl,net.ReadString(),net.ReadInt(GMS.NETINT_BITCOUNT)) +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 |
