From dce5504f263477402bb39f501f46a290f7531dfd Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 21 May 2016 14:12:49 -0400 Subject: Moved planting distance check to server-side --- gamemode/itemsystem/common_plantable.lua | 121 +++++++++++++++---------------- 1 file changed, 59 insertions(+), 62 deletions(-) (limited to 'gamemode') diff --git a/gamemode/itemsystem/common_plantable.lua b/gamemode/itemsystem/common_plantable.lua index 067f464..44b491b 100644 --- a/gamemode/itemsystem/common_plantable.lua +++ b/gamemode/itemsystem/common_plantable.lua @@ -4,35 +4,32 @@ Before genericMakePlantable get called, be sure the item has an .GrowTime =numbe and a .OnGrow = function(player) ]] -if(SERVER) then +if (SERVER) then util.AddNetworkString( "gms_plantseed" ) end local function plant(player, resourcename) - if(CLIENT) then - - if LocalPlayer():GetPos():Distance( LocalPlayer():GetEyeTrace().HitPos ) > 180 then - - chat.AddText( Color( 200, 0, 0 ), "Too far away!" ) - return false - - end + if (CLIENT) then net.Start("gms_plantseed") net.WriteString(resourcename) net.SendToServer() end - if(SERVER) then + 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") 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 ) ) + 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:DecResource( resourcename, 1 ) + player:DecResource( resourcename, 1 ) end end net.Receive( "gms_plantseed", function(len,pl) @@ -41,68 +38,68 @@ net.Receive( "gms_plantseed", function(len,pl) end) function genericMakePlantable( tbl ) - local plant = function(player) + local plantthis = function(player) plant(player,tbl.Name) end - if(tbl.Actions == nil) then + if (tbl.Actions == nil) then tbl.Actions = {} end - tbl.Actions["Plant " .. tbl.Name] = plant + 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 + 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 + ent.PhysgunDisabled = true - return ent + 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 + 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 -- cgit v1.2.3-70-g09d2