summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2016-04-30 15:35:22 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2016-04-30 15:35:22 -0400
commit603b64b1a93b36f04d25018ec3f53b16dcd84019 (patch)
tree0bd9df6581b745d30f354f12ef420165e57b6bb5
parent677682840305841d4538c6f5d5151f36959ae56f (diff)
downloadgmstranded-603b64b1a93b36f04d25018ec3f53b16dcd84019.tar.gz
gmstranded-603b64b1a93b36f04d25018ec3f53b16dcd84019.tar.bz2
gmstranded-603b64b1a93b36f04d25018ec3f53b16dcd84019.zip
Fixed plant eating
-rw-r--r--entities/entities/gms_food.lua4
-rw-r--r--entities/entities/gms_generic_plantable.lua122
-rw-r--r--gamemode/client/cl_inventory.lua1
-rw-r--r--gamemode/configure_me.lua2
-rw-r--r--gamemode/itemsystem/common.lua69
-rw-r--r--gamemode/itemsystem/common_dropable.lua2
-rw-r--r--gamemode/itemsystem/items/bananaseeds.lua15
-rw-r--r--gamemode/itemsystem/items/berry.lua35
-rw-r--r--gamemode/itemsystem/items/grainseeds.lua6
-rw-r--r--gamemode/itemsystem/items/herbs.lua2
-rw-r--r--gamemode/itemsystem/items/melonseeds.lua13
-rw-r--r--gamemode/itemsystem/items/orangeseeds.lua21
-rw-r--r--gamemode/itemsystem/items/sprout.lua1
-rw-r--r--gamemode/processes.lua18
14 files changed, 277 insertions, 34 deletions
diff --git a/entities/entities/gms_food.lua b/entities/entities/gms_food.lua
index 2ad1297..174a46c 100644
--- a/entities/entities/gms_food.lua
+++ b/entities/entities/gms_food.lua
@@ -56,7 +56,7 @@ function ENT:Draw()
self:DrawModel()
local food = self.Food or "Loading..."
- local tex = self.FoodIcons[ string.gsub( food, " ", "_" ) ] or texLogo
+ local tex = self.FoodIcons[food] or texLogo
cam.Start3D2D( self:GetPos() + Vector( 0, 0, 20 ), self.AddAngle, 0.01 )
surface.SetDrawColor( Color( 255, 255, 255, 255 ) )
@@ -93,7 +93,7 @@ function ENT:StartTouch( ent )
if ( ent:GetClass() == "gms_resourcedrop" ) then
big_gms_combineresourcepack( self, ent )
end
- if ( ent:GetClass() == "gms_buildsite" ) then
+ if ( ent:GetClass() == "gms_buildsite" ) then
gms_addbuildsiteresourcePack( self, ent )
end
end
diff --git a/entities/entities/gms_generic_plantable.lua b/entities/entities/gms_generic_plantable.lua
new file mode 100644
index 0000000..81f31b1
--- /dev/null
+++ b/entities/entities/gms_generic_plantable.lua
@@ -0,0 +1,122 @@
+--[[
+ Things you need to set when createing a generic plantable:
+ GrowTime (number),
+ Owner (player),
+ OnGrow (function),
+]]--
+AddCSLuaFile()
+
+ENT.Type = "anim"
+ENT.Base = "gms_base_entity"
+ENT.PrintName = "Seed"
+
+ENT.Model = "models/weapons/w_bugbait.mdl"
+ENT.Color = Color( 0, 255, 0, 255 )
+
+if ( CLIENT ) then return end
+
+function ENT:OnInitialize()
+ print("Initalizeing seed")
+ timer.Simple(self.GrowTime,function()
+ print("Grow's owner is:")
+ print(self:GetOwner())
+ self:OnGrow(self,self:GetOwner())
+ self:Remove()
+ end)
+end
+
+function ENT:Grow()
+ local ply = self:GetOwner()
+ local pos = self:GetPos()
+
+ local num = 1
+ if ( IsValid( ply ) && ply:HasUnlock( "Adept_Farmer" ) ) then num = num + math.random( 0, 1 ) end
+ if ( IsValid( ply ) && ply:HasUnlock( "Expert_Farmer" ) ) then num = num + math.random( 0, 2 ) end
+
+ if ( self.Type == "tree" ) then
+ GAMEMODE.MakeTree( pos )
+ elseif ( self.Type == "melon" ) then
+ GAMEMODE.MakeMelon( pos, num, ply )
+ elseif ( self.Type == "banana" ) then
+ GAMEMODE.MakeBanana( pos, num, ply )
+ elseif ( self.Type == "orange" ) then
+ GAMEMODE.MakeOrange( pos, num, ply )
+ elseif ( self.Type == "grain" ) then
+ GAMEMODE.MakeGrain( pos, ply )
+ elseif ( self.Type == "berry" ) then
+ GAMEMODE.MakeBush( pos, ply )
+ end
+
+ self.Grown = true
+ self:Fadeout()
+end
+
+function ENT:OnRemove()
+ if ( !self.Grown && self.Type != "tree" && IsValid( self:GetOwner() ) ) then
+ self:GetOwner():SetNWInt( "plants", self:GetOwner():GetNWInt( "plants" ) - 1 )
+ end
+ timer.Destroy( "GMS_SeedTimers_" .. self:EntIndex() )
+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
+
+function GAMEMODE.MakeTree( pos )
+ //GAMEMODE.MakeGenericPlant( ply, pos, GMS.TreeModels[ math.random( 1, #GMS.TreeModels ) ], true )
+ local ent = ents.Create( "gms_tree" )
+ ent:SetPos( pos )
+ ent:Spawn()
+ ent.GMSAutoSpawned = true
+ ent:SetNetworkedString( "Owner", "World" )
+end
+
+
+function GAMEMODE.MakeBush( pos, ply )
+ GAMEMODE.MakeGenericPlant( ply, pos + Vector( math.random( -10, 10 ), math.random( -10, 10 ), 16 ), "models/props/pi_shrub.mdl" )
+end
+
+function GAMEMODE.MakeMelon( pos, num, ply )
+ local plant = GAMEMODE.MakeGenericPlant( ply, pos + Vector( 0, 0, 13 ), "models/props/CS_militia/fern01.mdl" )
+ plant.Children = 0
+
+ for i = 1, num do
+ GAMEMODE.MakeGenericPlantChild( ply, pos + Vector( math.random( -25, 25 ), math.random( -25, 25 ), math.random( 5, 7 ) ), "models/props_junk/watermelon01.mdl", plant )
+ end
+end
+
+function GAMEMODE.MakeOrange( pos, num, ply )
+ local plant = GAMEMODE.MakeGenericPlant( ply, pos + Vector( 0, 0, -12 ), "models/props/cs_office/plant01_p1.mdl" )
+ plant.Children = 0
+
+ plant:SetCollisionGroup( 0 )
+ plant:SetSolid( SOLID_NONE )
+ plant.Children = 0
+
+ for i = 1, num do
+ GAMEMODE.MakeGenericPlantChild( ply, pos + Vector( math.random( -5, 5 ), math.random( -5, 5 ), math.random( 13, 30 ) ), "models/props/cs_italy/orange.mdl", plant )
+ end
+end
diff --git a/gamemode/client/cl_inventory.lua b/gamemode/client/cl_inventory.lua
index 851626f..7578609 100644
--- a/gamemode/client/cl_inventory.lua
+++ b/gamemode/client/cl_inventory.lua
@@ -70,6 +70,7 @@ local function createPanel()
continue
else
selection:SetImage(GMS.Resources[k].Icon)
+ selection:SetTooltip(GMS.Resources[k].Description)
end
selection:SetSize(64,64)
diff --git a/gamemode/configure_me.lua b/gamemode/configure_me.lua
index 86bbd89..70d0f4b 100644
--- a/gamemode/configure_me.lua
+++ b/gamemode/configure_me.lua
@@ -4,7 +4,7 @@
jA_cOp, prop_dynamic, Chewgum, Wokkel, robotboy655
Additional content by
- Djarex, Apickx
+ Djarex, Scott, Apickx
*/
//Make sure that this is the gamemode folder name
diff --git a/gamemode/itemsystem/common.lua b/gamemode/itemsystem/common.lua
index 5a47c24..b002a43 100644
--- a/gamemode/itemsystem/common.lua
+++ b/gamemode/itemsystem/common.lua
@@ -17,9 +17,44 @@ function startProcessGeneric(player, string, time, ondone)
end)
end
-local function plant(player, planttype)
- print("Plant method called!")
+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)
@@ -30,3 +65,33 @@ function genericMakePlantable( tbl )
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_dropable.lua b/gamemode/itemsystem/common_dropable.lua
index 2b8446d..94513d3 100644
--- a/gamemode/itemsystem/common_dropable.lua
+++ b/gamemode/itemsystem/common_dropable.lua
@@ -69,7 +69,5 @@ end
net.Receive( "gms_dropresources", function(len,pl)
local resourcename = net.ReadString()
local resourcenum = net.ReadInt(GMS.NETINT_BITCOUNT)
- print("resourcename:" .. resourcename)
- print("resourcenum:" .. resourcenum)
genericDropResource(pl,resourcename,resourcenum)
end)
diff --git a/gamemode/itemsystem/items/bananaseeds.lua b/gamemode/itemsystem/items/bananaseeds.lua
index 72e14b0..4a9d0c0 100644
--- a/gamemode/itemsystem/items/bananaseeds.lua
+++ b/gamemode/itemsystem/items/bananaseeds.lua
@@ -5,6 +5,21 @@ ITEM.Description = "Something you can plant!"
ITEM.Icon = "test.png"
ITEM.UniqueData = false
+
+--Things needed to make something plantable
+ITEM.GrowTime = 1
+ITEM.OnGrow = function(self, aor, owner)
+ local plant = GAMEMODE.MakeGenericPlant( owner, self:GetPos() + Vector( 0, 0, -3 ), "models/props/de_dust/du_palm_tree01_skybx.mdl" )
+ plant.Children = 0
+
+ local num = 1
+ if ( IsValid( ply ) && ply:HasUnlock( "Adept_Farmer" ) ) then num = num + math.random( 0, 1 ) end
+ if ( IsValid( ply ) && ply:HasUnlock( "Expert_Farmer" ) ) then num = num + math.random( 0, 2 ) end
+
+ for i = 1, num do
+ GAMEMODE.MakeGenericPlantChild( owner, self:GetPos() + Vector( math.random( -7, 7 ), math.random( -7, 7 ), math.random( 48, 55 ) ), "models/props/cs_italy/bananna_bunch.mdl", plant )
+ end
+end
genericMakePlantable(ITEM)
genericMakeDroppable(ITEM)
diff --git a/gamemode/itemsystem/items/berry.lua b/gamemode/itemsystem/items/berry.lua
index acf018d..77a3a35 100644
--- a/gamemode/itemsystem/items/berry.lua
+++ b/gamemode/itemsystem/items/berry.lua
@@ -9,29 +9,30 @@ if(SERVER) then
util.AddNetworkString( "gms_eatberry" )
end
+local eat_client = function(ln, player)
+ net.Start("gms_eatberry")
+ net.SendToServer()
+end
+
+local finishedeating = function()
+ player:DecResource( "Berries", 1 )
+ player:SendMessage( "You're a little less hungry and thirsty now.", 3, Color( 10, 200, 10, 255 ) )
+ --Set hunger and thirst
+ player:SetFood(math.Clamp(player.Hunger+100,0,1000))
+ player:SetThirst(math.Clamp(player.Thirst+100,0,1000))
+end
+
local eat = function(ln, player)
- if(CLIENT) then
- net.Start("gms_eatberry")
- net.SendToServer()
- end
- if(SERVER) then
- if(player.Resources["Berries"] <= 0) then
- player:SendMessage( "You don't have enough to do that!", 3, Color( 10, 200, 10, 255 ) )
- return
- end
- startProcessGeneric(player,"Eating some berries",3,function()
- player:DecResource( "Berries", 1 )
- player:SendMessage( "You're a little less hungry and thirsty now.", 3, Color( 10, 200, 10, 255 ) )
- --Set hunger and thirst
- player:SetFood(math.Clamp(player.Hunger+100,0,1000))
- player:SetThirst(math.Clamp(player.Thirst+100,0,1000))
- end)
+ if(player.Resources["Berries"] <= 0) then
+ player:SendMessage( "You don't have enough to do that!", 3, Color( 10, 200, 10, 255 ) )
+ return
end
+ startProcessGeneric(player,"Eating some berries",3,finishedeating)
end
net.Receive( "gms_eatberry", eat)
ITEM.Actions = {}
genericMakeDroppable(ITEM)
-ITEM.Actions["Eat Berry"] = eat
+ITEM.Actions["Eat Berry"] = eat_client
GMS.RegisterResource(ITEM)
diff --git a/gamemode/itemsystem/items/grainseeds.lua b/gamemode/itemsystem/items/grainseeds.lua
index 9057df8..5b7ba3c 100644
--- a/gamemode/itemsystem/items/grainseeds.lua
+++ b/gamemode/itemsystem/items/grainseeds.lua
@@ -5,6 +5,12 @@ ITEM.Description = "Something you can plant, or mash up into flour"
ITEM.Icon = "test.png"
ITEM.UniqueData = false
+
+--Things needed to make something plantable
+ITEM.GrowTime = 1
+ITEM.OnGrow = function(self, aor, owner)
+ GAMEMODE.MakeGenericPlant( owner, self:GetPos() + Vector( math.random( -10, 10 ), math.random( -10, 10 ), 0 ), "models/props_foliage/cattails.mdl" )
+end
genericMakePlantable(ITEM)
genericMakeDroppable(ITEM)
diff --git a/gamemode/itemsystem/items/herbs.lua b/gamemode/itemsystem/items/herbs.lua
index c9339ce..f0b9dc8 100644
--- a/gamemode/itemsystem/items/herbs.lua
+++ b/gamemode/itemsystem/items/herbs.lua
@@ -1,7 +1,7 @@
ITEM = {}
ITEM.Name = "Herbs"
-ITEM.Description = "Something you can plant!"
+ITEM.Description = "Blech, vegtables..."
ITEM.Icon = "test.png"
ITEM.UniqueData = false
diff --git a/gamemode/itemsystem/items/melonseeds.lua b/gamemode/itemsystem/items/melonseeds.lua
index 8ddaea5..8d82f7a 100644
--- a/gamemode/itemsystem/items/melonseeds.lua
+++ b/gamemode/itemsystem/items/melonseeds.lua
@@ -5,6 +5,19 @@ ITEM.Description = "Something you can plant!"
ITEM.Icon = "test.png"
ITEM.UniqueData = false
+ITEM.GrowTime = 1
+ITEM.OnGrow = function(self, aor, owner)
+ local plant = GAMEMODE.MakeGenericPlant( owner, self:GetPos() + Vector( 0, 0, 13 ), "models/props/CS_militia/fern01.mdl" )
+ plant.Children = 0
+
+ local num = 1
+ if ( IsValid( ply ) && ply:HasUnlock( "Adept_Farmer" ) ) then num = num + math.random( 0, 1 ) end
+ if ( IsValid( ply ) && ply:HasUnlock( "Expert_Farmer" ) ) then num = num + math.random( 0, 2 ) end
+
+ for i = 1, num do
+ GAMEMODE.MakeGenericPlantChild( owner, self:GetPos() + Vector( math.random( -25, 25 ), math.random( -25, 25 ), math.random( 5, 7 ) ), "models/props_junk/watermelon01.mdl", plant )
+ end
+end
genericMakeDroppable(ITEM)
genericMakePlantable(ITEM)
diff --git a/gamemode/itemsystem/items/orangeseeds.lua b/gamemode/itemsystem/items/orangeseeds.lua
index 01122c3..c9c3963 100644
--- a/gamemode/itemsystem/items/orangeseeds.lua
+++ b/gamemode/itemsystem/items/orangeseeds.lua
@@ -5,6 +5,27 @@ ITEM.Description = "Something you can plant!"
ITEM.Icon = "test.png"
ITEM.UniqueData = false
+--Things needed to make something plantable
+ITEM.GrowTime = 1
+ITEM.OnGrow = function(self, aor, owner)
+ print("Owner:")
+ print(owner)
+ local plant = GAMEMODE.MakeGenericPlant( owner, self:GetPos() + Vector( 0, 0, -12 ), "models/props/cs_office/plant01_p1.mdl" )
+ plant.Children = 0
+
+ plant:SetCollisionGroup( 0 )
+ plant:SetSolid( SOLID_NONE )
+ plant.Children = 0
+
+ local num = 1
+ if ( IsValid( owner ) && owner:HasUnlock( "Adept_Farmer" ) ) then num = num + math.random( 0, 1 ) end
+ if ( IsValid( owner ) && owner:HasUnlock( "Expert_Farmer" ) ) then num = num + math.random( 0, 2 ) end
+
+ for i = 1, num do
+ GAMEMODE.MakeGenericPlantChild( owner, self:GetPos() + Vector( math.random( -5, 5 ), math.random( -5, 5 ), math.random( 13, 30 ) ), "models/props/cs_italy/orange.mdl", plant )
+ end
+end
+
genericMakePlantable(ITEM)
genericMakeDroppable(ITEM)
diff --git a/gamemode/itemsystem/items/sprout.lua b/gamemode/itemsystem/items/sprout.lua
new file mode 100644
index 0000000..218ff2c
--- /dev/null
+++ b/gamemode/itemsystem/items/sprout.lua
@@ -0,0 +1 @@
+print("Hello from sprout.lua!")
diff --git a/gamemode/processes.lua b/gamemode/processes.lua
index 4b7fc15..333f404 100644
--- a/gamemode/processes.lua
+++ b/gamemode/processes.lua
@@ -93,11 +93,11 @@ function PROCESS:OnStart()
if ( plant ) then owner = plant:GetNWEntity( "plantowner" ) end
if ( self.Data.Entity:GetModel() == "models/props_junk/watermelon01.mdl" ) then
- self.SideGain = "Melon_Seeds"
+ self.SideGain = "Melon Seeds"
elseif ( self.Data.Entity:GetModel() == "models/props/cs_italy/orange.mdl" ) then
- self.SideGain = "Orange_Seeds"
+ self.SideGain = "Orange Seeds"
elseif ( self.Data.Entity:GetModel() == "models/props/cs_italy/bananna_bunch.mdl" ) then
- self.SideGain = "Banana_Seeds"
+ self.SideGain = "Banana Seeds"
end
if ( plant ) then
@@ -122,7 +122,7 @@ function PROCESS:OnStop()
local num = math.random( numstart, numto )
if ( num ~= 0 ) then
self.Owner:IncResource( self.SideGain, num )
- self.Owner:SendMessage( string.gsub( self.SideGain, "_", " " ) .. " ( " .. num .. "x )", 3, Color( 10, 200, 10, 255 ) )
+ self.Owner:SendMessage( self.SideGain .. " ( " .. num .. "x )", 3, Color( 10, 200, 10, 255 ) )
self.Owner:EmitSound( Sound( "items/ammo_pickup.wav" ) )
end
end
@@ -407,7 +407,7 @@ function PROCESS:OnStop()
if ( num > 50 - self.Owner:GetSkill( "Harvesting" ) - add ) then
local amount = math.random( 1, 2 )
- self.Owner:IncResource( "Grain_Seeds", amount )
+ self.Owner:IncResource( "Grain Seeds", amount )
self.Owner:IncXP( "Harvesting", math.Clamp( math.Round( 50 / self.Owner:GetSkill( "Harvesting" ) ), 1, 1000 ) )
self.Owner:SendMessage( "Grain Seeds ( " .. amount .. "x )", 3, Color( 10, 200, 10, 255 ) )
self.Owner:EmitSound( Sound( "items/ammo_pickup.wav" ) )
@@ -698,10 +698,10 @@ GMS.RegisterProcess( "SproutCollect", PROCESS )
---------------------------------------------------------*/
/*Alright, let's refactor this planting code*/
local plant_generic = {
- {"Watermelon","Melon_Seeds","melon","PlantMelon"},
- {"Banana","Banana_Seeds","banana","PlantBanana"},
- {"Orange","Orange_Seeds","orange","PlantOrange"},
- {"Grain","Grain_Seeds","grain","PlantGrain"},
+ {"Watermelon","Melon Seeds","melon","PlantMelon"},
+ {"Banana","Banana Seeds","banana","PlantBanana"},
+ {"Orange","Orange Seeds","orange","PlantOrange"},
+ {"Grain","Grain Seeds","grain","PlantGrain"},
{"Berry Bush","Berries","berry","PlantBush"},
{"Tree","Sprouts","tree","PlantTree"},
}