diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2016-05-25 22:06:26 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2016-05-25 22:06:26 -0400 |
| commit | 4adec24c3a2a53f518d817ae8a6ddd0c4c47422c (patch) | |
| tree | adb91a867dfda05f5c2880e19d0111fb657ecb9f /gamemode/structuresystem/common_smelt.lua | |
| parent | 699df0d5df4e7d00a0d2b838b8c851c9b5027cea (diff) | |
| download | gmstranded-4adec24c3a2a53f518d817ae8a6ddd0c4c47422c.tar.gz gmstranded-4adec24c3a2a53f518d817ae8a6ddd0c4c47422c.tar.bz2 gmstranded-4adec24c3a2a53f518d817ae8a6ddd0c4c47422c.zip | |
more work on the structure system
Diffstat (limited to 'gamemode/structuresystem/common_smelt.lua')
| -rw-r--r-- | gamemode/structuresystem/common_smelt.lua | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/gamemode/structuresystem/common_smelt.lua b/gamemode/structuresystem/common_smelt.lua new file mode 100644 index 0000000..bb34331 --- /dev/null +++ b/gamemode/structuresystem/common_smelt.lua @@ -0,0 +1,83 @@ + +if SERVER then + util.AddNetworkString( "makerecipe" ) +end +function genericMakeFurnace(tbl) + local oldusefunc = tbl.onUse + local overrideuse = function(self, ply) + if SERVER or ply != LocalPlayer() then return end + print("I am the local player!") + local DermaPanel = vgui.Create( "DFrame" ) + DermaPanel:SetPos( 100, 100 ) + 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(128) + Grid:SetRowHeight(128) + for k,v in pairs(tbl.Recipes) do + local testbut = vgui.Create("DButton") + testbut:SetText(v.Name) + testbut:SetSize(128,128) + testbut.DoClick = function(button) + net.Start("makerecipe") + net.WriteString(tbl.Name) + if(tbl.uniquedata) then net.WriteUInt(self:EntIndex(), GMS.NETINT_BITCOUNT) end + net.WriteUInt(k, GMS.NETINT_BITCOUNT) + net.SendToServer() + end + Grid:AddItem(testbut) + DermaPanel:MakePopup() + end + oldusefunc(self,ply) + end + tbl.onUse = overrideuse +end +net.Receive( "makerecipe", function(ln,ply) + local tblname = net.ReadString() + local tbl = GMS.Structures[tblname] + print("Table is:") + PrintTable(tbl) + print("Recipes table is:") + PrintTable(tbl.Recipes) + assert(tbl != nil,"Maybe someone's trying to hack lol") + if tbl.uniquedata then + local entnum = net.ReadUInt(GMS.NETINT_BITCOUNT) + tbl = GMS.UniqueStructures[entnum] + end + local recipenum = net.ReadUInt(GMS.NETINT_BITCOUNT) + print("Useing recipes:") + PrintTable(tbl.Recipes) + print("And recipenum:") + PrintTable(tbl.Recipes[recipenum]) + assert(tbl.Recipes != nil and tbl.Recipes[recipenum] != nil, "Invalid recpie!") + print("Attempting to craft recpie:") + PrintTable(tbl.Recipes[recipenum]) + local recipe = tbl.Recipes[recipenum] + local numrequired = 1 + for k, v in pairs( recipe.Req ) do + numrequired = numrequired + v + print("numrequired is now:" .. numrequired) + end + local time = math.pow(numrequired,tbl.timemult) - ((numrequired * tbl.timemult) * math.pow(ply:GetSkill("Smelting"),tbl.skillease)) + time = time * numrequired / 5 + --time = math.max( time - math.floor( ply:GetSkill( "Smelting" ) / 5 ), math.max( timecount * tbl.skillease, 2 ) ) + + print("I think smelting this should take " .. time .. " seconds") + +end) + +function recipieForSmelt(tbl, name, description, required, result, ratio, mults) + for k,v in pairs(mults) do + local thisrecipie = {} + thisrecipie.Name = name .. " x" .. v + thisrecipie.Description = description + thisrecipie.Req = {} + thisrecipie.Req[required] = ratio[1] * v + thisrecipie.Results = {} + thisrecipie.Results[result] = ratio[2] * v + table.insert(tbl,0,thisrecipie) + end +end |
