1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
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
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]
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)
assert(tbl.Recipes != nil and tbl.Recipes[recipenum] != nil, "Invalid recpie!")
local recipe = tbl.Recipes[recipenum]
local numrequired = 1
for k, v in pairs( recipe.Req ) do
numrequired = numrequired + v
end
local time = math.pow(numrequired,tbl.timemult) - ((numrequired * tbl.timemult) * math.pow(ply:GetSkill("Smelting"),tbl.skillease))
time = time * numrequired / 5
for k,v in pairs(recipe.Req) do
if ply:GetResource(k) < 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, time, function(player)
for k,v in pairs(recipe.Results) do
player:IncResource(k,v)
end
for k,v in pairs(recipe.Req) do
ply:DecResource(k,v)
end
end)
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
|