diff options
| author | Apickx <apickx@cogarr.com> | 2018-03-24 20:47:32 -0400 |
|---|---|---|
| committer | Apickx <apickx@cogarr.com> | 2018-03-24 20:47:32 -0400 |
| commit | d22897e044a422e125f46e52c3467473a3656378 (patch) | |
| tree | b7eedbaa95f3ec6c7c28a2b33405dda84adbf945 /data/artery/global | |
| download | artery_stranded-d22897e044a422e125f46e52c3467473a3656378.tar.gz artery_stranded-d22897e044a422e125f46e52c3467473a3656378.tar.bz2 artery_stranded-d22897e044a422e125f46e52c3467473a3656378.zip | |
Inital commit
Inital commit
Diffstat (limited to 'data/artery/global')
19 files changed, 1749 insertions, 0 deletions
diff --git a/data/artery/global/art_sawhorse/cl_ent_sawhorse.lua b/data/artery/global/art_sawhorse/cl_ent_sawhorse.lua new file mode 100644 index 0000000..2cbe16a --- /dev/null +++ b/data/artery/global/art_sawhorse/cl_ent_sawhorse.lua @@ -0,0 +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") diff --git a/data/artery/global/art_sawhorse/sh_ent_sawhorse.lua b/data/artery/global/art_sawhorse/sh_ent_sawhorse.lua new file mode 100644 index 0000000..bf0e640 --- /dev/null +++ b/data/artery/global/art_sawhorse/sh_ent_sawhorse.lua @@ -0,0 +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 diff --git a/data/artery/global/art_sawhorse/sv_ent_sawhorse.lua b/data/artery/global/art_sawhorse/sv_ent_sawhorse.lua new file mode 100644 index 0000000..393aaed --- /dev/null +++ b/data/artery/global/art_sawhorse/sv_ent_sawhorse.lua @@ -0,0 +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") diff --git a/data/artery/global/art_shipyardcontrol/cl_ent_shipyardcontrol.lua b/data/artery/global/art_shipyardcontrol/cl_ent_shipyardcontrol.lua new file mode 100644 index 0000000..c9be7a6 --- /dev/null +++ b/data/artery/global/art_shipyardcontrol/cl_ent_shipyardcontrol.lua @@ -0,0 +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") diff --git a/data/artery/global/art_shipyardcontrol/sh_ent_shipyardcontrol.lua b/data/artery/global/art_shipyardcontrol/sh_ent_shipyardcontrol.lua new file mode 100644 index 0000000..bb0026b --- /dev/null +++ b/data/artery/global/art_shipyardcontrol/sh_ent_shipyardcontrol.lua @@ -0,0 +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 diff --git a/data/artery/global/art_shipyardcontrol/sv_ent_shipyardcontrol.lua b/data/artery/global/art_shipyardcontrol/sv_ent_shipyardcontrol.lua new file mode 100644 index 0000000..ed1eed0 --- /dev/null +++ b/data/artery/global/art_shipyardcontrol/sv_ent_shipyardcontrol.lua @@ -0,0 +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") diff --git a/data/artery/global/art_workbench/cl_ent_workbench.lua b/data/artery/global/art_workbench/cl_ent_workbench.lua new file mode 100644 index 0000000..8f4b722 --- /dev/null +++ b/data/artery/global/art_workbench/cl_ent_workbench.lua @@ -0,0 +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") diff --git a/data/artery/global/art_workbench/sh_ent_workbench.lua b/data/artery/global/art_workbench/sh_ent_workbench.lua new file mode 100644 index 0000000..4900d3e --- /dev/null +++ b/data/artery/global/art_workbench/sh_ent_workbench.lua @@ -0,0 +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 diff --git a/data/artery/global/art_workbench/sv_ent_workbench.lua b/data/artery/global/art_workbench/sv_ent_workbench.lua new file mode 100644 index 0000000..9ce7e0f --- /dev/null +++ b/data/artery/global/art_workbench/sv_ent_workbench.lua @@ -0,0 +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") diff --git a/data/artery/global/cl_crafting_inv.lua b/data/artery/global/cl_crafting_inv.lua new file mode 100644 index 0000000..ead7c3e --- /dev/null +++ b/data/artery/global/cl_crafting_inv.lua @@ -0,0 +1,3 @@ +--[[ + The client part +]] diff --git a/data/artery/global/cl_stranded_craftpanel.txt b/data/artery/global/cl_stranded_craftpanel.txt new file mode 100644 index 0000000..ee90f57 --- /dev/null +++ b/data/artery/global/cl_stranded_craftpanel.txt @@ -0,0 +1,20 @@ +--Maybe this will get used some day. + +do return end +local i = nrequire("cl_inventory.lua") + +i.ShowInventory() + +local otab = otab or nil +local function addcraftingtab() + if otab then otab:Remove() end + + local cpnl = vgui.Create("DPanel") + + + + otab = i.tabsheet:AddSheet("Crafting",cpnl,"icon16/user.png", false, false, "Craft things!") +end + + +addcraftingtab()
\ No newline at end of file diff --git a/data/artery/global/sh_chopwood.txt b/data/artery/global/sh_chopwood.txt new file mode 100644 index 0000000..46e2c07 --- /dev/null +++ b/data/artery/global/sh_chopwood.txt @@ -0,0 +1,239 @@ +--Wood chopping minigame +if not nrequire then return end +local meta = FindMetaTable("Player") +local itm = nrequire("item.lua") +local skil = nrequire("sh_skillcommon.lua") +skil.RegisterSkill({"Forageing","Woodcutting"}) + +local function isoutside(puzzle,width,height,position) --rewrite this at some point + print("Checking ",width,height,position) + PrintTable(puzzle) + + return position < width or position > ((height-1) * width) or --If we are top or bottom + position % width == 0 or (position + 1) % width == 0 or --If we are on either side + puzzle[position + width] == nil or puzzle[position - width] == nil or + puzzle[position + 1] == nil or puzzle[position - 1] == nil +end + +if SERVER then + util.AddNetworkString("artery_chop_wood_start") + util.AddNetworkString("artery_chop_wood_quit") + util.AddNetworkString("artery_chop_wood_action") + function puzzlefactory(width,height,veriety) + local puzzle = {} + local height,width = 4,4 + local avaliable = {} + for i = 0,width-1 do + table.insert(avaliable,i) --first row + table.insert(avaliable,(height-1) * width + i) --last row + end + for i = 1,height-2 do + table.insert(avaliable,width * i) --first column + end + for i = 2,height-1 do + table.insert(avaliable,(width * i) - 1 ) --last column + end + table.RemoveByValue(avaliable,-1) + for i = 0,((width*height)/2)-1 do + local pairtype = math.random(0,veriety-1) + --Randomly add tiles to the board, marking new places as avaliable as we go + local rs1 = table.remove(avaliable,math.random(1,#avaliable)) + local rs2 = table.remove(avaliable,math.random(1,#avaliable)) + puzzle[rs1] = pairtype + puzzle[rs2] = pairtype + local pot = { --Potential new avaliable spots to put things + rs1+width, + rs1-width, + rs2+width, + rs2-width, + } + --Add things left and right, but not if they jump left-to-right on the board + if rs1 % width ~= 0 then + pot[#pot+1] = rs1-1 + end + if rs1+1 % width ~= 0 then + pot[#pot+1] = rs1+1 + end + if rs2 % width ~= 0 then + pot[#pot+1] = rs2-1 + end + if rs2+1 % width ~= 0 then + pot[#pot+1] = rs2+1 + end + --Remove up-down things that go off the board + local npot = {} + for k,v in ipairs(pot) do + if puzzle[v] == nil and v >= 0 and v < height*width then + npot[#npot+1] = v + end + end + pot = npot + for k,v in ipairs(pot) do + local alreadyin = false + for i,j in ipairs(avaliable) do + if j == v then + alreadyin = true + break + end + end + if not alreadyin then + avaliable[#avaliable+1] = v + end + end + end + return puzzle + end + local playerpuzzles = {} + local playerpuzzledims = {} + function meta:ChopWood() + print("Chopwood called") + playerpuzzles[self] = puzzlefactory(4,4,5) + playerpuzzledims[self] = {4,4} + net.Start("artery_chop_wood_start") + net.WriteTable(playerpuzzles[self]) + net.WriteUInt(4,8) + net.WriteUInt(4,8) + net.Send(self) + end + local function kickcheater(who) + print("I think",who,"was cheating!!!") + end + net.Receive("artery_chop_wood_action",function(ln,ply) + local pos1 = net.ReadUInt(8) + local pos2 = net.ReadUInt(8) + local pz = playerpuzzles[ply] + local dim = playerpuzzledims[ply] + if isoutside(pz,dim[1],dim[2],pos1) and isoutside(pz,dim[1],dim[2],pos2) then + pz[pos1] = nil + pz[pos2] = nil + else + error("Player cheated!") + kickcheater(ply) + end + ply:SetLuaAnimation("stranded_chop_wood") + end) + net.Receive("artery_chop_wood_quit",function(ln,ply) + local pz = playerpuzzles[ply] + if #pz == 0 then + print("Player completed puzzle!") + local item = itm.GetItemByName("Wood") + ply:GiveItem(item) + ply:AddSkill("Woodcutting",1) + else + print("Player did not complete puzzle!") + end + ply:StopLuaAnimation("stranded_chop_wood") + end) +else --client + local svg = nrequire("cl_svg.lua") + 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 matico = {} + for k,v in pairs(matmap) do + matico[k] = svg.MaterialFromSVG(v,nil,"rgb(0,0,0);") + end + local matico_selected = {} + for k,v in pairs(matmap) do + matico_selected[k] = svg.MaterialFromSVG(v,"rgb(100,100,200);","rgb(255,255,255);") + end + + net.Receive("artery_chop_wood_start",function() + local puzzle = net.ReadTable() + local width = net.ReadUInt(8) + local height = net.ReadUInt(8) + local puzzleview = vgui.Create( "DFrame" ) + puzzleview:SetSize( ScrW()*0.5, ScrH()*0.5 ) + puzzleview:Center() + puzzleview:SetTitle( "Chop wood..." ) + puzzleview:SetDraggable( true ) + puzzleview:MakePopup() + + local puzzlepane = vgui.Create( "DPanel", puzzleview ) + puzzlepane:Dock(FILL) + + local puzzlehelp = vgui.Create( "DLabel",puzzlepane) + puzzlehelp:SetText("To chop wood, match the cells in pairs.\nYou complete the puzzle when all the cells are gone.\nYou may only match cells that are not surrounded\nby other cells.") + puzzlehelp:SizeToContents() + puzzlehelp:SetDark(true) + puzzlehelp:Dock(RIGHT) + + local puzzlegrid = vgui.Create( "DGrid", puzzlepane ) + puzzlegrid:SetCols(width) + puzzlegrid:Dock(FILL) + + local numleft = width*height + local selected + for i = 0, width*height - 1 do + local tile = vgui.Create("DImageButton") + --tile:SetText(puzzle[i]) + local tmat = matico[puzzle[i]] + if tmat.material then + tile:SetMaterial(tmat.material) + end + tile.position = i + tile.number = puzzle[i] + --tile:SizeToContents() + tile:SetWidth(32) + tile:SetHeight(32) + tile:SetStretchToFit( true ) + tile:SetIsToggle(true) + tile.DoClick = function(self) + local tp = self.position + if not isoutside(puzzle,width,height,tp) then + print("Could not press this button!") + return + end + + + if selected == nil then + selected = self + self:SetToggle(true) + self:SetMaterial(matico_selected[self.number].material) + elseif self == selected then + print("Selected is self!") + self:SetToggle(false) + self:SetMaterial(matico[self.number].material) + selected = nil + else + if selected.number == self.number then + net.Start("artery_chop_wood_action") + net.WriteUInt(self.position,8) + net.WriteUInt(selected.position,8) + net.SendToServer() + puzzle[self.position] = nil + puzzle[selected.position] = nil + --puzzlegrid:RemoveItem(self) + --puzzlegrid:RemoveItem(selected) + self:Remove() + selected:Remove() + selected = nil + numleft = numleft - 2 + if numleft == 0 then + timer.Simple(0.5,function() + print("Puzzle is empty! sending quit!") + net.Start("artery_chop_wood_quit") + net.SendToServer() + end) + puzzleview:Remove() + else + print("Puzzle is") + PrintTable(puzzle) + end + end + end + end + puzzlegrid:AddItem(tile) + end + puzzlegrid:Center() + puzzlegrid:InvalidateLayout(true) + function puzzlegrid:PerformLayout(w,h)--Don't re-layout ourselves. + + end + end) +end diff --git a/data/artery/global/sh_crafting_inv.lua b/data/artery/global/sh_crafting_inv.lua new file mode 100644 index 0000000..d720551 --- /dev/null +++ b/data/artery/global/sh_crafting_inv.lua @@ -0,0 +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) diff --git a/data/artery/global/sh_minerock.txt b/data/artery/global/sh_minerock.txt new file mode 100644 index 0000000..0e6bcaf --- /dev/null +++ b/data/artery/global/sh_minerock.txt @@ -0,0 +1,371 @@ +if not nrequire then return end +local meta = FindMetaTable("Player") +local rockdata = { + {nil,0}, + {"Stone" , 15}, + {"Copper" , 30}, + {"Tin" , 60}, + {"Iron" , 120}, + {"Coal" , 180}, +} + +local skil = nrequire("sh_skillcommon.lua") +skil.RegisterSkill({"Forageing","Mineing"}) + +local function printpuzzle(puzzle) + Msg("========================") + for y = 0, puzzle.height-1 do + for x = 0, puzzle.width-1 do + Msg(puzzle.tiles[x][y]) + end + Msg("\n") + end +end + +local function findmatchesfortile(puzzle,x,y) + printpuzzle(puzzle) + local matches = {} + local pt = puzzle.tiles + local t = pt[x][y] + --Find horizontal matches + local matcheshoizontal = 1 + local cursor = x + 1 + local pot = {{x,y}} + while cursor < puzzle.width and pt[cursor][y] == t do + matcheshoizontal = matcheshoizontal + 1 + pot[#pot + 1] = {cursor,y} + cursor = cursor + 1 + end + cursor = x - 1 + while cursor >= 0 and pt[cursor][y] == t do + matcheshoizontal = matcheshoizontal + 1 + pot[#pot + 1] = {cursor,y} + cursor = cursor - 1 + end + if matcheshoizontal > 2 then + for k,v in ipairs(pot) do + matches[#matches+1] = v + end + end + + --Find verticle matches + local matchesverticle = 1 + cursor = y + 1 + pot = {{x,y}} + while cursor < puzzle.height and pt[x][cursor] == t do + matchesverticle = matchesverticle + 1 + pot[#pot + 1] = {x,cursor} + cursor = cursor + 1 + end + cursor = y - 1 + while cursor >= 0 and pt[x][cursor] == t do + matchesverticle = matchesverticle + 1 + pot[#pot + 1] = {x,cursor} + cursor = cursor - 1 + end + if matchesverticle > 2 then + for k,v in ipairs(pot) do + matches[#matches+1] = v + end + end + return matches +end + +local function canswitch(puzzle,x1,y1,x2,y2) + if x1 == x2 and (y1 + 1 == y2 or y1 - 1 == y2) or + y1 == y2 and (x1 + 1 == x2 or x1 - 1 == x2) then + local v1 = puzzle.tiles[x1][y1] + local v2 = puzzle.tiles[x2][y2] + local tcpy = table.Copy(puzzle) + tcpy.tiles[x2][y2] = v1 + tcpy.tiles[x1][y1] = v2 + printpuzzle(tcpy) + local m1 = findmatchesfortile(tcpy,x1,y1) + local m2 = findmatchesfortile(tcpy,x2,y2) + return #m1 > 0 or #m2 > 0 + end + return false +end + +local oremap = { + [0] = "materials/svg/faithtoken/originals/svg/000000/transparent/ore.svg", + "materials/svg/lorc/originals/svg/000000/transparent/rock.svg", + "materials/svg/lorc/originals/svg/000000/transparent/stone-block.svg", + "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) + print("dropping ", x,y) + for ty = y, 0, -1 do + tp[x][ty] = tp[x][ty - spaces] or math.random(0,puzzle.variety) + end + end + for k,v in pairs(matches) do + dropcolumn(v[1],v[2],1) + end + end + + + + local function findmatchesfor(puzzle) + local duped = {} + for i = 0, puzzle.width-1 do + duped [i] = {} + end + for y = 0,puzzle.height-1 do + for x = 0, puzzle.width-1 do + local matches = findmatchesfortile(puzzle,x,y) + for k,v in pairs(matches) do + duped[v[1]][v[2]] = true + end + end + end + local m = {} + for y = 0,puzzle.height-1 do + for x = 0, puzzle.width-1 do + if duped[x][y] then + m[#m+1] = {x,y} + end + end + end + return m + end + + local puzzles = {} + local scores = {} + function meta:MineRock() + local p = genpuzzle(5,5,4) + local m = findmatchesfor(p) + while #m > 0 do + del_and_replace(p,m) + m = findmatchesfor(p) + end + puzzles[self] = p + scores[self] = 0 + self:StartAnimation("stranded_mine_rocks") + net.Start("artery_mine_rock_start") + 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) + local y1 = net.ReadUInt(8) + local x2 = net.ReadUInt(8) + local y2 = net.ReadUInt(8) + if not canswitch(p,x1,y1,x2,y2) then + kick_cheating_player(ply) + end + local v1,v2 = p.tiles[x1][y1],p.tiles[x2][y2] + p.tiles[x2][y2] = v1 + p.tiles[x1][y1] = v2 + local m = findmatchesfor(p) + while #m > 0 do + scores[ply] = scores[ply] + #m + del_and_replace(p,m) + m = findmatchesfor(p) + end + printpuzzle(p) + net.Start("artery_mine_rocks_update") + net.WriteTable(p) + net.WriteDouble(scores[ply]) + net.Send(ply) + ply:StartAnimation("stranded_mine_rock") + end) + + net.Receive("artery_mine_rock_quit",function(ln,ply) + local s = scores[ply] + local cursor = 1 + while cursor <= #rockdata and s >= rockdata[cursor][2] do + cursor = cursor + 1 + end + local n = rockdata[cursor-1][1] + if n == nil then return end + local togive = itm.GetItemByName(n) + ply:GiveItem(togive) + ply:AddSkill("Mineing",s) + ply:StopAnimation("stranded_mine_rock") + end) +else + local svg = nrequire("cl_svg.lua") + + local mine = {} + local tbl + local puzzleview + local rocks = {} + + local oremats = {} + for k,v in pairs(oremap) do + oremats[k] = svg.MaterialFromSVG(v,nil,"rgb(0,0,0);") + end + local oremats_selected = {} + for k,v in pairs(oremap) do + oremats_selected[k] = svg.MaterialFromSVG(v,"rgb(100,100,200);","rgb(255,255,255);") + end + net.Receive("artery_mine_rock_start",function() + tbl = net.ReadTable() + puzzleview = vgui.Create( "DFrame" ) + puzzleview:SetSize( ScrW()*0.5, ScrH()*0.5 ) + puzzleview:Center() + puzzleview:SetTitle( "Mine Rocks..." ) + puzzleview:SetDraggable( true ) + puzzleview:MakePopup() + puzzleview.OnClose = function(self) + 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) + local selected + for y = 0,tbl.height-1 do + for x = 0,tbl.width-1 do + local tile = vgui.Create("DImageButton") + mine[x] = mine[x] or {} + mine[x][y] = tile + local tmat = oremats[tbl.tiles[x][y]] + if tmat.material then + tile:SetMaterial(tmat.material) + end + tile:SetStretchToFit( true ) + tile.position = {x,y} + tile:SetWidth(32) + tile:SetHeight(32) + tile:SetIsToggle(true) + tile.OnToggled = function(self,state) + if state then + self:SetMaterial(oremats_selected[tbl.tiles[x][y]].material) + else + self:SetMaterial(oremats[tbl.tiles[x][y]].material) + end + end + tile.DoClick = function(self) + if selected == nil then + selected = self + self:SetToggle(true) + self:OnToggled(true) + elseif selected ~= self then + --Check if we can switch + local sp = selected.position + local tp = self.position + if canswitch(tbl,sp[1],sp[2],tp[1],tp[2]) then + net.Start("artery_mine_rock_action") + net.WriteUInt(sp[1],8) + net.WriteUInt(sp[2],8) + net.WriteUInt(tp[1],8) + net.WriteUInt(tp[2],8) + net.SendToServer() + local v1,v2 = selected:GetText(),self:GetText() + selected:SetText(v2) + self:SetText(v1) + selected:SetToggle(false) + selected:OnToggled(false) + selected = nil + end + else + selected:SetToggle(false) + selected:OnToggled(false) + selected = nil + end + end + puzzlegrid:AddItem(tile) + end + end + + end) + + net.Receive("artery_mine_rocks_update",function() + tbl = net.ReadTable() + local score = net.ReadDouble() + puzzleview:SetTitle("Mine Rocks... (" .. score .. ")") + printpuzzle(tbl) + for y = 0, tbl.height-1 do + for x = 0, tbl.width-1 do + mine[x][y]:SetMaterial(oremats[(tbl.tiles[x][y])].material) + end + end + if score > rockdata[#rockdata][2] then + puzzleview:Close() + return + end + for k,v in ipairs(rockdata) do + if score >= v[2] then + local l = v[2] + local n = rockdata[k+1][2] + local frac = (score-l) / (n - l) + rocks[1]:SetFraction(frac) + rocks[2]:SetText(v[1] or "") + rocks[3]:SetText(rockdata[k+1][1]) + end + end + end) + +end diff --git a/data/artery/global/sh_shipyard.txt b/data/artery/global/sh_shipyard.txt new file mode 100644 index 0000000..b29c63c --- /dev/null +++ b/data/artery/global/sh_shipyard.txt @@ -0,0 +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 diff --git a/data/artery/global/sh_stranded_items.txt b/data/artery/global/sh_stranded_items.txt new file mode 100644 index 0000000..5551f3b --- /dev/null +++ b/data/artery/global/sh_stranded_items.txt @@ -0,0 +1,61 @@ +--Some items from stranded +if not nrequire then return end +local reg = nrequire("item.lua") + +local items = { + { + Name = "Stone", + Description = "A bit of rock", + pacname = "error.mdl", + }, + { + Name = "Copper", + Description = "A dull orange metal", + pacname = "error.mdl", + }, + { + Name = "Tin", + Description = "A brittle shiny metal", + pacname = "error.mdl", + }, + { + Name = "Iron", + Description = "A strong gray metal", + pacnme = "error.mdl", + }, + { + Name = "Coal", + Description = "Compressed dead stuff", + pacname = "error.mdl" + }, + { + Name = "Wood", + Description = "It probably floats...", + pacname = "error.mdl" + }, + { + Name = "Nail", + Description = "Put things together!", + pacname = "error.mdl" + } +} + +local base = {} + +function base:Serialize() + return "" +end + +function base:DeSerialize(str) + return self +end + +base.Shape = {{true}} + +for k,v in pairs(items) do + local b = table.Copy(base) + for i,j in pairs(v) do + b[i] = j + end + reg.RegisterItem(b) +end diff --git a/data/artery/global/sh_stranded_tools.txt b/data/artery/global/sh_stranded_tools.txt new file mode 100644 index 0000000..c11241c --- /dev/null +++ b/data/artery/global/sh_stranded_tools.txt @@ -0,0 +1,210 @@ +--This is a test file! +if not nrequire then return end +local reg = nrequire("item.lua") +local pac +if SERVER then + pac = nrequire("core/pac/sv_pac.lua") +end + +local skil = nrequire("sh_skillcommon.lua") +skil.RegisterSkill({"Sailing","Paddleing"}) + +local paddleents = {} +hook.Add("Tick","paddleents",function() + for k,v in pairs(paddleents) do + --Make sure the player is still on the boat + --Find the entity below the player + local tr = util.TraceLine({ + start = v:GetPos() + Vector(0,0,20), + endpos = v:GetPos() + Vector(0,0,-20), + filter = v + }) + --And Add some velocity to it + if tr.Entity and IsValid(tr.Entity) then + --Move the boat + local oldvel = tr.Entity:GetVelocity() + local eye = v:EyeAngles():Forward() + eye.z = 0 + local newvel = oldvel + (eye * 5) * tr.Entity:GetPhysicsObject():GetMass() + k:GetPhysicsObject():SetVelocity(newvel) + print("newvel is", newvel) + v:AddSkill("Paddleing",0.1) + end + --Add skill for the player + --Turn the boat + --local angdif = v:EyeAngles().yaw - k:GetAngles().yaw + --k:GetPhysicsObject():SetAngleVelocity(Angle(0,angdif,0)) + end +end) + +local items = { + { + Name = "Axe", + Tooltip = "Usefull for cutting down trees", + Shape = { + {true,true}, + {true}, + {true} + }, + Model = "error.mdl", + pacname = "stranded_axe", + onClick = function(self, ply) --Run server side + print("Trying to chop...") + local tr = ply:GetEyeTrace() + print("Mattype:",tr.MatType,"Needed:",MAT_WOOD) + if tr.MatType == MAT_WOOD then + print("Chopping....") + ply:ChopWood() + end + end + }, + { + Name = "Pickaxe", + Tooltip = "Maybe you can dig up rocks with this", + Shape = { + {true,true,true}, + {false,true}, + {false, true}, + }, + Model = "error.mdl", + pacname = "stranded_pickaxe", + onClick = function(self, ply) --Run server side + print("Trying to pick...") + local tr = ply:GetEyeTrace() + print("Mattype:",tr.MatType,"Needed:",MAT_CONCRETE) + if tr.MatType == MAT_CONCRETE then + print("Chopping....") + ply:MineRock() + end + end + }, + { + Name = "Hammer", + Tooltip = "You should be able to build things with this", + Shape = { + {true,true,true}, + {false,true}, + {false,true}, + }, + Model = "error.mdl", + pacname = "stranded_hammer", + onClick = function(self,ply) + print("trying to hammer") + local tr = ply:GetEyeTrace() + local tents = {} + local cursor = 0 + local firstsucpos = nil + while IsValid(tr.Entity) and tr.Entity != game.GetWorld() and cursor < 4 do + firstsucpos = firstsucpos or tr.HitPos + tents[#tents+1] = tr.Entity + tnents = table.Copy(tents) + tnents[#tnents + 1] = ply + tr = util.TraceLine({ + start = tr.HitPos, + endpos = tr.HitPos + ply:EyeAngles():Forward() * 10, + filter = tnents + }) + cursor = cursor + 1 + end + print("found ents:") + PrintTable(tents) + --See if the player has nails + local nloc = ply:HasItem("Nail") + if nloc then + print("nlock was truthy, hammering...") + ply:RemoveItem(nloc) + local nail = ents.Create("prop_dynamic") + print("Setting pos to:",firstsucpos) + nail:SetPos(firstsucpos) + nail:SetAngles(ply:EyeAngles()) + nail:SetModel("models/crossbow_bolt.mdl") + nail:Spawn() + for k,v in pairs(tents) do + for i,j in pairs(tents) do + if v != j then + print("Welding ",j," to ", v) + constraint.Weld(j,v,0,0,100000,true,false) + end + end + end + nail:SetParent(tents[1]) + end + end + }, + { + Name = "Paddle", + Tooltip = "Row Row Row your boat", + Shape = { + {true}, + {true}, + {true} + }, + Model = "error.mdl", + pacname = "stranded_axe", + onClick = function(self, ply) --Run server side + --If we're current paddleing, stop + if self.paddleing then + print("paddleing ent removed") + paddleents[self.paddleing] = nil + self.paddleing = nil + return + end + + --Find the entity below the player + local tr = util.TraceLine({ + start = ply:GetPos() + Vector(0,0,20), + endpos = ply:GetPos() + Vector(0,0,-20), + filter = ply + }) + --And Add some velocity to it + if tr.Entity and IsValid(tr.Entity) then + print("Paddleing ent added") + self.paddleing = tr.Entity + paddleents[tr.Entity] = ply + end + end + }, +} + +local base = {} + +function base:Serialize() + return "" +end + +function base:DeSerialize() + return self +end + +function base:DoOnPanel(dmodelpanel) + dmodelpanel:SetModel(self.Model) +end + +function base:DoOnEquipPanel(dmodelpanel) + dmodelpanel:SetModel(self.Model) +end + +base.Equipable = "Right Hand" + +function base:onDropped(ent) + if CLIENT then return end + pac.ApplyPac(ent,self.pacname) + ent:SetAngles(Angle(180,0,0)) + ent:SetColor(Color(0,0,0,0)) +end + +function base:onEquip(ent) + if CLIENT then return end + pac.ApplyPac(ent,self.pacname) +end + +function base:onUnEquip(ent) + if CLIENT then return end + pac.RemovePac(ent,self.pacname) +end + +for k,v in pairs(items) do + local tbase = table.Copy(base) + for i,j in pairs(v) do tbase[i] = j end + reg.RegisterItem(tbase) +end diff --git a/data/artery/global/sv_config.txt b/data/artery/global/sv_config.txt new file mode 100644 index 0000000..30efdc3 --- /dev/null +++ b/data/artery/global/sv_config.txt @@ -0,0 +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 diff --git a/data/artery/global/sv_dupboat.lua b/data/artery/global/sv_dupboat.lua new file mode 100644 index 0000000..1a32d0c --- /dev/null +++ b/data/artery/global/sv_dupboat.lua @@ -0,0 +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) |
