From c90d4ae74d9a51249009ebac34d3627bc3812fa3 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Fri, 29 Apr 2016 22:17:10 -0400 Subject: Fixed up inventory --- gamemode/itemsystem/common.lua | 51 ++++++++++++++++++++++++++++--- gamemode/itemsystem/items/baits.lua | 18 +---------- gamemode/itemsystem/items/bananaseeds.lua | 18 +---------- gamemode/itemsystem/items/berry.lua | 18 +---------- gamemode/itemsystem/items/grainseeds.lua | 18 +---------- gamemode/itemsystem/items/herbs.lua | 18 +---------- gamemode/itemsystem/items/melonseeds.lua | 18 +---------- gamemode/itemsystem/items/orangeseeds.lua | 18 +---------- 8 files changed, 53 insertions(+), 124 deletions(-) (limited to 'gamemode/itemsystem') diff --git a/gamemode/itemsystem/common.lua b/gamemode/itemsystem/common.lua index f7d6c72..65239d6 100644 --- a/gamemode/itemsystem/common.lua +++ b/gamemode/itemsystem/common.lua @@ -17,6 +17,43 @@ function startProcessGeneric(player, string, time, ondone) end) end +function genericMakeDroppable(tbl) + local drop1 = function(player) + genericDropResource(player,tbl.Name,1) + end + local dropall = function(player) + PrintTable(Resources) + print("Ammount:" .. Resources[tbl.Name]) + genericDropResource(player,tbl.Name,Resources[tbl.Name]) + end + local dropx = function(player) + if(SERVER) then return end + local frame = vgui.Create( "DFrame" ) + frame:SetSize( 400, 200 ) + frame:Center() + frame:MakePopup() + + local TextEntry = vgui.Create( "DTextEntry", frame ) -- create the form as a child of frame + TextEntry:SetPos( 25, 50 ) + TextEntry:SetSize( 75, 85 ) + TextEntry:SetText( "Sample String" ) + TextEntry.OnEnter = function( self ) + genericDropResource(player,tbl.Name,self:GetValue()) + end + + end + if(tbl.Actions == nil) then + tbl.Actions = {} + end + if(tbl.Actions["Drop"] == nil) then + tbl.Actions["Drop"] = {} + end + tbl.Actions["Drop"]["Drop 1"] = drop1 + tbl.Actions["Drop"]["Drop all"] = dropall + tbl.Actions["Drop"]["Drop X"] = dropx +end + + if(SERVER) then util.AddNetworkString( "gms_dropresources" ) end @@ -28,19 +65,23 @@ function genericDropResource(player, resource, ammount) net.SendToServer() end if(SERVER) then - if(player.Resources[resource] <= ammount) then + if(player.Resources[resource] < ammount) then player:SendMessage("You don't have that many to drop!", 3, Color(255, 255, 255, 255)) return end - local res = ply:GetResource( Type ) + local res = player.Resources[resource] if ( ammount > res ) then ammount = res end - ply:DropResource( Type, int ) - ply:DecResource( Type, int ) + player:DropResource( resource, ammount ) + player:DecResource( resource, ammount ) end end net.Receive( "gms_dropresources", function(len,pl) - genericDropResource(pl,net.ReadString(),net.ReadInt(GMS.NETINT_BITCOUNT)) + 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/baits.lua b/gamemode/itemsystem/items/baits.lua index 47bf1d0..f6824cd 100644 --- a/gamemode/itemsystem/items/baits.lua +++ b/gamemode/itemsystem/items/baits.lua @@ -5,22 +5,6 @@ ITEM.Description = "Something you can plant!" ITEM.Icon = "test.png" ITEM.UniqueData = false -local drop1 = function(player) - print("Drop 1 called") -end - -local dropall = function(player) - print("Drop all called") -end - -local dropx = function(player) - print("Drop x called") -end - -ITEM.Actions = {} -ITEM.Actions["Drop"] = {} -ITEM.Actions["Drop"]["Drop 1"] = drop1 -ITEM.Actions["Drop"]["Drop all"] = dropall -ITEM.Actions["Drop"]["Drop X"] = dropx +genericMakeDroppable(ITEM) GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/bananaseeds.lua b/gamemode/itemsystem/items/bananaseeds.lua index 358ed63..103bca9 100644 --- a/gamemode/itemsystem/items/bananaseeds.lua +++ b/gamemode/itemsystem/items/bananaseeds.lua @@ -5,22 +5,6 @@ ITEM.Description = "Something you can plant!" ITEM.Icon = "test.png" ITEM.UniqueData = false -local drop1 = function(player) - print("Drop 1 called") -end - -local dropall = function(player) - print("Drop all called") -end - -local dropx = function(player) - print("Drop x called") -end - -ITEM.Actions = {} -ITEM.Actions["Drop"] = {} -ITEM.Actions["Drop"]["Drop 1"] = drop1 -ITEM.Actions["Drop"]["Drop all"] = dropall -ITEM.Actions["Drop"]["Drop X"] = dropx +genericMakeDroppable(ITEM) GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/berry.lua b/gamemode/itemsystem/items/berry.lua index 2021ffd..125a78b 100644 --- a/gamemode/itemsystem/items/berry.lua +++ b/gamemode/itemsystem/items/berry.lua @@ -30,24 +30,8 @@ local eat = function(ln, player) end net.Receive( "gms_eatberry", eat) -local drop1 = function(player) - genericDropResource(player,ITEM.Name,1) -end - -local dropall = function(player) - genericDropResource(player,ITEM.Name,9999) -end - -local dropx = function(player) - print("Drop x called") -end - ITEM.Actions = {} +genericMakeDroppable(ITEM) ITEM.Actions["EatBerry"] = eat -ITEM.Actions["Drop"] = {} -ITEM.Actions["Drop"]["Drop 1"] = drop1 -ITEM.Actions["Drop"]["Drop all"] = dropall -ITEM.Actions["Drop"]["Drop X"] = dropx - GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/grainseeds.lua b/gamemode/itemsystem/items/grainseeds.lua index 9b22a0b..be81e5f 100644 --- a/gamemode/itemsystem/items/grainseeds.lua +++ b/gamemode/itemsystem/items/grainseeds.lua @@ -5,22 +5,6 @@ ITEM.Description = "Something you can plant, or mash up into flour" ITEM.Icon = "test.png" ITEM.UniqueData = false -local drop1 = function(player) - print("Drop 1 called") -end - -local dropall = function(player) - print("Drop all called") -end - -local dropx = function(player) - print("Drop x called") -end - -ITEM.Actions = {} -ITEM.Actions["Drop"] = {} -ITEM.Actions["Drop"]["Drop 1"] = drop1 -ITEM.Actions["Drop"]["Drop all"] = dropall -ITEM.Actions["Drop"]["Drop X"] = dropx +genericMakeDroppable(ITEM) GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/herbs.lua b/gamemode/itemsystem/items/herbs.lua index 9db5417..c9339ce 100644 --- a/gamemode/itemsystem/items/herbs.lua +++ b/gamemode/itemsystem/items/herbs.lua @@ -5,22 +5,6 @@ ITEM.Description = "Something you can plant!" ITEM.Icon = "test.png" ITEM.UniqueData = false -local drop1 = function(player) - print("Drop 1 called") -end - -local dropall = function(player) - print("Drop all called") -end - -local dropx = function(player) - print("Drop x called") -end - -ITEM.Actions = {} -ITEM.Actions["Drop"] = {} -ITEM.Actions["Drop"]["Drop 1"] = drop1 -ITEM.Actions["Drop"]["Drop all"] = dropall -ITEM.Actions["Drop"]["Drop X"] = dropx +genericMakeDroppable(ITEM) GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/melonseeds.lua b/gamemode/itemsystem/items/melonseeds.lua index 874ac46..84d4f95 100644 --- a/gamemode/itemsystem/items/melonseeds.lua +++ b/gamemode/itemsystem/items/melonseeds.lua @@ -5,22 +5,6 @@ ITEM.Description = "Something you can plant!" ITEM.Icon = "test.png" ITEM.UniqueData = false -local drop1 = function(player) - print("Drop 1 called") -end - -local dropall = function(player) - print("Drop all called") -end - -local dropx = function(player) - print("Drop x called") -end - -ITEM.Actions = {} -ITEM.Actions["Drop"] = {} -ITEM.Actions["Drop"]["Drop 1"] = drop1 -ITEM.Actions["Drop"]["Drop all"] = dropall -ITEM.Actions["Drop"]["Drop X"] = dropx +genericMakeDroppable(ITEM) GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/orangeseeds.lua b/gamemode/itemsystem/items/orangeseeds.lua index 33fd698..39a2bec 100644 --- a/gamemode/itemsystem/items/orangeseeds.lua +++ b/gamemode/itemsystem/items/orangeseeds.lua @@ -5,22 +5,6 @@ ITEM.Description = "Something you can plant!" ITEM.Icon = "test.png" ITEM.UniqueData = false -local drop1 = function(player) - print("Drop 1 called") -end - -local dropall = function(player) - print("Drop all called") -end - -local dropx = function(player) - print("Drop x called") -end - -ITEM.Actions = {} -ITEM.Actions["Drop"] = {} -ITEM.Actions["Drop"]["Drop 1"] = drop1 -ITEM.Actions["Drop"]["Drop all"] = dropall -ITEM.Actions["Drop"]["Drop X"] = dropx +genericMakeDroppable(ITEM) GMS.RegisterResource(ITEM) -- cgit v1.2.3-70-g09d2 From 57b9d6d553943190c58b7d5f77d2ee475fe36479 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 30 Apr 2016 00:12:48 -0400 Subject: Improvements to inventory --- gamemode/client/cl_inventory.lua | 6 ++- gamemode/init.lua | 6 ++- gamemode/itemsystem/common.lua | 67 +------------------------------ gamemode/itemsystem/common_dropable.lua | 70 +++++++++++++++++++++++++++++++++ gamemode/itemsystem/items/berry.lua | 4 +- gamemode/server/player_functions.lua | 19 +++------ 6 files changed, 87 insertions(+), 85 deletions(-) create mode 100644 gamemode/itemsystem/common_dropable.lua (limited to 'gamemode/itemsystem') diff --git a/gamemode/client/cl_inventory.lua b/gamemode/client/cl_inventory.lua index ab6f196..851626f 100644 --- a/gamemode/client/cl_inventory.lua +++ b/gamemode/client/cl_inventory.lua @@ -94,13 +94,11 @@ end local invpanel = nil function GM:OnSpawnMenuOpen() - print("Spawn menu hooked correctly") if(invpanel == nil) then invpanel = createPanel() return end - print("Not nil") if(! invpanel:IsValid()) then invpanel = createPanel() return @@ -108,12 +106,16 @@ function GM:OnSpawnMenuOpen() end function GM:ReloadSpawnMenu() + if(invpanel == nil) then + return + end if(!invpanel:IsValid()) then return end if(invpanel != nil) then invpanel:Close() invpanel = createPanel() + return end end diff --git a/gamemode/init.lua b/gamemode/init.lua index eb00238..a4c480a 100644 --- a/gamemode/init.lua +++ b/gamemode/init.lua @@ -129,7 +129,11 @@ function GM.FindTribeByID( id ) end -- Cancel process -concommand.Add( "gms_cancelprocess", function( ply, cmd, args ) ply:CancelProcess() end ) +concommand.Add( "gms_cancelprocess", function( ply, cmd, args ) + ply:CancelProcess() + + +end ) /* Menu toggles */ function GM:ShowHelp( ply ) end diff --git a/gamemode/itemsystem/common.lua b/gamemode/itemsystem/common.lua index 65239d6..674c0ce 100644 --- a/gamemode/itemsystem/common.lua +++ b/gamemode/itemsystem/common.lua @@ -17,71 +17,6 @@ function startProcessGeneric(player, string, time, ondone) end) end -function genericMakeDroppable(tbl) - local drop1 = function(player) - genericDropResource(player,tbl.Name,1) - end - local dropall = function(player) - PrintTable(Resources) - print("Ammount:" .. Resources[tbl.Name]) - genericDropResource(player,tbl.Name,Resources[tbl.Name]) - end - local dropx = function(player) - if(SERVER) then return end - local frame = vgui.Create( "DFrame" ) - frame:SetSize( 400, 200 ) - frame:Center() - frame:MakePopup() +function genericMakePlantable( tbl ) - local TextEntry = vgui.Create( "DTextEntry", frame ) -- create the form as a child of frame - TextEntry:SetPos( 25, 50 ) - TextEntry:SetSize( 75, 85 ) - TextEntry:SetText( "Sample String" ) - TextEntry.OnEnter = function( self ) - genericDropResource(player,tbl.Name,self:GetValue()) - end - - end - if(tbl.Actions == nil) then - tbl.Actions = {} - end - if(tbl.Actions["Drop"] == nil) then - tbl.Actions["Drop"] = {} - end - tbl.Actions["Drop"]["Drop 1"] = drop1 - tbl.Actions["Drop"]["Drop all"] = dropall - tbl.Actions["Drop"]["Drop X"] = dropx -end - - -if(SERVER) then - util.AddNetworkString( "gms_dropresources" ) -end -function genericDropResource(player, resource, ammount) - if(CLIENT) then - net.Start("gms_dropresources") - net.WriteString(resource) - net.WriteInt(ammount,GMS.NETINT_BITCOUNT) - 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)) - return - end - local res = player.Resources[resource] - - if ( ammount > res ) then - ammount = res - end - player:DropResource( resource, ammount ) - player:DecResource( resource, ammount ) - end 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/common_dropable.lua b/gamemode/itemsystem/common_dropable.lua new file mode 100644 index 0000000..1f4ec7e --- /dev/null +++ b/gamemode/itemsystem/common_dropable.lua @@ -0,0 +1,70 @@ +function genericMakeDroppable(tbl) + local drop1 = function(player) + genericDropResource(player,tbl.Name,1) + end + local dropall = function(player) + PrintTable(Resources) + print("Ammount:" .. Resources[tbl.Name]) + genericDropResource(player,tbl.Name,Resources[tbl.Name]) + end + local dropx = function(player) + if(SERVER) then return end + local frame = vgui.Create( "DFrame" ) + frame:SetSize( 400, 60 ) + frame:Center() + frame:MakePopup() + + local TextEntry = vgui.Create( "DTextEntry", frame ) -- create the form as a child of frame + TextEntry:SetPos( 20, 30 ) + TextEntry:SetSize( 360, 20 ) + TextEntry:SetText( "Number to drop:" ) + TextEntry.OnEnter = function( self ) + if(tonumber(self:GetValue(),10) == nil) then return end + genericDropResource(player,tbl.Name,self:GetValue()) + frame:Close() + end + + end + if(tbl.Actions == nil) then + tbl.Actions = {} + end + if(tbl.Actions["Drop"] == nil) then + tbl.Actions["Drop"] = {} + end + tbl.Actions["Drop"]["Drop 1"] = drop1 + tbl.Actions["Drop"]["Drop all"] = dropall + tbl.Actions["Drop"]["Drop X"] = dropx +end + + +if(SERVER) then + util.AddNetworkString( "gms_dropresources" ) +end +function genericDropResource(player, resource, ammount) + if(CLIENT) then + net.Start("gms_dropresources") + net.WriteString(resource) + net.WriteInt(ammount,GMS.NETINT_BITCOUNT) + 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)) + return + end + local res = player.Resources[resource] + + if ( ammount > res ) then + ammount = res + end + player:DropResource( resource, ammount ) + player:DecResource( resource, ammount ) + end +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/berry.lua b/gamemode/itemsystem/items/berry.lua index 125a78b..acf018d 100644 --- a/gamemode/itemsystem/items/berry.lua +++ b/gamemode/itemsystem/items/berry.lua @@ -15,7 +15,7 @@ local eat = function(ln, player) net.SendToServer() end if(SERVER) then - if(player.Resources[ITEM.Name] <= 0) 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 @@ -32,6 +32,6 @@ net.Receive( "gms_eatberry", eat) ITEM.Actions = {} genericMakeDroppable(ITEM) -ITEM.Actions["EatBerry"] = eat +ITEM.Actions["Eat Berry"] = eat GMS.RegisterResource(ITEM) diff --git a/gamemode/server/player_functions.lua b/gamemode/server/player_functions.lua index 646f851..b8afc32 100644 --- a/gamemode/server/player_functions.lua +++ b/gamemode/server/player_functions.lua @@ -656,18 +656,9 @@ end function PlayerMeta:CancelProcess() if ( !self.InProcess ) then return end - - local v = self.ProcessTable - if ( !v.Cancel ) then return end - - if ( v.Owner and v.Owner != NULL and IsValid( v.Owner ) ) then - v.Owner:Freeze( false ) - v.Owner:StopProcessBar() - v.Owner.InProcess = false - v.Owner:SendMessage( "Cancelled.", 3, Color( 200, 0, 0, 255 ) ) - end - - v.IsStopped = true - timer.Destroy( "GMS_ProcessTimer_" .. v.TimerID ) - GAMEMODE:RemoveProcessThink( v ) + timer.Destroy("process") + self:Freeze(false) + self.InProcess = false + self:SendMessage( "Cancelled.", 3, Color( 200, 0, 0, 255 ) ) + self:StopProcessBar() end -- cgit v1.2.3-70-g09d2 From 677682840305841d4538c6f5d5151f36959ae56f Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 30 Apr 2016 13:42:44 -0400 Subject: More work on makeing things plantable --- gamemode/itemsystem/common.lua | 12 +++++++++++- gamemode/itemsystem/common_dropable.lua | 5 +++++ gamemode/itemsystem/common_plantable.lua | 1 + gamemode/itemsystem/items/anexample.lua | 18 ++++++++++++++++++ gamemode/itemsystem/items/baits.lua | 2 +- gamemode/itemsystem/items/bananaseeds.lua | 1 + gamemode/itemsystem/items/grainseeds.lua | 1 + gamemode/itemsystem/items/melonseeds.lua | 1 + gamemode/itemsystem/items/orangeseeds.lua | 1 + 9 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 gamemode/itemsystem/common_plantable.lua (limited to 'gamemode/itemsystem') diff --git a/gamemode/itemsystem/common.lua b/gamemode/itemsystem/common.lua index 674c0ce..5a47c24 100644 --- a/gamemode/itemsystem/common.lua +++ b/gamemode/itemsystem/common.lua @@ -17,6 +17,16 @@ function startProcessGeneric(player, string, time, ondone) end) end -function genericMakePlantable( tbl ) +local function plant(player, planttype) + print("Plant method called!") +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 diff --git a/gamemode/itemsystem/common_dropable.lua b/gamemode/itemsystem/common_dropable.lua index 1f4ec7e..2b8446d 100644 --- a/gamemode/itemsystem/common_dropable.lua +++ b/gamemode/itemsystem/common_dropable.lua @@ -1,4 +1,5 @@ function genericMakeDroppable(tbl) + if(SERVER) then return end local drop1 = function(player) genericDropResource(player,tbl.Name,1) end @@ -7,6 +8,9 @@ function genericMakeDroppable(tbl) print("Ammount:" .. Resources[tbl.Name]) genericDropResource(player,tbl.Name,Resources[tbl.Name]) end + local drophalf = function(player) + genericDropResource(player,tbl.Name,math.ceil(Resources[tbl.Name]/2.0)) + end local dropx = function(player) if(SERVER) then return end local frame = vgui.Create( "DFrame" ) @@ -32,6 +36,7 @@ function genericMakeDroppable(tbl) tbl.Actions["Drop"] = {} end tbl.Actions["Drop"]["Drop 1"] = drop1 + tbl.Actions["Drop"]["Drop Half"] = drophalf tbl.Actions["Drop"]["Drop all"] = dropall tbl.Actions["Drop"]["Drop X"] = dropx end diff --git a/gamemode/itemsystem/common_plantable.lua b/gamemode/itemsystem/common_plantable.lua new file mode 100644 index 0000000..383d8d2 --- /dev/null +++ b/gamemode/itemsystem/common_plantable.lua @@ -0,0 +1 @@ +print("Hello from common_plantable.lua!") diff --git a/gamemode/itemsystem/items/anexample.lua b/gamemode/itemsystem/items/anexample.lua index 19cdbd7..100096f 100644 --- a/gamemode/itemsystem/items/anexample.lua +++ b/gamemode/itemsystem/items/anexample.lua @@ -14,5 +14,23 @@ ITEM.Icon = "test.png" --If this item has "unique data", for example batteries that run out of charge ITEM.UniqueData = false +--A table of strings to functions that show up when the player clicks the item in their inventory. +--The you may also use strings to tables of strings to functions (and so on) to make drop-down menus. +--Example: +--[[ +ITEM.Actions = { + "Click me!" = functions(player) print("I was clicked!") end + "Or me!" = functions(player) print("I was clicked by " .. player:Name()) end + "Drop down" = { + "This is an item in a drop down" = function(player) print("Drop1") end + "Drop downs can have more drop downs!" = { + "Drop2" = function(player) print("Drop2") end + "Drop3" = function(player) print("Drop3") end + } + } +} +--]] +ITEM.Actions = {} + --Be sure to register when everything is said and done! GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/baits.lua b/gamemode/itemsystem/items/baits.lua index f6824cd..47a6fbb 100644 --- a/gamemode/itemsystem/items/baits.lua +++ b/gamemode/itemsystem/items/baits.lua @@ -1,7 +1,7 @@ ITEM = {} ITEM.Name = "Baits" -ITEM.Description = "Something you can plant!" +ITEM.Description = "Something you can use to fish with! (Consumed automatically)" ITEM.Icon = "test.png" ITEM.UniqueData = false diff --git a/gamemode/itemsystem/items/bananaseeds.lua b/gamemode/itemsystem/items/bananaseeds.lua index 103bca9..72e14b0 100644 --- a/gamemode/itemsystem/items/bananaseeds.lua +++ b/gamemode/itemsystem/items/bananaseeds.lua @@ -5,6 +5,7 @@ ITEM.Description = "Something you can plant!" ITEM.Icon = "test.png" ITEM.UniqueData = false +genericMakePlantable(ITEM) genericMakeDroppable(ITEM) GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/grainseeds.lua b/gamemode/itemsystem/items/grainseeds.lua index be81e5f..9057df8 100644 --- a/gamemode/itemsystem/items/grainseeds.lua +++ b/gamemode/itemsystem/items/grainseeds.lua @@ -5,6 +5,7 @@ ITEM.Description = "Something you can plant, or mash up into flour" ITEM.Icon = "test.png" ITEM.UniqueData = false +genericMakePlantable(ITEM) genericMakeDroppable(ITEM) GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/melonseeds.lua b/gamemode/itemsystem/items/melonseeds.lua index 84d4f95..8ddaea5 100644 --- a/gamemode/itemsystem/items/melonseeds.lua +++ b/gamemode/itemsystem/items/melonseeds.lua @@ -6,5 +6,6 @@ ITEM.Icon = "test.png" ITEM.UniqueData = false genericMakeDroppable(ITEM) +genericMakePlantable(ITEM) GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/orangeseeds.lua b/gamemode/itemsystem/items/orangeseeds.lua index 39a2bec..01122c3 100644 --- a/gamemode/itemsystem/items/orangeseeds.lua +++ b/gamemode/itemsystem/items/orangeseeds.lua @@ -5,6 +5,7 @@ ITEM.Description = "Something you can plant!" ITEM.Icon = "test.png" ITEM.UniqueData = false +genericMakePlantable(ITEM) genericMakeDroppable(ITEM) GMS.RegisterResource(ITEM) -- cgit v1.2.3-70-g09d2 From 603b64b1a93b36f04d25018ec3f53b16dcd84019 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 30 Apr 2016 15:35:22 -0400 Subject: Fixed plant eating --- entities/entities/gms_food.lua | 4 +- entities/entities/gms_generic_plantable.lua | 122 ++++++++++++++++++++++++++++ gamemode/client/cl_inventory.lua | 1 + gamemode/configure_me.lua | 2 +- gamemode/itemsystem/common.lua | 69 +++++++++++++++- gamemode/itemsystem/common_dropable.lua | 2 - gamemode/itemsystem/items/bananaseeds.lua | 15 ++++ gamemode/itemsystem/items/berry.lua | 35 ++++---- gamemode/itemsystem/items/grainseeds.lua | 6 ++ gamemode/itemsystem/items/herbs.lua | 2 +- gamemode/itemsystem/items/melonseeds.lua | 13 +++ gamemode/itemsystem/items/orangeseeds.lua | 21 +++++ gamemode/itemsystem/items/sprout.lua | 1 + gamemode/processes.lua | 18 ++-- 14 files changed, 277 insertions(+), 34 deletions(-) create mode 100644 entities/entities/gms_generic_plantable.lua create mode 100644 gamemode/itemsystem/items/sprout.lua (limited to 'gamemode/itemsystem') 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"}, } -- cgit v1.2.3-70-g09d2 From adcec79b09baa5b6804795077caae8ad7e6c0394 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 30 Apr 2016 20:15:02 -0400 Subject: Added mineing resources --- gamemode/cl_init.lua | 1 + gamemode/configure_me.lua | 5 +++ gamemode/init.lua | 6 +++- gamemode/itemsystem/items/admantineore.lua | 10 ++++++ gamemode/itemsystem/items/copperore.lua | 10 ++++++ gamemode/itemsystem/items/goldore.lua | 10 ++++++ gamemode/itemsystem/items/ironore.lua | 10 ++++++ gamemode/itemsystem/items/mithirilore.lua | 10 ++++++ gamemode/itemsystem/items/platinumore.lua | 10 ++++++ gamemode/itemsystem/items/silverore.lua | 10 ++++++ gamemode/itemsystem/items/steelore.lua | 10 ++++++ gamemode/itemsystem/items/stone.lua | 10 ++++++ gamemode/itemsystem/items/strangestone.lua | 10 ++++++ gamemode/itemsystem/items/techore.lua | 10 ++++++ gamemode/processes.lua | 20 +++++------ gamemode/server/player_functions.lua | 14 ++++++-- gamemode/shared.lua | 6 +++- gamemode/shared/developer_cheats.lua | 56 ++++++++++++++++++++++++++++++ 18 files changed, 203 insertions(+), 15 deletions(-) create mode 100644 gamemode/itemsystem/items/admantineore.lua create mode 100644 gamemode/itemsystem/items/copperore.lua create mode 100644 gamemode/itemsystem/items/goldore.lua create mode 100644 gamemode/itemsystem/items/ironore.lua create mode 100644 gamemode/itemsystem/items/mithirilore.lua create mode 100644 gamemode/itemsystem/items/platinumore.lua create mode 100644 gamemode/itemsystem/items/silverore.lua create mode 100644 gamemode/itemsystem/items/steelore.lua create mode 100644 gamemode/itemsystem/items/stone.lua create mode 100644 gamemode/itemsystem/items/strangestone.lua create mode 100644 gamemode/itemsystem/items/techore.lua create mode 100644 gamemode/shared/developer_cheats.lua (limited to 'gamemode/itemsystem') diff --git a/gamemode/cl_init.lua b/gamemode/cl_init.lua index 776f894..6d496ac 100644 --- a/gamemode/cl_init.lua +++ b/gamemode/cl_init.lua @@ -3,6 +3,7 @@ include( "utility.lua") includeFolder("craftablesystem",true) includeFolder("itemsystem",true) includeFolder("client",true) +includeFolder("shared",true) include( "shared.lua" ) diff --git a/gamemode/configure_me.lua b/gamemode/configure_me.lua index 70d0f4b..6e26eb9 100644 --- a/gamemode/configure_me.lua +++ b/gamemode/configure_me.lua @@ -26,3 +26,8 @@ GMS.LootableNPCs = { "npc_pigeon", "npc_zombie" } + +//SteamID's of any developers, this list should be empty on production servers! +GMS.Developers = { + "STEAM_0:0:0" //the single-player steamid +} diff --git a/gamemode/init.lua b/gamemode/init.lua index a4c480a..5b1fa5a 100644 --- a/gamemode/init.lua +++ b/gamemode/init.lua @@ -4,10 +4,12 @@ include( "init_static.lua") AddCSLuaFolder("client",false) AddCSLuaFolder("craftablesystem",true) AddCSLuaFolder("itemsystem",true) +AddCSLuaFolder("shared",true) includeFolder("server",false) includeFolder("craftablesystem",true) includeFolder("itemsystem",true) +includeFolder("shared",true) AddCSLuaFile( "configure_me.lua" ) @@ -131,7 +133,7 @@ end -- Cancel process concommand.Add( "gms_cancelprocess", function( ply, cmd, args ) ply:CancelProcess() - + end ) @@ -937,6 +939,7 @@ concommand.Add( "gms_makefire", GM.MakeCampfire ) ---------------------------------------------------------------------------------------------------- */ function GM:PlayerInitialSpawn( ply ) + print("--------Inital spawn called!---------") ply:SetTeam( 1 ) ply.Skills = {} @@ -996,6 +999,7 @@ function GM:PlayerInitialSpawn( ply ) ply.FeatureUnlocks = tbl["unlocks"] ply.MaxResources = ( ply.Skills["Survival"] * 5 ) + 25 + print("Setting MaxResources to " .. ply.MaxResources) ply:SendMessage( "Loaded character successfully.", 3, Color( 255, 255, 255, 255 ) ) ply:SendMessage( "Last visited on " .. tbl.date .. ", enjoy your stay.", 10, Color( 255, 255, 255, 255 ) ) diff --git a/gamemode/itemsystem/items/admantineore.lua b/gamemode/itemsystem/items/admantineore.lua new file mode 100644 index 0000000..2b1ac16 --- /dev/null +++ b/gamemode/itemsystem/items/admantineore.lua @@ -0,0 +1,10 @@ +ITEM = {} + +ITEM.Name = "Adamantine Ore" +ITEM.Description = "Something you can craft with!" +ITEM.Icon = "test.png" +ITEM.UniqueData = false + +genericMakeDroppable(ITEM) + +GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/copperore.lua b/gamemode/itemsystem/items/copperore.lua new file mode 100644 index 0000000..c7e1fea --- /dev/null +++ b/gamemode/itemsystem/items/copperore.lua @@ -0,0 +1,10 @@ +ITEM = {} + +ITEM.Name = "Copper Ore" +ITEM.Description = "Something you can craft with!" +ITEM.Icon = "test.png" +ITEM.UniqueData = false + +genericMakeDroppable(ITEM) + +GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/goldore.lua b/gamemode/itemsystem/items/goldore.lua new file mode 100644 index 0000000..a5b1a53 --- /dev/null +++ b/gamemode/itemsystem/items/goldore.lua @@ -0,0 +1,10 @@ +ITEM = {} + +ITEM.Name = "Gold Ore" +ITEM.Description = "Something you can craft with!" +ITEM.Icon = "test.png" +ITEM.UniqueData = false + +genericMakeDroppable(ITEM) + +GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/ironore.lua b/gamemode/itemsystem/items/ironore.lua new file mode 100644 index 0000000..b94d9eb --- /dev/null +++ b/gamemode/itemsystem/items/ironore.lua @@ -0,0 +1,10 @@ +ITEM = {} + +ITEM.Name = "Iron Ore" +ITEM.Description = "Something you can craft with!" +ITEM.Icon = "test.png" +ITEM.UniqueData = false + +genericMakeDroppable(ITEM) + +GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/mithirilore.lua b/gamemode/itemsystem/items/mithirilore.lua new file mode 100644 index 0000000..da3dea8 --- /dev/null +++ b/gamemode/itemsystem/items/mithirilore.lua @@ -0,0 +1,10 @@ +ITEM = {} + +ITEM.Name = "Mithril Ore" +ITEM.Description = "Something you can craft with!" +ITEM.Icon = "test.png" +ITEM.UniqueData = false + +genericMakeDroppable(ITEM) + +GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/platinumore.lua b/gamemode/itemsystem/items/platinumore.lua new file mode 100644 index 0000000..b94d9eb --- /dev/null +++ b/gamemode/itemsystem/items/platinumore.lua @@ -0,0 +1,10 @@ +ITEM = {} + +ITEM.Name = "Iron Ore" +ITEM.Description = "Something you can craft with!" +ITEM.Icon = "test.png" +ITEM.UniqueData = false + +genericMakeDroppable(ITEM) + +GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/silverore.lua b/gamemode/itemsystem/items/silverore.lua new file mode 100644 index 0000000..b94d9eb --- /dev/null +++ b/gamemode/itemsystem/items/silverore.lua @@ -0,0 +1,10 @@ +ITEM = {} + +ITEM.Name = "Iron Ore" +ITEM.Description = "Something you can craft with!" +ITEM.Icon = "test.png" +ITEM.UniqueData = false + +genericMakeDroppable(ITEM) + +GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/steelore.lua b/gamemode/itemsystem/items/steelore.lua new file mode 100644 index 0000000..c245ade --- /dev/null +++ b/gamemode/itemsystem/items/steelore.lua @@ -0,0 +1,10 @@ +ITEM = {} + +ITEM.Name = "Steel Ore" +ITEM.Description = "Something you can craft with!" +ITEM.Icon = "test.png" +ITEM.UniqueData = false + +genericMakeDroppable(ITEM) + +GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/stone.lua b/gamemode/itemsystem/items/stone.lua new file mode 100644 index 0000000..d288d27 --- /dev/null +++ b/gamemode/itemsystem/items/stone.lua @@ -0,0 +1,10 @@ +ITEM = {} + +ITEM.Name = "Stone" +ITEM.Description = "Something you can craft with!" +ITEM.Icon = "test.png" +ITEM.UniqueData = false + +genericMakeDroppable(ITEM) + +GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/strangestone.lua b/gamemode/itemsystem/items/strangestone.lua new file mode 100644 index 0000000..9d684ce --- /dev/null +++ b/gamemode/itemsystem/items/strangestone.lua @@ -0,0 +1,10 @@ +ITEM = {} + +ITEM.Name = "Strange Stone" +ITEM.Description = "Something you can craft with!" +ITEM.Icon = "test.png" +ITEM.UniqueData = false + +genericMakeDroppable(ITEM) + +GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/techore.lua b/gamemode/itemsystem/items/techore.lua new file mode 100644 index 0000000..cc494e6 --- /dev/null +++ b/gamemode/itemsystem/items/techore.lua @@ -0,0 +1,10 @@ +ITEM = {} + +ITEM.Name = "Tech Ore" +ITEM.Description = "Something you can craft with!" +ITEM.Icon = "test.png" +ITEM.UniqueData = false + +genericMakeDroppable(ITEM) + +GMS.RegisterResource(ITEM) diff --git a/gamemode/processes.lua b/gamemode/processes.lua index 333f404..45e544d 100644 --- a/gamemode/processes.lua +++ b/gamemode/processes.lua @@ -615,34 +615,34 @@ function PROCESS:OnStop() self.Owner:IncResource( "Stone", num3 ) self.Owner:SendMessage( "Stone ( " .. num3 .. "x )", 3, Color( 10, 200, 10, 255 ) ) elseif ( num2 == 2 ) then - self.Owner:IncResource( "Copper_Ore", num3 ) + self.Owner:IncResource( "Copper Ore", num3 ) self.Owner:SendMessage( "Copper Ore ( "..num3 .. "x )", 3, Color( 10, 200, 10, 255 ) ) elseif ( num2 == 3 ) then - self.Owner:IncResource( "Iron_Ore", num3 ) + self.Owner:IncResource( "Iron Ore", num3 ) self.Owner:SendMessage( "Iron Ore ( " .. num3 .. "x )", 3, Color( 10, 200, 10, 255 ) ) elseif ( num2 == 4 ) then - self.Owner:IncResource( "Tech_Ore", num3 ) + self.Owner:IncResource( "Tech Ore", num3 ) self.Owner:SendMessage( "Tech Ore ( " .. num3 .. "x )", 3, Color( 10, 200, 10, 255 ) ) elseif ( num2 == 5 ) then - self.Owner:IncResource( "Silver_Ore", num3 ) + self.Owner:IncResource( "Silver Ore", num3 ) self.Owner:SendMessage( "Silver Ore ( " .. num3 .. "x )", 3, Color( 10, 200, 10, 255 ) ) elseif ( num2 == 6 ) then - self.Owner:IncResource( "Gold_Ore", num3 ) + self.Owner:IncResource( "Gold Ore", num3 ) self.Owner:SendMessage( "Gold Ore ( " .. num3 .. "x )", 3, Color( 10, 200, 10, 255 ) ) elseif ( num2 == 7 ) then - self.Owner:IncResource( "Steel_Ore", num3 ) + self.Owner:IncResource( "Steel Ore", num3 ) self.Owner:SendMessage( "Steel Ore ( " .. num3 .. "x )", 3, Color( 10, 200, 10, 255 ) ) elseif ( num2 == 8 ) then - self.Owner:IncResource( "Platinum_Ore", num3 ) + self.Owner:IncResource( "Platinum Ore", num3 ) self.Owner:SendMessage( "Platinum Ore ( " .. num3 .. "x )", 3, Color( 10, 200, 10, 255 ) ) elseif ( num2 == 85 ) then - self.Owner:IncResource( "Strange_Stone", num3 ) + self.Owner:IncResource( "Strange Stone", num3 ) self.Owner:SendMessage( "Strange Stone ( " .. num3 .. "x ) ", 3, Color( 0, 247, 255, 255) ) elseif ( num2 == 9 ) then - self.Owner:IncResource( "Mithril_Ore", num3 ) + self.Owner:IncResource( "Mithril Ore", num3 ) self.Owner:SendMessage( "Mithril Ore ( " .. num3 .. "x ) ", 3, Color(10, 200, 10, 255) ) elseif ( num2 == 10) then - self.Owner:IncResource( "Adamantine_Ore", num3 ) + self.Owner:IncResource( "Adamantine Ore", num3 ) self.Owner:SendMessage( "Adamantine Ore( " .. num3 .. "x ) ", 3, Color(255,0, 111, 255) ) end diff --git a/gamemode/server/player_functions.lua b/gamemode/server/player_functions.lua index b8afc32..09de491 100644 --- a/gamemode/server/player_functions.lua +++ b/gamemode/server/player_functions.lua @@ -150,9 +150,9 @@ function PlayerMeta:SetResource( resource, int ) PrintTable(resource) print(int) - if ( !self.Resources[resource] ) then self.Resources[resource] = 0 end + --if ( !self.Resources[resource] ) then self.Resources[resource] = 0 end - self.Resources[resource] = int + --self.Resources[resource] = int if(net.Start("gms_SetResource",false)) then net.WriteString(resource.Name) @@ -186,6 +186,10 @@ function PlayerMeta:IncResource( resource, int ) if ( !self.Resources[resource] ) then self.Resources[resource] = 0 end local all = self:GetAllResources() local max = self.MaxResources + print("When adding resources, max resource is:") + print(max) + print("All is:") + print(all) if ( all + int > max ) then self.Resources[resource] = self.Resources[resource] + ( max - all ) @@ -196,6 +200,8 @@ function PlayerMeta:IncResource( resource, int ) end self:SetResource(resource, self:GetResource( resource )) + print("Now all is:") + print(self:GetAllResources()) end function PlayerMeta:DecResource( resource, int ) @@ -215,12 +221,14 @@ function PlayerMeta:DecResource( resource, int ) end function PlayerMeta:GetAllResources() + print("Totaling data in:") + PrintTable(self.Resources) local num = 0 for k, v in pairs( self.Resources ) do num = num + v end - + print("Total was " .. num) return num end diff --git a/gamemode/shared.lua b/gamemode/shared.lua index 2cc0234..5588e1f 100644 --- a/gamemode/shared.lua +++ b/gamemode/shared.lua @@ -93,7 +93,11 @@ end local PlayerMeta = FindMetaTable( "Player" ) function PlayerMeta:IsDeveloper() - if ( self:SteamID() == "STEAM_0:0:18313012" ) then return true end + for k,v in pairs(GMS.Developers) do + if(self:SteamID() == v) then + return true + end + end return false end diff --git a/gamemode/shared/developer_cheats.lua b/gamemode/shared/developer_cheats.lua new file mode 100644 index 0000000..e8c4fbb --- /dev/null +++ b/gamemode/shared/developer_cheats.lua @@ -0,0 +1,56 @@ +--This file contains things to help developers debug while working on the code. All this stuff relies on the Developers table in configre_me.lua + +local pmeta = FindMetaTable( "Player" ) + +function pmeta:IsDeveloper() + for k,v in pairs(GMS.Developers) do + if(self:SteamID() == v) then + return true + end + end + return false +end + +-----------------Print inventory--------------------- +local printServerResources = function(ply,cmd,args) + if(CLIENT or (!ply:IsDeveloper())) then return end + PrintTable(ply.Resources) +end + +local printServerResourcesAuto = function(cmd,args) end + +concommand.Add("gms_sv_printSvRes",printServerResources,printServerResourcesAuto,"Prints the server representation of your resources") + +local printClientResources = function(ply,cmd,args) + if(SERVER or (!ply:IsDeveloper())) then return end + PrintTable(Resources) +end + +local printClientResourcesAuto = function(cmd,args) end + +concommand.Add("gms_sv_printClRes",printClientResources,printClientResourcesAuto,"Prints the client representation of your resources") + +------------------Give weapons---------------------- +local giveWeapon = function(ply,cmd,args) + if(!ply:IsDeveloper()) then return end + if(weapons.Get(args[1]) == nil) then + print("Could not find weapon:" .. args[1]) + return + end + ply:Give(args[1]) +end + +local giveWeaponAuto = function(cmd,args) + local possibles = {} + local needle = string.Trim(args) + print("\"" .. needle .. "\"") + for k,v in pairs(weapons.GetList()) do + local fplace = string.find(v.ClassName,needle) + if(fplace != nil) then + table.insert(possibles,cmd .. " " .. v.ClassName) + end + end + return possibles +end + +concommand.Add("gms_sv_givewep",giveWeapon,giveWeaponAuto) -- cgit v1.2.3-70-g09d2 From c6b56a911622f9a52fd92293074192d1f13d3e96 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 30 Apr 2016 20:25:34 -0400 Subject: Added water bottle --- gamemode/itemsystem/items/platinumore.lua | 2 +- gamemode/itemsystem/items/silverore.lua | 2 +- gamemode/itemsystem/items/waterbottle.lua | 37 +++++++++++++++++++++++++++++++ gamemode/processes.lua | 4 ++-- 4 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 gamemode/itemsystem/items/waterbottle.lua (limited to 'gamemode/itemsystem') diff --git a/gamemode/itemsystem/items/platinumore.lua b/gamemode/itemsystem/items/platinumore.lua index b94d9eb..14b3f62 100644 --- a/gamemode/itemsystem/items/platinumore.lua +++ b/gamemode/itemsystem/items/platinumore.lua @@ -1,6 +1,6 @@ ITEM = {} -ITEM.Name = "Iron Ore" +ITEM.Name = "Platinum Ore" ITEM.Description = "Something you can craft with!" ITEM.Icon = "test.png" ITEM.UniqueData = false diff --git a/gamemode/itemsystem/items/silverore.lua b/gamemode/itemsystem/items/silverore.lua index b94d9eb..f0b0505 100644 --- a/gamemode/itemsystem/items/silverore.lua +++ b/gamemode/itemsystem/items/silverore.lua @@ -1,6 +1,6 @@ ITEM = {} -ITEM.Name = "Iron Ore" +ITEM.Name = "Silver Ore" ITEM.Description = "Something you can craft with!" ITEM.Icon = "test.png" ITEM.UniqueData = false diff --git a/gamemode/itemsystem/items/waterbottle.lua b/gamemode/itemsystem/items/waterbottle.lua new file mode 100644 index 0000000..df43749 --- /dev/null +++ b/gamemode/itemsystem/items/waterbottle.lua @@ -0,0 +1,37 @@ +ITEM = {} + +ITEM.Name = "Water Bottle" +ITEM.Description = "A delicious edible!" +ITEM.Icon = "test.png" +ITEM.UniqueData = false + +if(SERVER) then + util.AddNetworkString( "gms_drinkwaterbottle" ) +end + +local eat_client = function(ln, player) + net.Start("gms_drinkwaterbottle") + net.SendToServer() +end + +local finisheddrink = function() + player:DecResource( "Water Bottle", 1 ) + player:SendMessage( "You're a little less hungry and thirsty now.", 3, Color( 10, 200, 10, 255 ) ) + --Set thirst + player:SetThirst(math.Clamp(player.Thirst+100,0,1000)) +end + +local drink = function(ln, player) + if(player.Resources["Water Bottle"] <= 0) then + player:SendMessage( "You don't have enough to do that!", 3, Color( 10, 200, 10, 255 ) ) + return + end + startProcessGeneric(player,"Drinking some water",1,finisheddrink) +end +net.Receive( "gms_drinkwaterbottle", drink) + +ITEM.Actions = {} +genericMakeDroppable(ITEM) +ITEM.Actions["Drink Water"] = drink_client + +GMS.RegisterResource(ITEM) diff --git a/gamemode/processes.lua b/gamemode/processes.lua index 45e544d..58a2b48 100644 --- a/gamemode/processes.lua +++ b/gamemode/processes.lua @@ -844,11 +844,11 @@ end function PROCESS:OnStop() if (self.Owner:GetActiveWeapon():GetClass() == "gms_bucket") then - self.Owner:IncResource( "Water_Bottles", 10 ) + self.Owner:IncResource( "Water Bottles", 10 ) self.Owner:SendMessage( "Water Bottle ( 10x )", 3, Color( 10, 200, 10, 255 ) ) self.Owner:EmitSound( Sound( "ambient/water/water_spray" .. math.random( 1, 3 ) .. ".wav" ) ) else - self.Owner:IncResource( "Water_Bottles", 1 ) + self.Owner:IncResource( "Water Bottles", 1 ) self.Owner:SendMessage( "Water Bottle ( 1x )", 3, Color( 10, 200, 10, 255 ) ) self.Owner:EmitSound( Sound( "ambient/water/water_spray" .. math.random( 1, 3 ) .. ".wav" ) ) end -- cgit v1.2.3-70-g09d2