From 94cc3813c462df5f7bfd875d5a817b0da42006e6 Mon Sep 17 00:00:00 2001 From: Apickx Date: Wed, 12 Feb 2025 16:41:17 -0600 Subject: Final commit --- .../artery/global/art_sawhorse/cl_ent_sawhorse.lua | 118 +++---- .../artery/global/art_sawhorse/sh_ent_sawhorse.lua | 106 +++--- .../artery/global/art_sawhorse/sv_ent_sawhorse.lua | 172 ++++----- .../art_shipyardcontrol/cl_ent_shipyardcontrol.lua | 128 +++---- .../art_shipyardcontrol/sh_ent_shipyardcontrol.lua | 26 +- .../art_shipyardcontrol/sv_ent_shipyardcontrol.lua | 110 +++--- .../global/art_workbench/cl_ent_workbench.lua | 126 +++---- .../global/art_workbench/sh_ent_workbench.lua | 74 ++-- .../global/art_workbench/sv_ent_workbench.lua | 222 ++++++------ data/artery/global/cl_crafting_inv.lua | 6 +- data/artery/global/sh_chopwood.txt | 13 + data/artery/global/sh_crafting_inv.lua | 386 ++++++++++----------- data/artery/global/sh_minerock.txt | 59 ++-- data/artery/global/sh_shipyard.txt | 126 +++---- data/artery/global/sv_config.txt | 20 +- data/artery/global/sv_dupboat.lua | 76 ++-- 16 files changed, 892 insertions(+), 876 deletions(-) (limited to 'data/artery') diff --git a/data/artery/global/art_sawhorse/cl_ent_sawhorse.lua b/data/artery/global/art_sawhorse/cl_ent_sawhorse.lua index 2cbe16a..f80784d 100644 --- a/data/artery/global/art_sawhorse/cl_ent_sawhorse.lua +++ b/data/artery/global/art_sawhorse/cl_ent_sawhorse.lua @@ -1,59 +1,59 @@ ---[[ - Client stuff! -]] -local ENT = nrequire("sh_ent_sawhorse.lua") - -function ENT:Draw() - - self.Entity:DrawModel() - -end - -net.Receive("art_sawhorse_open",function() - local who = net.ReadEntity() - print("Opening sawhorse") - local selectframe = vgui.Create("DFrame") - selectframe:SetSize(ScrW()/2, ScrH()/2) - selectframe:Center() - selectframe:SetTitle("Sawhorse") - - local scroll = vgui.Create( "DScrollPanel",selectframe ) - scroll:Dock(FILL) - - local grid = vgui.Create( "DGrid", scroll ) - grid:SetPos( 10, 30 ) - grid:SetCols( 2 ) - grid:SetColWide( 200 ) - grid:SetRowHeight(100) - grid:Dock(FILL) - - print("s.props is",ENT.props) - PrintTable(ENT.props) - - for k,v in pairs(ENT.props) do - local p = vgui.Create("DPanel") - p:SetSize(200,100) - --p:Dock(FILL) - local but = vgui.Create("DModelPanel",p) - but:SetModel(v.model) - but:SetSize(100,100) - but:Dock(LEFT) - but.DoClick = function(self) - net.Start("art_sawhorse_select") - net.WriteString(k) - net.WriteEntity(who) - net.SendToServer() - print("I want to make a ", k) - end - local label = vgui.Create("DLabel",p) - label:SetSize(100,100) - label:Dock(RIGHT) - label:SetText(string.format("%s\nCost:%d wood",k,v.cost)) - label:SetDark(true) - grid:AddItem(p) - end - - selectframe:MakePopup() -end) - -scripted_ents.Register(ENT,"art_sawhorse") +--[[ + Client stuff! +]] +local ENT = nrequire("sh_ent_sawhorse.lua") + +function ENT:Draw() + + self.Entity:DrawModel() + +end + +net.Receive("art_sawhorse_open",function() + local who = net.ReadEntity() + print("Opening sawhorse") + local selectframe = vgui.Create("DFrame") + selectframe:SetSize(ScrW()/2, ScrH()/2) + selectframe:Center() + selectframe:SetTitle("Sawhorse") + + local scroll = vgui.Create( "DScrollPanel",selectframe ) + scroll:Dock(FILL) + + local grid = vgui.Create( "DGrid", scroll ) + grid:SetPos( 10, 30 ) + grid:SetCols( 2 ) + grid:SetColWide( 200 ) + grid:SetRowHeight(100) + grid:Dock(FILL) + + print("s.props is",ENT.props) + PrintTable(ENT.props) + + for k,v in pairs(ENT.props) do + local p = vgui.Create("DPanel") + p:SetSize(200,100) + --p:Dock(FILL) + local but = vgui.Create("DModelPanel",p) + but:SetModel(v.model) + but:SetSize(100,100) + but:Dock(LEFT) + but.DoClick = function(self) + net.Start("art_sawhorse_select") + net.WriteString(k) + net.WriteEntity(who) + net.SendToServer() + print("I want to make a ", k) + end + local label = vgui.Create("DLabel",p) + label:SetSize(100,100) + label:Dock(RIGHT) + label:SetText(string.format("%s\nCost:%d wood",k,v.cost)) + label:SetDark(true) + grid:AddItem(p) + end + + selectframe:MakePopup() +end) + +scripted_ents.Register(ENT,"art_sawhorse") diff --git a/data/artery/global/art_sawhorse/sh_ent_sawhorse.lua b/data/artery/global/art_sawhorse/sh_ent_sawhorse.lua index bf0e640..49ede91 100644 --- a/data/artery/global/art_sawhorse/sh_ent_sawhorse.lua +++ b/data/artery/global/art_sawhorse/sh_ent_sawhorse.lua @@ -1,53 +1,53 @@ - -local ENT = {} - -ENT.Type = "anim" -ENT.Base = "art_chest" -ENT.PrintName = "art_sawhorse" -ENT.Author = "Apickx" - -ENT.Spawnable = false -ENT.AdminSpawnable = false - -local skil = nrequire("sh_skillcommon.lua") -skil.RegisterSkill({"Crafting","Carpentry"}) - -ENT.props = { - ["A short board"] = { - model = "models/props_debris/wood_board06a.mdl", - cost = 1 - }, - ["A longer board"] = { - model = "models/props_debris/wood_board07a.mdl", - cost = 2, - }, - ["A pallet"] = { - model = "models/props_junk/wood_pallet001a.mdl", - cost = 2 - }, - ["A large flat peice of wood"] = { - model = "models/props_wasteland/wood_fence01a.mdl", - cost = 3 - }, - ["A small flat peice of wood"] = { - model = "models/props_wasteland/wood_fence02a.mdl", - cost = 2 - }, - ["A very strong, boyent fence"] = { - model = "models/props_c17/FurnitureShelf001a.mdl", - cost = 2 - }, - ["A round table"] = { - model = "models/props_c17/FurnitureTable001a.mdl", - cost = 1 - }, - ["A rectangle table"] = { - model = "models/props_c17/FurnitureTable002a.mdl", - cost = 1 - }, - ["A tall pole"] = { - model = "models/props_docks/dock01_pole01a_128.mdl", - cost = 2 - } -} -return ENT + +local ENT = {} + +ENT.Type = "anim" +ENT.Base = "art_chest" +ENT.PrintName = "art_sawhorse" +ENT.Author = "Apickx" + +ENT.Spawnable = false +ENT.AdminSpawnable = false + +local skil = nrequire("sh_skillcommon.lua") +skil.RegisterSkill({"Crafting","Carpentry"}) + +ENT.props = { + ["A short board"] = { + model = "models/props_debris/wood_board06a.mdl", + cost = 1 + }, + ["A longer board"] = { + model = "models/props_debris/wood_board07a.mdl", + cost = 2, + }, + ["A pallet"] = { + model = "models/props_junk/wood_pallet001a.mdl", + cost = 2 + }, + ["A large flat peice of wood"] = { + model = "models/props_wasteland/wood_fence01a.mdl", + cost = 3 + }, + ["A small flat peice of wood"] = { + model = "models/props_wasteland/wood_fence02a.mdl", + cost = 2 + }, + ["A very strong, boyent fence"] = { + model = "models/props_c17/FurnitureShelf001a.mdl", + cost = 2 + }, + ["A round table"] = { + model = "models/props_c17/FurnitureTable001a.mdl", + cost = 1 + }, + ["A rectangle table"] = { + model = "models/props_c17/FurnitureTable002a.mdl", + cost = 1 + }, + ["A tall pole"] = { + model = "models/props_docks/dock01_pole01a_128.mdl", + cost = 2 + } +} +return ENT diff --git a/data/artery/global/art_sawhorse/sv_ent_sawhorse.lua b/data/artery/global/art_sawhorse/sv_ent_sawhorse.lua index 393aaed..100864a 100644 --- a/data/artery/global/art_sawhorse/sv_ent_sawhorse.lua +++ b/data/artery/global/art_sawhorse/sv_ent_sawhorse.lua @@ -1,86 +1,86 @@ ---[[ - This entity gives townies things to do -]] - -local ENT = nrequire("sh_ent_sawhorse.lua") - -DEFINE_BASECLASS("art_chest") -- this defined a local variable called BaseClass - -AddCSLuaFile( "cl_init.lua" ) -AddCSLuaFile( "shared.lua" ) - -print("Hello from art_sawhorse init.lua!") - -local s = include("shared.lua") -local inv = nrequire("core/inventory/inventory.lua") -local itm = nrequire("core/inventory/item.lua") - -function ENT:Initialize( ) - self.InvType = "Crafting Inventory" - BaseClass.Initialize(self) - timer.Simple(0.1,function() - self.data.inventories[self:GetCreationID()].accepts = { - ["Wood"] = true, - } - end) - self.Entity:SetModel("models/props/cs_militia/sawhorse.mdl") - self.Entity:PhysicsInit( SOLID_VPHYSICS ) - self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) - self.Entity:SetSolid( SOLID_VPHYSICS ) - self.Entity:Activate() - local phys = self.Entity:GetPhysicsObject() - if (phys:IsValid()) then - phys:Wake() - phys:SetMass(100) - end - self.selfPos = self.Entity - self:SetUseType(SIMPLE_USE) -end - - -util.AddNetworkString("art_sawhorse_open") -util.AddNetworkString("art_sawhorse_select") -util.AddNetworkString("art_sawhorse_puzzle") -util.AddNetworkString("art_sawhorse_put") -util.AddNetworkString("art_sawhorse_close") - -function ENT:Use(a,c,u,v) - net.Start("art_sawhorse_open") - net.WriteEntity(self) - net.Send(c) - BaseClass.Use(self,a,c,u,v) -end - -net.Receive("art_sawhorse_select",function(ln,ply) - local name = net.ReadString() - local who = net.ReadEntity() - print("props are:") - PrintTable(ENT.props) - assert(ENT.props[name],"Player " .. ply:Nick() .. " tried to make a prop we don't have:" .. name) - local cost = ENT.props[name].cost - print("player wanted to make a ",name,cost) - local num = 0 - local myinv = who.data.inventories[who:GetCreationID()] - local cursor = myinv:Has("Wood") - local titm = nil - while cursor ~= nil and num < cost do - titm = myinv:Remove(cursor) - num = num + 1 - cursor = myinv:Has("Wood") - end - if num == cost then - local e = ents.Create("prop_physics") - e:SetPos(who:GetPos() + Vector(0,0,100)) - e:SetModel(ENT.props[name].model) - e:Spawn() - ply:AddSkill("Carpentry",cost) - else - --Put stuff back in if we didn't have enough! - for i = 1,num do - local pos = myinv:FindPlaceFor(titm) - myinv:Put(pos,titm) - end - end -end) - -scripted_ents.Register(ENT,"art_sawhorse") +--[[ + This entity gives townies things to do +]] + +local ENT = nrequire("sh_ent_sawhorse.lua") + +DEFINE_BASECLASS("art_chest") -- this defined a local variable called BaseClass + +AddCSLuaFile( "cl_init.lua" ) +AddCSLuaFile( "shared.lua" ) + +print("Hello from art_sawhorse init.lua!") + +local s = include("shared.lua") +local inv = nrequire("core/inventory/inventory.lua") +local itm = nrequire("core/inventory/item.lua") + +function ENT:Initialize( ) + self.InvType = "Crafting Inventory" + BaseClass.Initialize(self) + timer.Simple(0.1,function() + self.data.inventories[self:GetCreationID()].accepts = { + ["Wood"] = true, + } + end) + self.Entity:SetModel("models/props/cs_militia/sawhorse.mdl") + self.Entity:PhysicsInit( SOLID_VPHYSICS ) + self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) + self.Entity:SetSolid( SOLID_VPHYSICS ) + self.Entity:Activate() + local phys = self.Entity:GetPhysicsObject() + if (phys:IsValid()) then + phys:Wake() + phys:SetMass(100) + end + self.selfPos = self.Entity + self:SetUseType(SIMPLE_USE) +end + + +util.AddNetworkString("art_sawhorse_open") +util.AddNetworkString("art_sawhorse_select") +util.AddNetworkString("art_sawhorse_puzzle") +util.AddNetworkString("art_sawhorse_put") +util.AddNetworkString("art_sawhorse_close") + +function ENT:Use(a,c,u,v) + net.Start("art_sawhorse_open") + net.WriteEntity(self) + net.Send(c) + BaseClass.Use(self,a,c,u,v) +end + +net.Receive("art_sawhorse_select",function(ln,ply) + local name = net.ReadString() + local who = net.ReadEntity() + print("props are:") + PrintTable(ENT.props) + assert(ENT.props[name],"Player " .. ply:Nick() .. " tried to make a prop we don't have:" .. name) + local cost = ENT.props[name].cost + print("player wanted to make a ",name,cost) + local num = 0 + local myinv = who.data.inventories[who:GetCreationID()] + local cursor = myinv:Has("Wood") + local titm = nil + while cursor ~= nil and num < cost do + titm = myinv:Remove(cursor) + num = num + 1 + cursor = myinv:Has("Wood") + end + if num == cost then + local e = ents.Create("prop_physics") + e:SetPos(who:GetPos() + Vector(0,0,100)) + e:SetModel(ENT.props[name].model) + e:Spawn() + ply:AddSkill("Carpentry",cost) + else + --Put stuff back in if we didn't have enough! + for i = 1,num do + local pos = myinv:FindPlaceFor(titm) + myinv:Put(pos,titm) + end + end +end) + +scripted_ents.Register(ENT,"art_sawhorse") diff --git a/data/artery/global/art_shipyardcontrol/cl_ent_shipyardcontrol.lua b/data/artery/global/art_shipyardcontrol/cl_ent_shipyardcontrol.lua index c9be7a6..a382132 100644 --- a/data/artery/global/art_shipyardcontrol/cl_ent_shipyardcontrol.lua +++ b/data/artery/global/art_shipyardcontrol/cl_ent_shipyardcontrol.lua @@ -1,64 +1,64 @@ ---[[ - Client stuff! -]] -local ENT = nrequire("sh_ent_shipyardcontrol.lua") - -function ENT:Draw() - self:DrawModel() - -end - -net.Receive("art_shipyard_open",function() - local who = net.ReadEntity() - print("Opening shipyard") - local selectframe = vgui.Create("DFrame") - selectframe:SetSize(ScrW() / 2, ScrH() / 2) - selectframe:Center() - selectframe:SetTitle("Shipyard") - - local scroll = vgui.Create( "DScrollPanel",selectframe ) - scroll:Dock(FILL) - - local labelname = vgui.Create("DLabel",scroll) - labelname:Dock(TOP) - labelname:SetText("Ship name:") - labelname:SetDark(true) - - local textname = vgui.Create("DTextEntry",scroll) - textname:Dock(TOP) - - local buttonfinish = vgui.Create( "DButton", scroll ) - buttonfinish:SetText("Finish") - buttonfinish:Dock(TOP) - buttonfinish.DoClick = function() - net.Start("art_shipyard_finalize") - net.WriteEntity(who) - net.WriteString(textname:GetValue()) - net.SendToServer() - end - - selectframe:MakePopup() -end) - ---[[ - Display the bounds of shipyards -]] - -hook.Add( "PostDrawOpaqueRenderables", "artery_draw_shipyards", function() - local ztd = zones.FindByClass("artery_shipyard") - for k,v in pairs(ztd) do - local bounds = v.bounds - cam.Start3D2D( bounds.mins, Angle(0,0,0), 1 ) - local x,y = bounds.maxs.x - bounds.mins.x, -(bounds.maxs.y - bounds.mins.y) - surface.SetDrawColor( 238, 238, 255, 50 ) - surface.DrawRect( 0, 0, x, y ) - surface.SetDrawColor( 100,100,255,255) - surface.DrawLine(0,0,x,0) - surface.DrawLine(0,0,0,y) - surface.DrawLine(x,y,x,0) - surface.DrawLine(x,y,0,y) - cam.End3D2D() - end -end ) - -scripted_ents.Register(ENT,"art_shipyardcontrol") +--[[ + Client stuff! +]] +local ENT = nrequire("sh_ent_shipyardcontrol.lua") + +function ENT:Draw() + self:DrawModel() + +end + +net.Receive("art_shipyard_open",function() + local who = net.ReadEntity() + print("Opening shipyard") + local selectframe = vgui.Create("DFrame") + selectframe:SetSize(ScrW() / 2, ScrH() / 2) + selectframe:Center() + selectframe:SetTitle("Shipyard") + + local scroll = vgui.Create( "DScrollPanel",selectframe ) + scroll:Dock(FILL) + + local labelname = vgui.Create("DLabel",scroll) + labelname:Dock(TOP) + labelname:SetText("Ship name:") + labelname:SetDark(true) + + local textname = vgui.Create("DTextEntry",scroll) + textname:Dock(TOP) + + local buttonfinish = vgui.Create( "DButton", scroll ) + buttonfinish:SetText("Finish") + buttonfinish:Dock(TOP) + buttonfinish.DoClick = function() + net.Start("art_shipyard_finalize") + net.WriteEntity(who) + net.WriteString(textname:GetValue()) + net.SendToServer() + end + + selectframe:MakePopup() +end) + +--[[ + Display the bounds of shipyards +]] + +hook.Add( "PostDrawOpaqueRenderables", "artery_draw_shipyards", function() + local ztd = zones.FindByClass("artery_shipyard") + for k,v in pairs(ztd) do + local bounds = v.bounds + cam.Start3D2D( bounds.mins, Angle(0,0,0), 1 ) + local x,y = bounds.maxs.x - bounds.mins.x, -(bounds.maxs.y - bounds.mins.y) + surface.SetDrawColor( 238, 238, 255, 50 ) + surface.DrawRect( 0, 0, x, y ) + surface.SetDrawColor( 100,100,255,255) + surface.DrawLine(0,0,x,0) + surface.DrawLine(0,0,0,y) + surface.DrawLine(x,y,x,0) + surface.DrawLine(x,y,0,y) + cam.End3D2D() + end +end ) + +scripted_ents.Register(ENT,"art_shipyardcontrol") diff --git a/data/artery/global/art_shipyardcontrol/sh_ent_shipyardcontrol.lua b/data/artery/global/art_shipyardcontrol/sh_ent_shipyardcontrol.lua index bb0026b..acf87a4 100644 --- a/data/artery/global/art_shipyardcontrol/sh_ent_shipyardcontrol.lua +++ b/data/artery/global/art_shipyardcontrol/sh_ent_shipyardcontrol.lua @@ -1,13 +1,13 @@ - - -local ENT = {} - -ENT.Type = "anim" -ENT.Base = "art_chest" -ENT.PrintName = "art_shipyardcontrol" -ENT.Author = "Apickx" - -ENT.Spawnable = false -ENT.AdminSpawnable = false - -return ENT + + +local ENT = {} + +ENT.Type = "anim" +ENT.Base = "art_chest" +ENT.PrintName = "art_shipyardcontrol" +ENT.Author = "Apickx" + +ENT.Spawnable = false +ENT.AdminSpawnable = false + +return ENT diff --git a/data/artery/global/art_shipyardcontrol/sv_ent_shipyardcontrol.lua b/data/artery/global/art_shipyardcontrol/sv_ent_shipyardcontrol.lua index ed1eed0..3a2ac4f 100644 --- a/data/artery/global/art_shipyardcontrol/sv_ent_shipyardcontrol.lua +++ b/data/artery/global/art_shipyardcontrol/sv_ent_shipyardcontrol.lua @@ -1,55 +1,55 @@ ---[[ - This entity gives townies things to do -]] -if not nrequire then return end - -AddCSLuaFile( "cl_init.lua" ) -AddCSLuaFile( "shared.lua" ) - -print("Hello from art_shipyardcontrol init.lua!") - -local ENT = nrequire("sh_ent_shipyardcontrol.lua") - -function ENT:Initialize( ) - self.Entity:SetModel("models/props/cs_militia/sawhorse.mdl") - self.Entity:PhysicsInit( SOLID_VPHYSICS ) - self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) - self.Entity:SetSolid( SOLID_VPHYSICS ) - self.Entity:Activate() - local phys = self.Entity:GetPhysicsObject() - if (phys:IsValid()) then - phys:Wake() - phys:SetMass(100) - end - self.selfPos = self.Entity - self:SetUseType(SIMPLE_USE) -end - - -util.AddNetworkString("art_shipyard_open") -util.AddNetworkString("art_shipyard_finalize") -util.AddNetworkString("art_shipyard_close") - -function ENT:Use(a,c,u,v) - net.Start("art_shipyard_open") - net.WriteEntity(self) - net.Send(c) -end - -net.Receive("art_shipyard_finalize",function(ln,ply) - print("Finalizing ship...") - local area = net.ReadEntity() - local name = net.ReadString() - print("Name will be", name) - print(area,area.Zone) - local zone = zones.List[area.Zone] - local bounds = zone.bounds - local allents = ents.FindInBox(bounds.mins,bounds.maxs) - duplicator.SetLocalPos( ply:GetPos()) - local boat = duplicator.Copy(allents[1]) - duplicator.SetLocalPos(Vector(0,0,0)) - print("Got boat") - PrintTable(boat) -end) - -scripted_ents.Register(ENT,"art_shipyardcontrol") +--[[ + This entity gives townies things to do +]] +if not nrequire then return end + +AddCSLuaFile( "cl_init.lua" ) +AddCSLuaFile( "shared.lua" ) + +print("Hello from art_shipyardcontrol init.lua!") + +local ENT = nrequire("sh_ent_shipyardcontrol.lua") + +function ENT:Initialize( ) + self.Entity:SetModel("models/props/cs_militia/sawhorse.mdl") + self.Entity:PhysicsInit( SOLID_VPHYSICS ) + self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) + self.Entity:SetSolid( SOLID_VPHYSICS ) + self.Entity:Activate() + local phys = self.Entity:GetPhysicsObject() + if (phys:IsValid()) then + phys:Wake() + phys:SetMass(100) + end + self.selfPos = self.Entity + self:SetUseType(SIMPLE_USE) +end + + +util.AddNetworkString("art_shipyard_open") +util.AddNetworkString("art_shipyard_finalize") +util.AddNetworkString("art_shipyard_close") + +function ENT:Use(a,c,u,v) + net.Start("art_shipyard_open") + net.WriteEntity(self) + net.Send(c) +end + +net.Receive("art_shipyard_finalize",function(ln,ply) + print("Finalizing ship...") + local area = net.ReadEntity() + local name = net.ReadString() + print("Name will be", name) + print(area,area.Zone) + local zone = zones.List[area.Zone] + local bounds = zone.bounds + local allents = ents.FindInBox(bounds.mins,bounds.maxs) + duplicator.SetLocalPos( ply:GetPos()) + local boat = duplicator.Copy(allents[1]) + duplicator.SetLocalPos(Vector(0,0,0)) + print("Got boat") + PrintTable(boat) +end) + +scripted_ents.Register(ENT,"art_shipyardcontrol") diff --git a/data/artery/global/art_workbench/cl_ent_workbench.lua b/data/artery/global/art_workbench/cl_ent_workbench.lua index 8f4b722..7f30178 100644 --- a/data/artery/global/art_workbench/cl_ent_workbench.lua +++ b/data/artery/global/art_workbench/cl_ent_workbench.lua @@ -1,63 +1,63 @@ ---[[ - Client stuff! -]] -local ENT = nrequire("sh_ent_workbench.lua") - -function ENT:Draw() - - self.Entity:DrawModel() - -end - -net.Receive("art_workbench_open",function() - local who = net.ReadEntity() - print("Opening sawhorse") - local selectframe = vgui.Create("DFrame") - selectframe:SetSize(ScrW()/2, ScrH()/2) - selectframe:Center() - selectframe:SetTitle("Sawhorse") - - local scroll = vgui.Create( "DScrollPanel",selectframe ) - scroll:Dock(FILL) - - local grid = vgui.Create( "DGrid", scroll ) - grid:SetPos( 10, 30 ) - grid:SetCols( 2 ) - grid:SetColWide( 200 ) - grid:SetRowHeight(100) - grid:Dock(FILL) - - print("s.props is",ENT.props) - PrintTable(ENT.props) - - for k,v in pairs(ENT.props) do - local p = vgui.Create("DPanel") - p:SetSize(200,100) - --p:Dock(FILL) - local but = vgui.Create("DModelPanel",p) - but:SetModel(v.model) - but:SetSize(100,100) - but:Dock(LEFT) - but.DoClick = function(self) - net.Start("art_workbench_select") - net.WriteString(k) - net.WriteEntity(who) - net.SendToServer() - print("I want to make a ", k) - end - local label = vgui.Create("DLabel",p) - label:SetSize(100,100) - label:Dock(RIGHT) - local costtbl = {} - for k,v in pairs(v.reqs) do - costtbl[#costtbl+1] = string.format("%10s : %5d", k, v) - end - label:SetText(string.format("%s\nCost:\n%s",k,table.concat(costtbl,"\n"))) - label:SetDark(true) - grid:AddItem(p) - end - - selectframe:MakePopup() -end) - -scripted_ents.Register(ENT,"art_workbench") +--[[ + Client stuff! +]] +local ENT = nrequire("sh_ent_workbench.lua") + +function ENT:Draw() + + self.Entity:DrawModel() + +end + +net.Receive("art_workbench_open",function() + local who = net.ReadEntity() + print("Opening sawhorse") + local selectframe = vgui.Create("DFrame") + selectframe:SetSize(ScrW()/2, ScrH()/2) + selectframe:Center() + selectframe:SetTitle("Sawhorse") + + local scroll = vgui.Create( "DScrollPanel",selectframe ) + scroll:Dock(FILL) + + local grid = vgui.Create( "DGrid", scroll ) + grid:SetPos( 10, 30 ) + grid:SetCols( 2 ) + grid:SetColWide( 200 ) + grid:SetRowHeight(100) + grid:Dock(FILL) + + print("s.props is",ENT.props) + PrintTable(ENT.props) + + for k,v in pairs(ENT.props) do + local p = vgui.Create("DPanel") + p:SetSize(200,100) + --p:Dock(FILL) + local but = vgui.Create("DModelPanel",p) + but:SetModel(v.model) + but:SetSize(100,100) + but:Dock(LEFT) + but.DoClick = function(self) + net.Start("art_workbench_select") + net.WriteString(k) + net.WriteEntity(who) + net.SendToServer() + print("I want to make a ", k) + end + local label = vgui.Create("DLabel",p) + label:SetSize(100,100) + label:Dock(RIGHT) + local costtbl = {} + for k,v in pairs(v.reqs) do + costtbl[#costtbl+1] = string.format("%10s : %5d", k, v) + end + label:SetText(string.format("%s\nCost:\n%s",k,table.concat(costtbl,"\n"))) + label:SetDark(true) + grid:AddItem(p) + end + + selectframe:MakePopup() +end) + +scripted_ents.Register(ENT,"art_workbench") diff --git a/data/artery/global/art_workbench/sh_ent_workbench.lua b/data/artery/global/art_workbench/sh_ent_workbench.lua index 4900d3e..7468a32 100644 --- a/data/artery/global/art_workbench/sh_ent_workbench.lua +++ b/data/artery/global/art_workbench/sh_ent_workbench.lua @@ -1,37 +1,37 @@ -if not nrequire then return end - -local ENT = {} - -ENT.Type = "anim" -ENT.Base = "art_chest" -ENT.PrintName = "art_sawhorse" -ENT.Author = "Apickx" - -ENT.Spawnable = false -ENT.AdminSpawnable = false - -local skil = nrequire("sh_skillcommon.lua") -skil.RegisterSkill({"Crafting","Toolbuilding"}) - -ENT.props = { - ["Hammer"] = { - model = "models/weapons/w_hammer.mdl", - reqs = { - ["Wood"] = 2, - ["Iron"] = 1 - } - }, - ["Nail"] = { - model = "models/crossbow_bolt.mdl", - reqs = { - ["Copper"] = 1 - } - }, - ["Paddle"] = { - model = "models/weapons/w_hammer.mdl", - reqs = { - ["Wood"] = 4 - } - } -} -return ENT +if not nrequire then return end + +local ENT = {} + +ENT.Type = "anim" +ENT.Base = "art_chest" +ENT.PrintName = "art_sawhorse" +ENT.Author = "Apickx" + +ENT.Spawnable = false +ENT.AdminSpawnable = false + +local skil = nrequire("sh_skillcommon.lua") +skil.RegisterSkill({"Crafting","Toolbuilding"}) + +ENT.props = { + ["Hammer"] = { + model = "models/weapons/w_hammer.mdl", + reqs = { + ["Wood"] = 2, + ["Iron"] = 1 + } + }, + ["Nail"] = { + model = "models/crossbow_bolt.mdl", + reqs = { + ["Copper"] = 1 + } + }, + ["Paddle"] = { + model = "models/weapons/w_hammer.mdl", + reqs = { + ["Wood"] = 4 + } + } +} +return ENT diff --git a/data/artery/global/art_workbench/sv_ent_workbench.lua b/data/artery/global/art_workbench/sv_ent_workbench.lua index 9ce7e0f..75d00a3 100644 --- a/data/artery/global/art_workbench/sv_ent_workbench.lua +++ b/data/artery/global/art_workbench/sv_ent_workbench.lua @@ -1,111 +1,111 @@ ---[[ - This entity gives townies things to do -]] -if not nrequire then return end - -DEFINE_BASECLASS("art_chest") -- this defined a local variable called BaseClass - -AddCSLuaFile( "cl_init.lua" ) -AddCSLuaFile( "shared.lua" ) - -print("Hello from art_workbench init.lua!") - -local ENT = nrequire("sh_ent_workbench.lua") -local inv = nrequire("core/inventory/inventory.lua") -local itm = nrequire("core/inventory/item.lua") - -function ENT:Initialize( ) - self.InvType = "Crafting Inventory" - BaseClass.Initialize(self) - timer.Simple(0.1,function() - self.data.inventories[self:GetCreationID()].accepts = { - ["Wood"] = true, - ["Copper"] = true, - ["Iron"] = true - } - end) - self.Entity:SetModel("models/props/cs_militia/sawhorse.mdl") - self.Entity:PhysicsInit( SOLID_VPHYSICS ) - self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) - self.Entity:SetSolid( SOLID_VPHYSICS ) - self.Entity:Activate() - local phys = self.Entity:GetPhysicsObject() - if (phys:IsValid()) then - phys:Wake() - phys:SetMass(100) - end - self.selfPos = self.Entity - self:SetUseType(SIMPLE_USE) -end - - -util.AddNetworkString("art_workbench_open") -util.AddNetworkString("art_workbench_select") -util.AddNetworkString("art_workbench_puzzle") -util.AddNetworkString("art_workbench_put") -util.AddNetworkString("art_workbench_close") - -function ENT:Use(a,c,u,v) - net.Start("art_workbench_open") - net.WriteEntity(self) - net.Send(c) - BaseClass.Use(self,a,c,u,v) -end - -function ENT:NumOf(name) - local myinv = self.data.inventories[self:GetCreationID()] - local cursor = myinv:Has(name) - local titm = nil - local num = 0 - while cursor ~= nil do - titm = myinv:Remove(cursor) - num = num + 1 - cursor = myinv:Has(name) - end - --Put stuff back in - for i = 1,num do - if titm ~= nil then - local pos = myinv:FindPlaceFor(titm) - myinv:Put(pos,titm) - end - end - - return num -end - -net.Receive("art_workbench_select",function(ln,ply) - local name = net.ReadString() - local who = net.ReadEntity() - print("props are:") - PrintTable(s.props) - assert(s.props[name],"Player " .. ply:Nick() .. " tried to make a prop we don't have:" .. name) - local reqs = s.props[name].reqs - print("player wanted to make a ",name,reqs) - PrintTable(reqs) - local canmake = true - for k,v in pairs(reqs) do - if who:NumOf(k) < v then - canmake = false - break - end - end - - local myinv = who.data.inventories[who:GetCreationID()] - if canmake then - print("Player can make, giveing") - xpcall(function() - ply:GiveItem(itm.GetItemByName(name)) - ply:AddSkill("Toolbuilding",#reqs) - for k,v in pairs(reqs) do - for i = 1,v do - local cur = myinv:Has(k) - myinv:Remove(cur) - end - end - end,function(err) - Msg("Failed to insert:" .. err) - end) - end -end) - -scripted_ents.Register(ENT,"art_workbench") +--[[ + This entity gives townies things to do +]] +if not nrequire then return end + +DEFINE_BASECLASS("art_chest") -- this defined a local variable called BaseClass + +AddCSLuaFile( "cl_init.lua" ) +AddCSLuaFile( "shared.lua" ) + +print("Hello from art_workbench init.lua!") + +local ENT = nrequire("sh_ent_workbench.lua") +local inv = nrequire("core/inventory/inventory.lua") +local itm = nrequire("core/inventory/item.lua") + +function ENT:Initialize( ) + self.InvType = "Crafting Inventory" + BaseClass.Initialize(self) + timer.Simple(0.1,function() + self.data.inventories[self:GetCreationID()].accepts = { + ["Wood"] = true, + ["Copper"] = true, + ["Iron"] = true + } + end) + self.Entity:SetModel("models/props/cs_militia/sawhorse.mdl") + self.Entity:PhysicsInit( SOLID_VPHYSICS ) + self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) + self.Entity:SetSolid( SOLID_VPHYSICS ) + self.Entity:Activate() + local phys = self.Entity:GetPhysicsObject() + if (phys:IsValid()) then + phys:Wake() + phys:SetMass(100) + end + self.selfPos = self.Entity + self:SetUseType(SIMPLE_USE) +end + + +util.AddNetworkString("art_workbench_open") +util.AddNetworkString("art_workbench_select") +util.AddNetworkString("art_workbench_puzzle") +util.AddNetworkString("art_workbench_put") +util.AddNetworkString("art_workbench_close") + +function ENT:Use(a,c,u,v) + net.Start("art_workbench_open") + net.WriteEntity(self) + net.Send(c) + BaseClass.Use(self,a,c,u,v) +end + +function ENT:NumOf(name) + local myinv = self.data.inventories[self:GetCreationID()] + local cursor = myinv:Has(name) + local titm = nil + local num = 0 + while cursor ~= nil do + titm = myinv:Remove(cursor) + num = num + 1 + cursor = myinv:Has(name) + end + --Put stuff back in + for i = 1,num do + if titm ~= nil then + local pos = myinv:FindPlaceFor(titm) + myinv:Put(pos,titm) + end + end + + return num +end + +net.Receive("art_workbench_select",function(ln,ply) + local name = net.ReadString() + local who = net.ReadEntity() + print("props are:") + PrintTable(s.props) + assert(s.props[name],"Player " .. ply:Nick() .. " tried to make a prop we don't have:" .. name) + local reqs = s.props[name].reqs + print("player wanted to make a ",name,reqs) + PrintTable(reqs) + local canmake = true + for k,v in pairs(reqs) do + if who:NumOf(k) < v then + canmake = false + break + end + end + + local myinv = who.data.inventories[who:GetCreationID()] + if canmake then + print("Player can make, giveing") + xpcall(function() + ply:GiveItem(itm.GetItemByName(name)) + ply:AddSkill("Toolbuilding",#reqs) + for k,v in pairs(reqs) do + for i = 1,v do + local cur = myinv:Has(k) + myinv:Remove(cur) + end + end + end,function(err) + Msg("Failed to insert:" .. err) + end) + end +end) + +scripted_ents.Register(ENT,"art_workbench") diff --git a/data/artery/global/cl_crafting_inv.lua b/data/artery/global/cl_crafting_inv.lua index ead7c3e..6a61208 100644 --- a/data/artery/global/cl_crafting_inv.lua +++ b/data/artery/global/cl_crafting_inv.lua @@ -1,3 +1,3 @@ ---[[ - The client part -]] +--[[ + The client part +]] diff --git a/data/artery/global/sh_chopwood.txt b/data/artery/global/sh_chopwood.txt index 46e2c07..854bc92 100644 --- a/data/artery/global/sh_chopwood.txt +++ b/data/artery/global/sh_chopwood.txt @@ -5,6 +5,15 @@ local itm = nrequire("item.lua") local skil = nrequire("sh_skillcommon.lua") skil.RegisterSkill({"Forageing","Woodcutting"}) +local matmap = { + [0] = "materials/svg/delapouite/originals/svg/000000/transparent/log.svg", + "materials/svg/lorc/originals/svg/000000/transparent/root-tip.svg", + "materials/svg/lorc/originals/svg/000000/transparent/oak.svg", + "materials/svg/lorc/originals/svg/000000/transparent/pine-tree.svg", + "materials/svg/lorc/originals/svg/000000/transparent/dead-wood.svg", + +} + local function isoutside(puzzle,width,height,position) --rewrite this at some point print("Checking ",width,height,position) PrintTable(puzzle) @@ -19,6 +28,10 @@ if SERVER then util.AddNetworkString("artery_chop_wood_start") util.AddNetworkString("artery_chop_wood_quit") util.AddNetworkString("artery_chop_wood_action") + for k,v in pairs(matmap) do + resource.AddSingleFile(v) + end + function puzzlefactory(width,height,veriety) local puzzle = {} local height,width = 4,4 diff --git a/data/artery/global/sh_crafting_inv.lua b/data/artery/global/sh_crafting_inv.lua index d720551..0514ba0 100644 --- a/data/artery/global/sh_crafting_inv.lua +++ b/data/artery/global/sh_crafting_inv.lua @@ -1,193 +1,193 @@ ---[[ - An inventory that accepts materials and can store 100's of them. -]] ---[[ - Public functions: - RegisterInventory(tbl_inventory) ::nil - Registers a new inventory prototype, see below - CreateInventory(string_name) ::table_inventory - Creates a new inventory be sure to set the .owner and .id fields! - CreateInventoryFromData(string_name,string_data)::table_inventory) - Just deserializes an inventory. You still need to set .owner and .id! - DeriveInventory(string_name) ::table_inventory - Creates a new inventory from an old, allows for heiarchy. - Inventories have the following structure - field returns - inv.Name ::string - The name! - inv:FindPlaceFor(item) ::table_position or nil - Finds a place for the item - inv:CanFitIn(table_position,item) ::boolean - Check if the item can fit in the position - inv:Put(table_position,item) ::nil - Put an item in at the position - inv:Has(string_or_compare_func) ::table_position or nil - find an item in the inventory - inv:Remove(position) ::table_item - Remove an item from the position - inv:Get(position) ::table_item - Get the item at a position - inv:Serialize() ::string - Serialize the item to store it in a db - inv:DeSerialize(str) ::table_inventory - recreate the item from data in serialize - The above fields must be defined for new inventories. - ----------------------------------------------------- - The below are automatically made if they do not exist. - inv:AddObserver(tbl_other) ::number_id Whenever put or remove is called on this inventory, tbl_other's put() and remove() is also called, for easy networking to whoever needs it - inv:RemoveObserver(number_id) ::nil Removes an observer from the inventory - ------------------------------------------------------ - These fields should be defined when an inventory is created, before it can be used - inv.Owner ::entity - inv.id ::number -]] -if not nrequire then return end -local reg = nrequire("core/inventory/inventory.lua") -local itm = nrequire("core/inventory/item.lua") -local i = {} - -i.Name = "Crafting Inventory" -i.materials = {} -i.accepts = {} - -function i:FindPlaceFor(item) - if not self.accepts[item.Name] then return nil end - return {item.Name} -end - -function i:CanFitIn(position,item) - return self.accepts[item.Name] -end - -function i:Put(pos,item) - self.materials[item.Name] = (self.materials[item.Name] or 0) + 1 -end - -function i:Has(str_or_cmp) - if type(str_or_cmp) == "function" then error("Tried to check has of a workbench with function") end - if (self.materials[str_or_cmp] or 0) > 0 then - return {str_or_cmp} - else - return nil - end -end - -function i:Remove(tbl) - local ret = itm.GetItemByName(tbl[1]) - assert(self.materials[ tbl[1] ] > 0, "Tried to remove a resource when we didn't have any!") - self.materials[ tbl[1] ] = self.materials[ tbl[1] ] - 1 - return ret -end - -function i:Get(tbl) - return itm.GetItemByName(tbl[1]) -end - -function i:Serialize() - local s = { - materials = self.materials, - accepts = self.accepts - } - return util.TableToJSON(s) -end - -function i:DeSerialize(data) - local cpy = table.Copy(self) - local d = util.JSONToTable(data) - cpy.materials = d.materials - cpy.accepts = d.accepts - return cpy -end - -if CLIENT then - local svg = nrequire("cl_svg.lua") - local com = nrequire("cl_common.lua") - local col = nrequire("colortheme.lua") - local c = col.ui.border - local inputimg = svg.MaterialFromSVG("materials/svg/delapouite/gui/svg/000000/transparent/plain-arrow.svg", nil, ucol) - - function i.DrawOnDPanel(self,dpanel) - local matpnls = {} - local matscroll = vgui.Create("DScrollPanel",dpanel) - matscroll:Dock(FILL) - - local inputpnl = vgui.Create("DModelPanel",dpanel) - --inputpnl:Dock(TOP) - inputpnl.PaintOver = function(tp,w,h) - if inputimg.material then - surface.SetDrawColor(c.r,c.g,c.b) - surface.DrawOutlinedRect(0, 0, h, h) - surface.SetDrawColor(255,255,255) - surface.SetMaterial( inputimg.material ) - surface.DrawTexturedRect( 0, 0, h, h ) - end - end - inputpnl:Receiver("item",com.generatereceiver()) - inputpnl:SetSize(50,50) - inputpnl.info = { - owner = self.Owner, - id = self.id, - pos = {"*"}, - inv = self - } - inputpnl:Dock(TOP) - - local function create_panel(k,v) - local pnlitem = {} - pnlitem.panel = vgui.Create("DPanel",matscroll) - pnlitem.panel:Dock(TOP) - pnlitem.text = vgui.Create("DLabel",pnlitem.panel) - pnlitem.text:SetText(string.format("%10s : %5d",k,v - 1)) - pnlitem.text:Dock(FILL) - pnlitem.text:SetDark(true) - local ta = vgui.Create("DModelPanel",pnlitem.panel) - ta:Dock(LEFT) - ta:Droppable("item") - ta.info = { - owner = self.Owner, - id = self.id, - pos = {k}, - inv = self - } - matpnls[k] = pnlitem - end - - for k,v in pairs(self.materials) do - if v > 0 then - create_panel(k,v) - end - end - - local function refresh_ammt(name,p) - local pnlitem = matpnls[ name ] - local ammt = self.materials[name] - if ammt == 0 or ammt == nil then - pnlitem.panel:Remove() - else - pnlitem.text:SetText(string.format("%10s : %5d",name,ammt)) --Called before the actual inventorie's put, so +1 - end - end - - local observer = {} - observer.Put = function(obs,position,item) - if self.materials[ item.Name ] == nil or self.materials[ item.Name ] == 0 then --Create a panel for the item - create_panel(item.Name,1) - else - refresh_ammt(item.Name,1) - end - --matslbls[ position[1] ]:SetText(self.materials[ position[1] ]) - --drawitemat(self,position[1],position[2],item) - end - observer.Remove = function(obs,position) - if self.materials[position[1]] == 1 then --Remove at 1 since this is called before inventory's remove() - matpnls[position[1]].panel:Remove() - end - refresh_ammt(position[1],-1) - --matslbls[ position[1] ]:SetText(self.materials[ position[1] ]) - --undrawitemat(self,position[1],position[2]) - end - return observer - end -end - -reg.RegisterInventory(i) +--[[ + An inventory that accepts materials and can store 100's of them. +]] +--[[ + Public functions: + RegisterInventory(tbl_inventory) ::nil + Registers a new inventory prototype, see below + CreateInventory(string_name) ::table_inventory + Creates a new inventory be sure to set the .owner and .id fields! + CreateInventoryFromData(string_name,string_data)::table_inventory) + Just deserializes an inventory. You still need to set .owner and .id! + DeriveInventory(string_name) ::table_inventory + Creates a new inventory from an old, allows for heiarchy. + Inventories have the following structure + field returns + inv.Name ::string + The name! + inv:FindPlaceFor(item) ::table_position or nil + Finds a place for the item + inv:CanFitIn(table_position,item) ::boolean + Check if the item can fit in the position + inv:Put(table_position,item) ::nil + Put an item in at the position + inv:Has(string_or_compare_func) ::table_position or nil + find an item in the inventory + inv:Remove(position) ::table_item + Remove an item from the position + inv:Get(position) ::table_item + Get the item at a position + inv:Serialize() ::string + Serialize the item to store it in a db + inv:DeSerialize(str) ::table_inventory + recreate the item from data in serialize + The above fields must be defined for new inventories. + ----------------------------------------------------- + The below are automatically made if they do not exist. + inv:AddObserver(tbl_other) ::number_id Whenever put or remove is called on this inventory, tbl_other's put() and remove() is also called, for easy networking to whoever needs it + inv:RemoveObserver(number_id) ::nil Removes an observer from the inventory + ------------------------------------------------------ + These fields should be defined when an inventory is created, before it can be used + inv.Owner ::entity + inv.id ::number +]] +if not nrequire then return end +local reg = nrequire("core/inventory/inventory.lua") +local itm = nrequire("core/inventory/item.lua") +local i = {} + +i.Name = "Crafting Inventory" +i.materials = {} +i.accepts = {} + +function i:FindPlaceFor(item) + if not self.accepts[item.Name] then return nil end + return {item.Name} +end + +function i:CanFitIn(position,item) + return self.accepts[item.Name] +end + +function i:Put(pos,item) + self.materials[item.Name] = (self.materials[item.Name] or 0) + 1 +end + +function i:Has(str_or_cmp) + if type(str_or_cmp) == "function" then error("Tried to check has of a workbench with function") end + if (self.materials[str_or_cmp] or 0) > 0 then + return {str_or_cmp} + else + return nil + end +end + +function i:Remove(tbl) + local ret = itm.GetItemByName(tbl[1]) + assert(self.materials[ tbl[1] ] > 0, "Tried to remove a resource when we didn't have any!") + self.materials[ tbl[1] ] = self.materials[ tbl[1] ] - 1 + return ret +end + +function i:Get(tbl) + return itm.GetItemByName(tbl[1]) +end + +function i:Serialize() + local s = { + materials = self.materials, + accepts = self.accepts + } + return util.TableToJSON(s) +end + +function i:DeSerialize(data) + local cpy = table.Copy(self) + local d = util.JSONToTable(data) + cpy.materials = d.materials + cpy.accepts = d.accepts + return cpy +end + +if CLIENT then + local svg = nrequire("cl_svg.lua") + local com = nrequire("cl_common.lua") + local col = nrequire("colortheme.lua") + local c = col.ui.border + local inputimg = svg.MaterialFromSVG("materials/svg/delapouite/gui/svg/000000/transparent/plain-arrow.svg", nil, ucol) + + function i.DrawOnDPanel(self,dpanel) + local matpnls = {} + local matscroll = vgui.Create("DScrollPanel",dpanel) + matscroll:Dock(FILL) + + local inputpnl = vgui.Create("DModelPanel",dpanel) + --inputpnl:Dock(TOP) + inputpnl.PaintOver = function(tp,w,h) + if inputimg.material then + surface.SetDrawColor(c.r,c.g,c.b) + surface.DrawOutlinedRect(0, 0, h, h) + surface.SetDrawColor(255,255,255) + surface.SetMaterial( inputimg.material ) + surface.DrawTexturedRect( 0, 0, h, h ) + end + end + inputpnl:Receiver("item",com.generatereceiver()) + inputpnl:SetSize(50,50) + inputpnl.info = { + owner = self.Owner, + id = self.id, + pos = {"*"}, + inv = self + } + inputpnl:Dock(TOP) + + local function create_panel(k,v) + local pnlitem = {} + pnlitem.panel = vgui.Create("DPanel",matscroll) + pnlitem.panel:Dock(TOP) + pnlitem.text = vgui.Create("DLabel",pnlitem.panel) + pnlitem.text:SetText(string.format("%10s : %5d",k,v - 1)) + pnlitem.text:Dock(FILL) + pnlitem.text:SetDark(true) + local ta = vgui.Create("DModelPanel",pnlitem.panel) + ta:Dock(LEFT) + ta:Droppable("item") + ta.info = { + owner = self.Owner, + id = self.id, + pos = {k}, + inv = self + } + matpnls[k] = pnlitem + end + + for k,v in pairs(self.materials) do + if v > 0 then + create_panel(k,v) + end + end + + local function refresh_ammt(name,p) + local pnlitem = matpnls[ name ] + local ammt = self.materials[name] + if ammt == 0 or ammt == nil then + pnlitem.panel:Remove() + else + pnlitem.text:SetText(string.format("%10s : %5d",name,ammt)) --Called before the actual inventorie's put, so +1 + end + end + + local observer = {} + observer.Put = function(obs,position,item) + if self.materials[ item.Name ] == nil or self.materials[ item.Name ] == 0 then --Create a panel for the item + create_panel(item.Name,1) + else + refresh_ammt(item.Name,1) + end + --matslbls[ position[1] ]:SetText(self.materials[ position[1] ]) + --drawitemat(self,position[1],position[2],item) + end + observer.Remove = function(obs,position) + if self.materials[position[1]] == 1 then --Remove at 1 since this is called before inventory's remove() + matpnls[position[1]].panel:Remove() + end + refresh_ammt(position[1],-1) + --matslbls[ position[1] ]:SetText(self.materials[ position[1] ]) + --undrawitemat(self,position[1],position[2]) + end + return observer + end +end + +reg.RegisterInventory(i) diff --git a/data/artery/global/sh_minerock.txt b/data/artery/global/sh_minerock.txt index 0e6bcaf..b73748b 100644 --- a/data/artery/global/sh_minerock.txt +++ b/data/artery/global/sh_minerock.txt @@ -47,7 +47,7 @@ local function findmatchesfortile(puzzle,x,y) matches[#matches+1] = v end end - + --Find verticle matches local matchesverticle = 1 cursor = y + 1 @@ -94,39 +94,39 @@ local oremap = { "materials/svg/faithtoken/originals/svg/000000/transparent/minerals.svg", "materials/svg/delapouite/originals/svg/000000/transparent/stone-pile.svg", "materials/svg/lorc/originals/svg/000000/transparent/fossil.svg" - + } if SERVER then local itm = nrequire("item.lua") - + for k,v in pairs(oremap) do resource.AddSingleFile(v) end - + util.AddNetworkString("artery_mine_rock_start") util.AddNetworkString("artery_mine_rock_new") util.AddNetworkString("artery_mine_rock_quit") util.AddNetworkString("artery_mine_rock_action") util.AddNetworkString("artery_mine_rocks_update") - + local function genpuzzle(width,height,variety) local puzzle = {} puzzle.width = width puzzle.height = height puzzle.variety = variety puzzle.tiles = {} - + for i = 0,puzzle.width do puzzle.tiles[i] = {} for j = 0,puzzle.height do puzzle.tiles[i][j] = math.random(0,puzzle.variety) end end - + return puzzle end - + local function del_and_replace(puzzle,matches) local tp = puzzle.tiles local function dropcolumn(x,y,spaces) @@ -139,9 +139,9 @@ if SERVER then dropcolumn(v[1],v[2],1) end end - - - + + + local function findmatchesfor(puzzle) local duped = {} for i = 0, puzzle.width-1 do @@ -165,7 +165,7 @@ if SERVER then end return m end - + local puzzles = {} local scores = {} function meta:MineRock() @@ -182,11 +182,11 @@ if SERVER then net.WriteTable(p) net.Send(self) end - + local function kick_cheating_player(who) error(who:Nick() .. " was cheating!") end - + net.Receive("artery_mine_rock_action",function(ln,ply) local p = puzzles[ply] local x1 = net.ReadUInt(8) @@ -210,9 +210,9 @@ if SERVER then net.WriteTable(p) net.WriteDouble(scores[ply]) net.Send(ply) - ply:StartAnimation("stranded_mine_rock") + --ply:StartAnimation("stranded_mine_rock") end) - + net.Receive("artery_mine_rock_quit",function(ln,ply) local s = scores[ply] local cursor = 1 @@ -224,7 +224,7 @@ if SERVER then local togive = itm.GetItemByName(n) ply:GiveItem(togive) ply:AddSkill("Mineing",s) - ply:StopAnimation("stranded_mine_rock") + ply:StopAnimation("stranded_mine_rocks") end) else local svg = nrequire("cl_svg.lua") @@ -254,34 +254,34 @@ else net.Start("artery_mine_rock_quit") net.SendToServer() end - + local puzzlepane = vgui.Create( "DPanel", puzzleview ) puzzlepane:Dock(FILL) - + local help = vgui.Create("DLabel",puzzlepane) help:SetText("Click two cells to switch them.\nCreate runs of 3 or more to clear them from the board\nNew numbers come in from the top\nQuit at any time to receive the resource you have worked towards.") help:SetDark(true) help:SizeToContents() help:Dock(RIGHT) - + local rocklayout = vgui.Create("DPanel",puzzlepane) rocklayout:Dock(BOTTOM) - + local rockprogress = vgui.Create( "DProgress",rocklayout ) rockprogress:Dock(FILL) - + local rocknameleft = vgui.Create("DLabel",rocklayout) rocknameleft:Dock(LEFT) rocknameleft:SetDark(true) rocknameleft:SetText("") - + local rocknameright = vgui.Create("DLabel",rocklayout) rocknameright:Dock(RIGHT) rocknameright:SetDark(true) rocknameright:SetText(rockdata[2][1]) - + rocks = {rockprogress,rocknameleft,rocknameright} - + local puzzlegrid = vgui.Create( "DGrid", puzzlepane ) puzzlegrid:SetCols(tbl.width) puzzlegrid:Dock(TOP) @@ -306,6 +306,9 @@ else else self:SetMaterial(oremats[tbl.tiles[x][y]].material) end + end + tile.Paint = function(self,w,h) + end tile.DoClick = function(self) if selected == nil then @@ -339,9 +342,9 @@ else puzzlegrid:AddItem(tile) end end - + end) - + net.Receive("artery_mine_rocks_update",function() tbl = net.ReadTable() local score = net.ReadDouble() @@ -367,5 +370,5 @@ else end end end) - + end diff --git a/data/artery/global/sh_shipyard.txt b/data/artery/global/sh_shipyard.txt index b29c63c..b2f9395 100644 --- a/data/artery/global/sh_shipyard.txt +++ b/data/artery/global/sh_shipyard.txt @@ -1,63 +1,63 @@ ---[[ - A hunting ground zone will occasionally spawn a monster near a player that will go attack the player -]] -zones.RegisterClass("artery_shipyard",Color(238,238,255)) - ---Use this to set default properties. Only called on server. -hook.Add("OnZoneCreated","artery_outpost",function(zone,class,zoneID) - if class == "artery_shipyard" then - zone.datatbl = {} - zone.datatbl.control = ents.Create("art_shipyardcontrol") - zone.datatbl.control:SetPos(Entity(1):GetPos()) - zone.datatbl.control:Spawn() - zone.datatbl.control.Zone = zoneID - end -end) - --- Use this hook to let a player change a zone after making it or with the edit tool. --- class is zone.class, zone is the zone's full table, DPanel is a panel to parent your things to, zoneID is the zone's ID, DFrame is the whole frame. --- Return your preferred width and height for the panel and the frame will size to it. -hook.Add("ShowZoneOptions","artery_shipyard",function(zone,class,DPanel,zoneID,DFrame) - if class == "artery_shipyard" then - local w,h = 500, 400 - - local scroll = vgui.Create( "DScrollPanel",DPanel) - scroll:Dock(FILL) - - function synctbl() - net.Start("artery_shipyard_settbl") - net.WriteFloat(zoneID) - net.WriteTable(zone.datatbl) - net.SendToServer() - end - - print("Displaying table, my table is") - PrintTable(zone.datatbl) - - local shipinstr = vgui.Create("DLabel",DPanel) - shipinstr:Dock(TOP) - shipinstr:SetText("Find the control entity, and palce it somewhere reasonable.") - shipinstr:SetDark(true) - shipinstr:SizeToContents() - - return w, h -- Specify the width and height for the DPanel container. The frame will resize accordingly. - - end -end) - -if SERVER then - util.AddNetworkString("artery_shipyard_settbl") - net.Receive("artery_shipyard_settbl",function(len,ply) - print("Server change received!") - local id, new = net.ReadFloat(), net.ReadTable() - print("New table is:") - PrintTable(new) - if not ply:IsAdmin() then return end - local zone = zones.List[id] - zone.datatbl = new - if new.Name then - zone.Name = new.Name - end - zones.Sync() - end) -end +--[[ + A hunting ground zone will occasionally spawn a monster near a player that will go attack the player +]] +zones.RegisterClass("artery_shipyard",Color(238,238,255)) + +--Use this to set default properties. Only called on server. +hook.Add("OnZoneCreated","artery_outpost",function(zone,class,zoneID) + if class == "artery_shipyard" then + zone.datatbl = {} + zone.datatbl.control = ents.Create("art_shipyardcontrol") + zone.datatbl.control:SetPos(Entity(1):GetPos()) + zone.datatbl.control:Spawn() + zone.datatbl.control.Zone = zoneID + end +end) + +-- Use this hook to let a player change a zone after making it or with the edit tool. +-- class is zone.class, zone is the zone's full table, DPanel is a panel to parent your things to, zoneID is the zone's ID, DFrame is the whole frame. +-- Return your preferred width and height for the panel and the frame will size to it. +hook.Add("ShowZoneOptions","artery_shipyard",function(zone,class,DPanel,zoneID,DFrame) + if class == "artery_shipyard" then + local w,h = 500, 400 + + local scroll = vgui.Create( "DScrollPanel",DPanel) + scroll:Dock(FILL) + + function synctbl() + net.Start("artery_shipyard_settbl") + net.WriteFloat(zoneID) + net.WriteTable(zone.datatbl) + net.SendToServer() + end + + print("Displaying table, my table is") + PrintTable(zone.datatbl) + + local shipinstr = vgui.Create("DLabel",DPanel) + shipinstr:Dock(TOP) + shipinstr:SetText("Find the control entity, and palce it somewhere reasonable.") + shipinstr:SetDark(true) + shipinstr:SizeToContents() + + return w, h -- Specify the width and height for the DPanel container. The frame will resize accordingly. + + end +end) + +if SERVER then + util.AddNetworkString("artery_shipyard_settbl") + net.Receive("artery_shipyard_settbl",function(len,ply) + print("Server change received!") + local id, new = net.ReadFloat(), net.ReadTable() + print("New table is:") + PrintTable(new) + if not ply:IsAdmin() then return end + local zone = zones.List[id] + zone.datatbl = new + if new.Name then + zone.Name = new.Name + end + zones.Sync() + end) +end diff --git a/data/artery/global/sv_config.txt b/data/artery/global/sv_config.txt index 30efdc3..3f3e40b 100644 --- a/data/artery/global/sv_config.txt +++ b/data/artery/global/sv_config.txt @@ -1,10 +1,10 @@ -do return end -if not nrequire then return end -local n = nrequire("sv_newplayer.lua") - -n.newmeta = function() - return { - lastserver = "67.163.245.187:27015", - lastlocation = "175 325 524" - } -end +do return end +if not nrequire then return end +local n = nrequire("sv_newplayer.lua") + +n.newmeta = function() + return { + lastserver = "67.163.245.187:27015", + lastlocation = "175 325 524" + } +end diff --git a/data/artery/global/sv_dupboat.lua b/data/artery/global/sv_dupboat.lua index 1a32d0c..df613f6 100644 --- a/data/artery/global/sv_dupboat.lua +++ b/data/artery/global/sv_dupboat.lua @@ -1,38 +1,38 @@ -if not nrequire then return end -duplicator.Allow("prop_physics") - -local dups = {} - -local function copyplayer(ply,cmd,args) - local tr = util.TraceLine({ - start = ply:GetPos(), - endpos = ply:GetPos() + Vector(0,0,-100), - }) - local ent = tr.Entity - print('Ent is', ent) - duplicator.SetLocalPos( ply:GetPos()) - local dup = duplicator.Copy(ent) - duplicator.SetLocalPos(Vector(0,0,0)) - print("After normalizing, dup was") - PrintTable(dup) - dups[args[1]] = dup - print("saved boat as", args[1]) -end - -local function pasteplayer(ply,cmd,args) - print("Pasteing ", args[1]) - local dup = dups[args[1]] - print("Before setting up under player, dup is") - PrintTable(dup) - for k,v in pairs(dup.Entities) do - v.Pos = v.Pos + ply:GetPos() - end - print("After setting up under player, dup is") - PrintTable(dup) - duplicator.SetLocalPos( ply:GetPos()) - duplicator.Paste(ply,dup.Entities, dup.Constraints) - duplicator.SetLocalPos(Vector(0,0,0)) -end - -concommand.Add("artery_copyboat",copyplayer) -concommand.Add("artery_pasteboat",pasteplayer) +if not nrequire then return end +duplicator.Allow("prop_physics") + +local dups = {} + +local function copyplayer(ply,cmd,args) + local tr = util.TraceLine({ + start = ply:GetPos(), + endpos = ply:GetPos() + Vector(0,0,-100), + }) + local ent = tr.Entity + print('Ent is', ent) + duplicator.SetLocalPos( ply:GetPos()) + local dup = duplicator.Copy(ent) + duplicator.SetLocalPos(Vector(0,0,0)) + print("After normalizing, dup was") + PrintTable(dup) + dups[args[1]] = dup + print("saved boat as", args[1]) +end + +local function pasteplayer(ply,cmd,args) + print("Pasteing ", args[1]) + local dup = dups[args[1]] + print("Before setting up under player, dup is") + PrintTable(dup) + for k,v in pairs(dup.Entities) do + v.Pos = v.Pos + ply:GetPos() + end + print("After setting up under player, dup is") + PrintTable(dup) + duplicator.SetLocalPos( ply:GetPos()) + duplicator.Paste(ply,dup.Entities, dup.Constraints) + duplicator.SetLocalPos(Vector(0,0,0)) +end + +concommand.Add("artery_copyboat",copyplayer) +concommand.Add("artery_pasteboat",pasteplayer) -- cgit v1.2.3-70-g09d2