diff options
Diffstat (limited to 'gamemode/itemsystem')
| -rw-r--r-- | gamemode/itemsystem/common.lua | 46 | ||||
| -rw-r--r-- | gamemode/itemsystem/items/anexample.lua | 18 | ||||
| -rw-r--r-- | gamemode/itemsystem/items/baits.lua | 26 | ||||
| -rw-r--r-- | gamemode/itemsystem/items/bananaseeds.lua | 26 | ||||
| -rw-r--r-- | gamemode/itemsystem/items/berry.lua | 49 | ||||
| -rw-r--r-- | gamemode/itemsystem/items/grainseeds.lua | 26 | ||||
| -rw-r--r-- | gamemode/itemsystem/items/herbs.lua | 26 | ||||
| -rw-r--r-- | gamemode/itemsystem/items/melonseeds.lua | 26 | ||||
| -rw-r--r-- | gamemode/itemsystem/items/orangeseeds.lua | 26 | ||||
| -rw-r--r-- | gamemode/itemsystem/loaditems.lua | 29 |
10 files changed, 293 insertions, 5 deletions
diff --git a/gamemode/itemsystem/common.lua b/gamemode/itemsystem/common.lua new file mode 100644 index 0000000..f7d6c72 --- /dev/null +++ b/gamemode/itemsystem/common.lua @@ -0,0 +1,46 @@ +--This file holds a bunch of common functions that happen in items. They're seperated out here so that they're easy to change if there's a bug somewhere. + +--Freezes the player, creates the loading bar, and calls ondone when the timer is up. +function startProcessGeneric(player, string, time, ondone) + if(player.InProcess) then + self.Owner:SendMessage("You can't do that much at once!", 3, Color(255, 255, 255, 255)) + return + end + player.InProcess = true + player:Freeze(true) + player:MakeProcessBar( string, time, false ) + timer.Create( "process", time, 1, function() + player:Freeze(false) + player.InProcess = false + player:StopProcessBar() + ondone() + end) +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 = ply:GetResource( Type ) + + if ( ammount > res ) then + ammount = res + end + ply:DropResource( Type, int ) + ply:DecResource( Type, int ) + end +end +net.Receive( "gms_dropresources", function(len,pl) + genericDropResource(pl,net.ReadString(),net.ReadInt(GMS.NETINT_BITCOUNT)) +end) diff --git a/gamemode/itemsystem/items/anexample.lua b/gamemode/itemsystem/items/anexample.lua new file mode 100644 index 0000000..19cdbd7 --- /dev/null +++ b/gamemode/itemsystem/items/anexample.lua @@ -0,0 +1,18 @@ +--This file is to help developers add new items to the game + +ITEM = {} + +--The name of this item +ITEM.Name = "An Example" + +--A description that shows up when hovering over the item in the inventory +ITEM.Description = "Why did I even write this? No one will ever read it!" + +--The icon that this item users, relative to the gmsurvival/content/materials directory +ITEM.Icon = "test.png" + +--If this item has "unique data", for example batteries that run out of charge +ITEM.UniqueData = false + +--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 new file mode 100644 index 0000000..47bf1d0 --- /dev/null +++ b/gamemode/itemsystem/items/baits.lua @@ -0,0 +1,26 @@ +ITEM = {} + +ITEM.Name = "Baits" +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 + +GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/bananaseeds.lua b/gamemode/itemsystem/items/bananaseeds.lua new file mode 100644 index 0000000..358ed63 --- /dev/null +++ b/gamemode/itemsystem/items/bananaseeds.lua @@ -0,0 +1,26 @@ +ITEM = {} + +ITEM.Name = "Banana Seeds" +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 + +GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/berry.lua b/gamemode/itemsystem/items/berry.lua index 610147f..2021ffd 100644 --- a/gamemode/itemsystem/items/berry.lua +++ b/gamemode/itemsystem/items/berry.lua @@ -1,6 +1,53 @@ ITEM = {} -ITEM.Name = "Berry" +ITEM.Name = "Berries" ITEM.Description = "A delicious edible!" +ITEM.Icon = "test.png" +ITEM.UniqueData = false + +if(SERVER) then + util.AddNetworkString( "gms_eatberry" ) +end + +local eat = function(ln, player) + if(CLIENT) then + net.Start("gms_eatberry") + net.SendToServer() + end + if(SERVER) then + if(player.Resources[ITEM.Name] <= 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) + end +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 = {} +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 new file mode 100644 index 0000000..9b22a0b --- /dev/null +++ b/gamemode/itemsystem/items/grainseeds.lua @@ -0,0 +1,26 @@ +ITEM = {} + +ITEM.Name = "Grain Seeds" +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 + +GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/herbs.lua b/gamemode/itemsystem/items/herbs.lua new file mode 100644 index 0000000..9db5417 --- /dev/null +++ b/gamemode/itemsystem/items/herbs.lua @@ -0,0 +1,26 @@ +ITEM = {} + +ITEM.Name = "Herbs" +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 + +GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/melonseeds.lua b/gamemode/itemsystem/items/melonseeds.lua new file mode 100644 index 0000000..874ac46 --- /dev/null +++ b/gamemode/itemsystem/items/melonseeds.lua @@ -0,0 +1,26 @@ +ITEM = {} + +ITEM.Name = "Melon Seeds" +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 + +GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/items/orangeseeds.lua b/gamemode/itemsystem/items/orangeseeds.lua new file mode 100644 index 0000000..33fd698 --- /dev/null +++ b/gamemode/itemsystem/items/orangeseeds.lua @@ -0,0 +1,26 @@ +ITEM = {} + +ITEM.Name = "Orange Seeds" +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 + +GMS.RegisterResource(ITEM) diff --git a/gamemode/itemsystem/loaditems.lua b/gamemode/itemsystem/loaditems.lua index 8f8313b..a77ffb3 100644 --- a/gamemode/itemsystem/loaditems.lua +++ b/gamemode/itemsystem/loaditems.lua @@ -1,14 +1,35 @@ +//Loads Loads all the items in the gamemode, these should go into gamemode/itemsystem/itmes folder. +//Also adds a console command gms_printrestable, that prints all the (base) resource tables and their values. +//Keep in mind that if an item has UniqueData set to true, it's instance may be different than that shown in gms_printrestable + GMS.Resources = {} + function GMS.RegisterResource( tbl ) - local sname = string.Replace(tbl.Name, " ", "_") - print("Registering " .. sname) - GMS.Resources[sname] = tbl + if(tbl == nil) then + print("/gamemode/itemsystem/loaditems.lua: Attempted to register a nil entity! This might be a bug!") + return + end + if(tbl.Name == nil) then + print("/gamemode/itemsystem/loaditems.lua: Attempted to register an item with no name:") + PrintTable(tbl) + print("This might be a bug!") + return + end + if(tbl.UniqueData) then + tbl.UniqueDataID = -1 + end + print("Registering item:" .. tbl.Name) + GMS.Resources[tbl.Name] = tbl end -function GMS.GetItemByName(name) +function GMS.GetResourceByName(name) if(GMS.Resources[name]) then return GMS.Resources[name] else print("Resource " .. name .. " does not exist! This might be a bug!") end end + +concommand.Add("gms_printrestable",function(ply,cmd,args) + PrintTable(GMS.Resources) +end) |
