summaryrefslogtreecommitdiff
path: root/gamemode/structuresystem/common_smelt.lua
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2016-05-27 20:24:40 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2016-05-27 20:24:40 -0400
commit427b41c5683d9c913bd7b66d540d8a882a33ebf6 (patch)
tree8c91e778b2ad6385964573964674fb3aa97a9594 /gamemode/structuresystem/common_smelt.lua
parent9ea65b0c6a2b53766e5aa66cb6d86644a70da21f (diff)
downloadgmstranded-427b41c5683d9c913bd7b66d540d8a882a33ebf6.tar.gz
gmstranded-427b41c5683d9c913bd7b66d540d8a882a33ebf6.tar.bz2
gmstranded-427b41c5683d9c913bd7b66d540d8a882a33ebf6.zip
Refactored where the structure code was
Diffstat (limited to 'gamemode/structuresystem/common_smelt.lua')
-rw-r--r--gamemode/structuresystem/common_smelt.lua173
1 files changed, 0 insertions, 173 deletions
diff --git a/gamemode/structuresystem/common_smelt.lua b/gamemode/structuresystem/common_smelt.lua
deleted file mode 100644
index 68a50b1..0000000
--- a/gamemode/structuresystem/common_smelt.lua
+++ /dev/null
@@ -1,173 +0,0 @@
-
-if SERVER then
- util.AddNetworkString( "makerecipe" )
-end
-function genericMakeFurnace(tbl)
- local oldusefunc = tbl.onUse
- local overrideuse = function(self, ply)
- oldusefunc(self,ply)
- if SERVER or ply != LocalPlayer() then return end
-
- PrintTable(tbl.genericRecipes)
-
- tbl.Recipes = {}
- for k,v in pairs(tbl.genericRecipes) do
- local ratio = v.Ratio
- local mults = {1,5,10,20,50}
- for i,j in pairs(mults) do
- local thisrecipe = {}
- thisrecipe.Req = {}
- thisrecipe.Results = {}
- for l,m in pairs(v.Requirements) do
- thisrecipe.Req[l] = ratio[1] * j * m
- end
- for l,m in pairs(v.Results) do
- thisrecipe.Results[l] = ratio[2] * j * m
- end
- print("This recipe is :")
- PrintTable(thisrecipe)
- thisrecipe.Name = v.Name .. " x" .. j
- thisrecipe.Description = v.Description
- thisrecipe.genericNum = k
- thisrecipe.mult = j
- table.insert(tbl.Recipes,0,thisrecipe)
- end
- end
-
- print("Recipes are:")
- PrintTable(tbl.Recipes)
-
- local DermaPanel = vgui.Create( "DFrame" )
- DermaPanel:SetPos( 100, 100 )
- local buts = 128
- DermaPanel:SetSize( ScrW() / 1.3, ScrH() / 1.4 )
- DermaPanel:SetTitle( tbl.Name )
- DermaPanel:SetDraggable( true )
- DermaPanel:Center()
- local Grid = vgui.Create("DGrid",DermaPanel)
- Grid:SetPos(10,30)
- Grid:SetColWide(buts)
- Grid:SetRowHeight(buts)
- DermaPanel.info = vgui.Create("DPanel",DermaPanel)
- DermaPanel.info:SetPos(10,(buts * 2) + 30)
- DermaPanel.info:SetSize(ScrW() / 1.3 - 20, buts * 0.75)
- DermaPanel.infotext = vgui.Create("DLabel",DermaPanel.info)
- DermaPanel.infotext:SetText("")
- DermaPanel.infotext:SetPos(10,10)
- DermaPanel.infotext:SetDark(true)
- DermaPanel.infotext:SetFont( "ScoreboardSub" )
- DermaPanel.infotext:Dock(TOP)
- DermaPanel.reqtext = vgui.Create("DLabel",DermaPanel.info)
- DermaPanel.reqtext:SetPos(10,30)
- DermaPanel.reqtext:SetDark(true)
- DermaPanel.reqtext:Dock(FILL)
- for k,v in pairs(tbl.Recipes) do
- local testbut = vgui.Create("DButton")
- testbut:SetText(v.Name)
- testbut:SetSize(buts,buts)
- testbut.DoClick = function(button)
- print("Recipe is:")
- PrintTable(v)
- DermaPanel.structname = tbl.Name
- DermaPanel.recipeNum = v.genericNum
- DermaPanel.recipeMult = v.mult
- local text = v.Description .. "\nRequires:"
- for i,j in pairs(v.Req) do
- text = text .. "\n" .. i .. "x" .. j
- end
- DermaPanel.infotext:SetText(v.Name)
- DermaPanel.reqtext:SetText(text)
- local cancraft = true
- for i,j in pairs(v.Req) do
- if Resources[i] < j then
- print("Can't craft becaues " .. i .. "(" .. Resources[i] .. ") is less than " .. j)
- cancraft = false
- end
- end
- DermaPanel.makebutton:SetEnabled(cancraft)
- end
- Grid:AddItem(testbut)
- DermaPanel:MakePopup()
- end
- DermaPanel.makebutton = vgui.Create("DButton",DermaPanel)
- DermaPanel.makebutton:SetPos(10,(buts * 2) + (buts * 0.75) + 30)
- DermaPanel.makebutton:SetSize(ScrW() / 1.3 - 20, (buts / 4))
- DermaPanel.makebutton:SetText("Craft")
- DermaPanel.makebutton.DoClick = function()
- net.Start("makerecipe")
- net.WriteString(DermaPanel.structname)
- if tbl.uniquedata then net.WriteUInt(self:EntIndex(), GMS.NETINT_BITCOUNT) end
- net.WriteUInt(DermaPanel.recipeNum, GMS.NETINT_BITCOUNT)
- net.WriteUInt(DermaPanel.recipeMult, GMS.NETINT_BITCOUNT)
- net.SendToServer()
- end
-
- end
- tbl.onUse = overrideuse
-end
-net.Receive( "makerecipe", function(ln,ply)
- local tblname = net.ReadString()
- local tbl = GMS.Structures[tblname]
- assert(tbl != nil,"Tried to make a recipe in a structure that dosen't exist!")
- if tbl.uniquedata then
- local entnum = net.ReadUInt(GMS.NETINT_BITCOUNT)
- tbl = GMS.UniqueStructures[entnum]
- end
- local recipenum = net.ReadUInt(GMS.NETINT_BITCOUNT)
- local mult = net.ReadUInt(GMS.NETINT_BITCOUNT)
- print("Attempting to craft:")
- print("Table name:" .. tblname)
- print("Recipenum:" .. recipenum)
- print("Multiplier:" .. mult)
- print("This recipe is:")
- print("Table is:")
- PrintTable(tbl)
- local recipe = tbl.genericRecipes[recipenum]
- print("Recipe:")
- PrintTable(recipe)
-
- --Check that we have enough ingredients
- for k,v in pairs(recipe.Requirements) do
- if ply:GetResource(k * mult) < v then
- ply:SendMessage("You don't have enough!", 3, Color(255, 255, 255, 255))
- return
- end
- end
-
- --We have enough resources! make it!
- startProcessGeneric(ply,"Crafting " .. recipe.Name, recipe.Time(ply,mult), function(player)
- for k,v in pairs(recipe.Results) do
- player:IncResource(k * mult,v)
- end
- for k,v in pairs(recipe.Requirements) do
- ply:DecResource(k * mult,v)
- end
- end)
-
-end)
-
-function genericGiveRecipie(tbl, recipe)
- tbl.genericRecipes = tbl.genericRecipes or {}
- table.insert(tbl.genericRecipes, recipe)
-end
-
-function recipieForSmelt(tbl, name, description, required, result, ratio, mults)
- local recipie = {}
- recipie.Req = {}
- recipie.Req[required] = ratio[1]
- recipie.Results = {}
- recipie.Results[result] = ratio[2]
- local num = table.insert(tbl.GenericRecipe,0,recipe)
- for k,v in pairs(mults) do
- if v == 0 then continue end
- local thisrecipie = {}
- thisrecipie.Name = name .. " x" .. math.floor(v)
- thisrecipie.Description = description
- thisrecipie.Req = {}
- thisrecipie.Req[required] = math.floor(ratio[1] * v)
- thisrecipie.Results = {}
- thisrecipie.Results[result] = math.floor(ratio[2] * v)
- thisrecipie.GenericRecipe = num
- table.insert(tbl.Recipes,0,thisrecipie)
- end
-end