local buts = 90 local recipeWidth = buts*4 local recipeHeight = buts*1.5 local function makeCraftingWindow(name) local pw = 735 local ph = 500 local DermaPanel = vgui.Create( "DFrame" ) DermaPanel:SetPos( 100, 100 ) DermaPanel:SetSize( pw, ph ) DermaPanel:SetTitle( name ) DermaPanel:SetDraggable( true ) DermaPanel:Center() DermaPanel.Paint = function(self,w,h) draw.RoundedBox( 0, 0, 0, w, h, Color(86,86,86,200) ) end DermaPanel.scroll = vgui.Create( "DScrollPanel", DermaPanel ) DermaPanel.scroll:Dock(FILL) DermaPanel.scroll:SetPos( 0, 25 ) DermaPanel.Grid = vgui.Create("DGrid",DermaPanel.scroll) DermaPanel.Grid:SetPos(0,0) DermaPanel.Grid:SetColWide(recipeWidth+5) DermaPanel.Grid:SetCols(pw / recipeWidth) DermaPanel.Grid:SetRowHeight(recipeHeight+5) /*DermaPanel.info = vgui.Create("DPanel",DermaPanel) DermaPanel.info:SetPos(10,(buts * 2) + 30) DermaPanel.info:SetSize(pw - 20, buts * 0.75) DermaPanel.info:Dock(BOTTOM) 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) 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:SetEnabled(false) 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 */ return DermaPanel end if SERVER then util.AddNetworkString( "makerecipe" ) end function genericMakeCrafting(tbl) local oldusefunc = tbl.onUse local overrideuse = function(self, ply) oldusefunc(self,ply) if SERVER or ply != LocalPlayer() then return end tbl.Recipes = {} for k,v in pairs(tbl.genericRecipes) do local ratio = v.Ratio local mults = v.Mults 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 thisrecipe.Name = v.Name .. " x" .. j thisrecipe.Description = v.Description thisrecipe.genericNum = k thisrecipe.Image = v.Image thisrecipe.haslevelsfor = v.CanCraft(ply) thisrecipe.hasmatsfor = true PrintTable(thisrecipe.Req) for l,m in pairs(thisrecipe.Req) do if(Resources[l] == nil or Resources[l] < m) then thisrecipe.hasmatsfor = false break end end thisrecipe.mult = j table.insert(tbl.Recipes,0,thisrecipe) end end local DermaPanel = makeCraftingWindow(tbl.Name) local infoPosX = 130 local infoPosY = 20 for k,v in pairs(tbl.Recipes) do local recipeButton = vgui.Create("DButton") local text = v.Description .. "\nRequires:" for i,j in pairs(v.Req) do text = text .. "\n" .. i .. " x" .. j end recipeButton.text = text recipeButton:SetText("") recipeButton:SetSize(recipeWidth,recipeHeight) recipeButton.Paint = function() //draw.RoundedBox( 8, 5, 5, w-10, h-10, Color( 0, 0, 0 ) ) local fillcolor = Color(255,255,255) if v.haslevelsfor then if v.hasmatsfor then fillcolor = Color(23,180,23) else fillcolor = Color(200,0,0) end else fillcolor = Color(200,200,0) end draw.RoundedBox(0,0,0,recipeWidth,recipeHeight,Color(48,48,48,255)) draw.RoundedBox(0,15,15,110,recipeHeight-30,fillcolor) draw.RoundedBox(8,20,20,100,recipeHeight-40,Color(98,98,98)) //draw.RoundedBox(0,125,20,w-110,h-40,fillcolor) draw.DrawText( text, "TargetID", infoPosX, infoPosY, Color( 255, 255, 255, 255 ) ) end recipeButton.DoClick = function(button) DermaPanel.structname = tbl.Name DermaPanel.recipeNum = v.genericNum DermaPanel.recipeMult = v.mult 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 local img = vgui.Create("DImage", recipeButton) img:SetPos(24, 20) img:SetSize(buts, buts) img:SetImage(v.Image) DermaPanel.Grid:AddItem(recipeButton) 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) local recipe = tbl.genericRecipes[recipenum] --Check that we have enough ingredients for k,v in pairs(recipe.Requirements) do if ply:GetResource(k) < v then ply:SendMessage("You don't have enough!", 3, Color(255, 255, 255, 255)) return end end --Check that we're allowed to craft this if not recipe.CanCraft(ply) then ply:SendMessage("You can't craft that!", 3, Color(255, 255, 255, 255)) return 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) end for k,v in pairs(recipe.Requirements) do ply:DecResource(k,mult) end end) end) function genericGiveRecipie(tbl, recipe) tbl.genericRecipes = tbl.genericRecipes or {} table.insert(tbl.genericRecipes, recipe) end