aboutsummaryrefslogtreecommitdiff
path: root/gamemode
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode')
-rw-r--r--gamemode/client/cl_inventory.lua107
-rw-r--r--gamemode/client/cl_weaponswitch.lua4
-rw-r--r--gamemode/client/hud/cl_svgtest.lua46
-rw-r--r--gamemode/client/qtabs/cl_qinventory.lua69
-rw-r--r--gamemode/client/qtabs/cl_qprayers.lua8
-rw-r--r--gamemode/client/vgui/vgui_DMultiModelPanel.lua161
-rw-r--r--gamemode/config/colortheme.lua4
-rw-r--r--gamemode/core/inventory/inventory.lua14
-rw-r--r--gamemode/core/inventory/item.lua4
-rw-r--r--gamemode/core/inventory/sv_invtracker.lua80
-rw-r--r--gamemode/core/npc/cl_npcmap.lua (renamed from gamemode/core/npcmap/cl_npcmap.lua)0
-rw-r--r--gamemode/core/npc/sv_npcmap.lua (renamed from gamemode/core/npcmap/sv_npcmap.lua)0
-rw-r--r--gamemode/core/npc/sv_npcsystem.lua39
-rw-r--r--gamemode/inventorysystem/equipment.lua67
-rw-r--r--gamemode/inventorysystem/equipment/cl_equipment.lua140
-rw-r--r--gamemode/inventorysystem/equipment/sh_equipment.lua180
-rw-r--r--gamemode/inventorysystem/equipment/sv_equipment.lua5
-rw-r--r--gamemode/inventorysystem/prayers/sh_prayers.lua44
-rw-r--r--gamemode/itemsystem/armor/balaclava.lua (renamed from gamemode/shared/itemsystem/armor/balaclava.lua)44
-rw-r--r--gamemode/itemsystem/exampleitem.lua (renamed from gamemode/shared/itemsystem/exampleitem.lua)0
-rw-r--r--gamemode/itemsystem/foodstuffs/ratmeat.lua (renamed from gamemode/shared/itemsystem/foodstuffs/ratmeat.lua)2
-rw-r--r--gamemode/itemsystem/foodstuffs/watermelon.lua (renamed from gamemode/shared/itemsystem/foodstuffs/watermelon.lua)28
-rw-r--r--gamemode/itemsystem/item_common.lua (renamed from gamemode/shared/itemsystem/item_common.lua)0
-rw-r--r--gamemode/itemsystem/quest/rougebadge.lua (renamed from gamemode/shared/itemsystem/quest/rougebadge.lua)2
-rw-r--r--gamemode/itemsystem/quest/rougebook.lua (renamed from gamemode/shared/itemsystem/quest/rougebook.lua)2
-rw-r--r--gamemode/itemsystem/quest/togglechip.lua (renamed from gamemode/shared/itemsystem/quest/togglechip.lua)2
-rw-r--r--gamemode/itemsystem/scrapgun.lua (renamed from gamemode/shared/itemsystem/scrapgun.lua)2
-rw-r--r--gamemode/itemsystem/utility/flashlight.lua (renamed from gamemode/shared/itemsystem/utility/flashlight.lua)2
-rw-r--r--gamemode/itemsystem/weapons/knuckledclaw.lua (renamed from gamemode/shared/itemsystem/weapons/knuckledclaw.lua)2
-rw-r--r--gamemode/itemsystem/weapons/rustyaxe.lua (renamed from gamemode/shared/itemsystem/weapons/rustyaxe.lua)2
-rw-r--r--gamemode/itemsystem/weapons/scraphammer.lua (renamed from gamemode/shared/itemsystem/weapons/scraphammer.lua)2
-rw-r--r--gamemode/itemsystem/weapons/seratedknife.lua (renamed from gamemode/shared/itemsystem/weapons/seratedknife.lua)2
-rw-r--r--gamemode/itemsystem/weapons_common.lua (renamed from gamemode/shared/itemsystem/weapons_common.lua)0
-rw-r--r--gamemode/npcsystem/sv_blockingdummy.lua (renamed from gamemode/shared/npcsystem/blockingdummy.lua)6
-rw-r--r--gamemode/npcsystem/sv_dummy.lua (renamed from gamemode/shared/npcsystem/dummy.lua)4
-rw-r--r--gamemode/npcsystem/sv_rat.lua (renamed from gamemode/shared/npcsystem/rat.lua)5
-rw-r--r--gamemode/nrequire.lua64
-rw-r--r--gamemode/shared/concommands.lua2
-rw-r--r--gamemode/shared/loaditems.lua3
-rw-r--r--gamemode/shared/log.lua2
-rw-r--r--gamemode/shared/sh_setup.lua3
-rw-r--r--gamemode/utility/fn.lua1
-rw-r--r--gamemode/utility/stream.lua2
-rw-r--r--gamemode/utility/svg/cl_svg.lua98
44 files changed, 896 insertions, 358 deletions
diff --git a/gamemode/client/cl_inventory.lua b/gamemode/client/cl_inventory.lua
index 84cb347..390b923 100644
--- a/gamemode/client/cl_inventory.lua
+++ b/gamemode/client/cl_inventory.lua
@@ -1,6 +1,14 @@
--[[
Displays the inventory, for more information see /gamemode/shared/inventory.lua
]]
+--[[
+ Reserved inventory id's
+ 1 - Equipment
+ 2 - Prayers
+]]
+local qinv = nrequire("cl_qinventory.lua")
+local qpray = nrequire("cl_qprayers.lua")
+
print("Hello from cl_inventory.lua")
--debug.Trace()
@@ -15,14 +23,10 @@ end)
local lastpanel = lastpanel or 1
+--A master list of inventory sheets
local inventorysheets = {}
---[[
-ART.RegisterInventorySheet = function(func)
- inventorysheets[#inventorysheets + 1] = func
-end
-]]
-
+--Wether the player is in the inventory or not
local plyisininventory = false
--Displays a dropdown of options under the players mouse, if the option is clicked, does the function
@@ -39,60 +43,60 @@ local function createMenuFor(menu, tbl)
end
end
---[[
-function ART.RefreshDisplays()
- local discopy = LocalPlayer().invdisplays
- LocalPlayer().invdisplays = {}
- for k,ptbl in pairs(discopy) do
- if not ptbl.panel:IsValid() then continue end
- if ptbl.panel.Close ~= nil then
- ptbl.panel:Close()
- else
- print(ptbl.panel)
- error("panel has no close method")
- ptbl.panel:Remove()
- end
- ptbl.redraw()
- end
-end
-]]
+local qframe = nil --The master frame
+local qtabs = {} --The tabs
-local sheet
-function ShowInventory(ply,cmd,args)
- if plyisininventory then return end
- LocalPlayer().invdisplays = LocalPlayer().invdisplays or {}
- plyisininventory = true
- local width = ScrW()
- local height = ScrH()
- local dat = {}
- dat.panel = vgui.Create( "DFrame" )
- dat.redraw = ShowInventory
- table.insert(LocalPlayer().invdisplays,dat)
- local invpanel = dat.panel
- invpanel:SetPos( 0, 0 )
- invpanel:SetSize( width / 4, height )
- invpanel:SetTitle( "Inventory" )
- invpanel:SetDraggable( true )
- invpanel:MakePopup()
- invpanel.OnClose = function(self)
- plyisininventory = false
- end
+local width = ScrW()
+local height = ScrH()
+
+local player_data --The data the player needs to show the q panel
+net.Receive("art_load_player_data",function()
+ print("Got player data")
+ player_data = net.ReadTable()
+ print("It was")
+ PrintTable(player_data)
+end)
- sheet = vgui.Create( "DPropertySheet", invpanel )
- sheet:Dock( FILL )
+local function BuildInventory()
+ print("Building inventory")
+ if qframe then return end
+ if not player_data then print("no player data!") return end
+ qframe = vgui.Create("DFrame")
+ qframe:SetPos(0,0)
+ qframe:SetSize(width/4, height)
+ qframe:SetTitle("Inventory")
+ qframe:SetDraggable(true)
+ qframe:MakePopup()
+ qframe.OnClose = function(self)
+ plyisininventory = false
+ self:Hide()
+ return
+ end
+ local tabsheet = vgui.Create("DPropertySheet",qframe)
+ tabsheet:Dock(FILL)
+
+ local invsheet = qinv.CreateInventorySheet(tabsheet)
+ local invid = #qtabs + 1
+ invsheet.id = invid
+ qtabs[invid] = invsheet
+ tabsheet:AddSheet("Inventory",invsheet,"icon16/user.png")
- for k,v in pairs(inventorysheets) do
- local name,tsheet,image = v()
- sheet:AddSheet(name,tsheet,image)
- tsheet.sheetnum = name
- end
- sheet:SwitchToName(lastpanel)
+end
+
+local function ShowInventory()
+ print("qframe is ", qframe)
+ if not qframe then BuildInventory()
+ else qframe:Show() end
+ plyisininventory = true
end
hook.Add("OnSpawnMenuOpen","ArteryOpenInventory",ShowInventory)
hook.Add("OnSpawnMenuClose","ArteryCloseInventory",function()
+ plyisininventory = false
+ qframe:Hide()
+ if (not sheet) or (not sheet:GetActiveTab()) or (not sheet:GetActiveTab():GetPanel()) then return end
lastpanel = sheet:GetActiveTab():GetPanel().sheetnum
for k,v in pairs(LocalPlayer().invdisplays) do
if not v.panel:IsValid() then continue end
@@ -100,7 +104,6 @@ hook.Add("OnSpawnMenuClose","ArteryCloseInventory",function()
v.panel:Close()
LocalPlayer().invdisplays[k] = nil
end
- plyisininventory = false
end)
concommand.Add("showinventory",ShowInventory)
diff --git a/gamemode/client/cl_weaponswitch.lua b/gamemode/client/cl_weaponswitch.lua
index f7edcfc..085a0b3 100644
--- a/gamemode/client/cl_weaponswitch.lua
+++ b/gamemode/client/cl_weaponswitch.lua
@@ -1,4 +1,6 @@
-function GM:PlayerSwitchWeapon( ply, oldWeapon, newWeapon )
+local gm = GM or GAMEMODE
+
+function gm:PlayerSwitchWeapon( ply, oldWeapon, newWeapon )
return false
end
diff --git a/gamemode/client/hud/cl_svgtest.lua b/gamemode/client/hud/cl_svgtest.lua
new file mode 100644
index 0000000..baeb698
--- /dev/null
+++ b/gamemode/client/hud/cl_svgtest.lua
@@ -0,0 +1,46 @@
+do return end
+local svg = nrequire("cl_svg.lua")
+local mats = {}
+local matstrs = {}
+for i = 2,10 do
+ for _,t in pairs({"clubs","diamonds","hearts","spades"}) do
+ matstrs[#matstrs + 1] = string.format( "materials/svg/aussiesim/cards/svg/000000/transparent/card-%d-%s.svg",i,t)
+ end
+end
+
+for k,v in pairs(matstrs) do
+ mats[k] = file.Read(v,"GAME")
+end
+local truemats = {}
+for k,v in pairs(matstrs) do
+ truemats[k] = svg.MaterialFromSVG(v)
+end
+--local parsed = xmlparser:parse(matstr)
+local htmls = {}
+local nx = ScrW()/64
+local ny = ScrH()/64
+for x = 1,nx do
+ for y = 1,ny do
+ local thtml = vgui.Create("DSprite") --svg.SvgOnDpanel("materials/svg/aussiesim/cards/svg/000000/transparent/card-2-clubs.svg")
+ thtml:SetSize(64,64)
+ thtml:SetPos(x * 64,y * 64)
+ htmls[y * nx + x] = thtml
+ end
+end
+
+hook.Add("HUDPaint","paint_svg",function()
+ --local randommat = table.Random(matstrs)
+ --html:RunJavascript( string.format("document.body.innerHTML = 'HTML changed from Lua using JavaScript!';"" )
+ --[[
+ for k,v in pairs(htmls) do
+ v:UpdateImage(randommat)
+ end
+ ]]
+
+ for k,v in pairs(htmls) do
+ local randommat = table.Random(truemats)
+ if randommat.material then
+ v:SetMaterial(randommat.material)
+ end
+ end
+end)
diff --git a/gamemode/client/qtabs/cl_qinventory.lua b/gamemode/client/qtabs/cl_qinventory.lua
new file mode 100644
index 0000000..a3f8a16
--- /dev/null
+++ b/gamemode/client/qtabs/cl_qinventory.lua
@@ -0,0 +1,69 @@
+--[[
+ One of the tabs in the inventory
+]]
+
+local inv = nrequire("inventory/inventory.lua")
+local itm = nrequire("item.lua")
+
+local q = {}
+
+local known_inventories = {}
+local inventory_frames = {}
+
+net.Receive("art_ObserveInventory",function()
+ local id = net.ReadUInt(32)
+ local inv_type = net.ReadString()
+ print("Got inv type", inv_type,"id",id)
+ local inital_data = net.ReadData(net.ReadUInt(32))
+ known_inventories[id] = inv.CreateInventoryFromData(inv_type,initaldata)
+end)
+
+net.Receive("art_UpdateInventory",function()
+ local id = net.ReadUInt(32)
+ local isput = net.ReadBool()
+ local position = net.ReadTable()
+ if isput then
+ local item_name = net.ReadString()
+ local item_data = net.ReadData(net.ReadUInt(32))
+ local item = itm.GetItemFromData(item_name,item_data)
+ known_inventories[id]:Put(position,item)
+ else
+ known_inventories[id]:Remove(position)
+ end
+end)
+
+net.Receive("art_CloseInventory",function()
+ local id = net.ReadUInt(32)
+ known_inventories[id] = nil
+ if inventory_frames[id] then
+ inventory_frames[id]:Close()
+ inventory_frames[id] = nil
+ end
+end)
+
+local width,height = (ScrW() / 4) - 10, ScrH()
+local iconsize = width / 5
+
+
+q.CreateInventorySheet = function(dpanel_parent)
+ --assert(known_inventories[watch_id] ~= nil,"Attempted to watch an inventory that dosn't exist!")
+ --Display the equipment inventories
+ local invsheet = vgui.Create( "DPropertySheet", dpanel_parent )
+ invsheet:Dock( FILL )
+
+ for k,v in pairs(known_inventories) do
+ local tpanel = vgui.Create( "DPanel", invsheet )
+ tpanel.Paint = function( self, w, h )
+ draw.RoundedBox( 4, 0, 0, w, h, Color( 0, 128, 255 ) )
+ end
+ if v.DrawOnDPanel then
+ local prox = v:DrawOnDPanel(tpanel)
+ known_inventories[k]:AddObserver(prox)
+ end
+ invsheet:AddSheet( v.Name, tpanel, "icon16/tab.png" )
+ end
+
+ return invsheet
+end
+
+return q
diff --git a/gamemode/client/qtabs/cl_qprayers.lua b/gamemode/client/qtabs/cl_qprayers.lua
new file mode 100644
index 0000000..9f1b9ab
--- /dev/null
+++ b/gamemode/client/qtabs/cl_qprayers.lua
@@ -0,0 +1,8 @@
+
+local p = {}
+
+function p.CreatePrayerSheet(dpanel_parent)
+
+end
+
+return p
diff --git a/gamemode/client/vgui/vgui_DMultiModelPanel.lua b/gamemode/client/vgui/vgui_DMultiModelPanel.lua
deleted file mode 100644
index 37d0883..0000000
--- a/gamemode/client/vgui/vgui_DMultiModelPanel.lua
+++ /dev/null
@@ -1,161 +0,0 @@
-local PANEL = {}
-
-AccessorFunc( PANEL, "m_fAnimSpeed", "AnimSpeed" )
-AccessorFunc( PANEL, "vCamPos", "CamPos" )
-AccessorFunc( PANEL, "fFOV", "FOV" )
-AccessorFunc( PANEL, "vLookatPos", "LookAt" )
-AccessorFunc( PANEL, "aLookAngle", "LookAng" )
-AccessorFunc( PANEL, "colAmbientLight", "AmbientLight" )
-AccessorFunc( PANEL, "colColor", "Color" )
-AccessorFunc( PANEL, "bAnimated", "Animated" )
-
-function PANEL:Init()
-
- self.Entities = {}
- self.LastPaint = 0
- self.DirectionalLight = {}
- self.FarZ = 4096
-
- self:SetCamPos( Vector( 50, 50, 50 ) )
- self:SetLookAt( Vector( 0, 0, 40 ) )
- self:SetFOV( 70 )
-
- self:SetText( "" )
- self:SetAnimSpeed( 0.5 )
- self:SetAnimated( false )
-
- self:SetAmbientLight( Color( 50, 50, 50 ) )
-
- self:SetDirectionalLight( BOX_TOP, Color( 255, 255, 255 ) )
- self:SetDirectionalLight( BOX_FRONT, Color( 255, 255, 255 ) )
-
- self:SetColor( Color( 255, 255, 255, 255 ) )
-
-end
-
-function PANEL:SetDirectionalLight( iDirection, color )
- self.DirectionalLight[ iDirection ] = color
-end
-
-function PANEL:AddModel( strModelName )
-
- -- Note: Not in menu dll
- if ( !ClientsideModel ) then return end
-
- self.Entities[#self.Entities+1] = ClientsideModel(strModelName, RENDER_GROUP_OPAQUE_ENTITY)
- if ( !IsValid( self.Entities[#self.Entities] ) ) then return end
-
- self.Entities[#self.Entities]:SetNoDraw( true )
- self.Entities[#self.Entities]:SetIK( false )
-
-end
-
-function PANEL:DrawModel()
-
- local curparent = self
- local rightx = self:GetWide()
- local leftx = 0
- local topy = 0
- local bottomy = self:GetTall()
- local previous = curparent
- while( curparent:GetParent() != nil ) do
- curparent = curparent:GetParent()
- local x, y = previous:GetPos()
- topy = math.Max( y, topy + y )
- leftx = math.Max( x, leftx + x )
- bottomy = math.Min( y + previous:GetTall(), bottomy + y )
- rightx = math.Min( x + previous:GetWide(), rightx + x )
- previous = curparent
- end
- render.SetScissorRect( leftx, topy, rightx, bottomy, true )
-
- for k,v in pairs(self.Entities) do
- local ret = self:PreDrawModel( v )
- if ( ret != false ) then
- v:DrawModel()
- self:PostDrawModel( v )
- end
- end
-
- render.SetScissorRect( 0, 0, 0, 0, false )
-
-end
-
-function PANEL:PreDrawModel( ent )
- return true
-end
-
-function PANEL:PostDrawModel( ent )
-
-end
-
-function PANEL:Paint( w, h )
- for k,v in pairs(self.Entities) do
- if ( !IsValid( v ) ) then continue end
-
- local x, y = self:LocalToScreen( 0, 0 )
-
- self:LayoutEntity( v )
-
- local ang = self.aLookAngle
- if ( !ang ) then
- ang = ( self.vLookatPos - self.vCamPos ):Angle()
- end
-
- cam.Start3D( self.vCamPos, ang, self.fFOV, x, y, w, h, 5, self.FarZ )
-
- render.SuppressEngineLighting( true )
- render.SetLightingOrigin( v:GetPos() )
- render.ResetModelLighting( self.colAmbientLight.r / 255, self.colAmbientLight.g / 255, self.colAmbientLight.b / 255 )
- render.SetColorModulation( self.colColor.r / 255, self.colColor.g / 255, self.colColor.b / 255 )
- render.SetBlend( ( self:GetAlpha() / 255 ) * ( self.colColor.a / 255 ) )
-
- for i = 0, 6 do
- local col = self.DirectionalLight[ i ]
- if ( col ) then
- render.SetModelLighting( i, col.r / 255, col.g / 255, col.b / 255 )
- end
- end
-
- self:DrawModel()
-
- render.SuppressEngineLighting( false )
- cam.End3D()
-
- self.LastPaint = RealTime()
- end
-end
-
---[[
-function PANEL:StartScene( name )
-
- if ( IsValid( self.Scene ) ) then
- self.Scene:Remove()
- end
-
- self.Scene = ClientsideScene( name, self.Entity )
-
-end
-]]
-
-function PANEL:LayoutEntity( Entity )
-
- --
- -- This function is to be overriden
- --
-
- if ( self.bAnimated ) then
- self:RunAnimation()
- end
- Entity:SetAngles( Angle( 0, RealTime() * 10 % 360, 0 ) )
-
-end
-
-function PANEL:OnRemove()
- for k,v in pairs(self.Entities) do
- v:Remove()
- self.Entities[k] = nil
- end
-end
-
-derma.DefineControl( "DModelPanel", "A panel containing a model", PANEL, "DModelPanel" )
diff --git a/gamemode/config/colortheme.lua b/gamemode/config/colortheme.lua
index ac803cc..f54fdd7 100644
--- a/gamemode/config/colortheme.lua
+++ b/gamemode/config/colortheme.lua
@@ -26,4 +26,8 @@ theme.console = {
black_bold = Color(40,44,54),
}
+theme.ui = {
+ border = Color(113,113,113)
+}
+
return theme
diff --git a/gamemode/core/inventory/inventory.lua b/gamemode/core/inventory/inventory.lua
index 59c2bba..f6e8f9c 100644
--- a/gamemode/core/inventory/inventory.lua
+++ b/gamemode/core/inventory/inventory.lua
@@ -50,8 +50,8 @@ local inventories = {} --Master list
local function DefaultAddObserver(self,tbl)
if self.observers == nil then self.observers = {} end
- self.observers[#observers + 1] = tbl
- return #observers
+ self.observers[#self.observers + 1] = tbl
+ return #self.observers
end
local function DefaultRemoveObserver(self,observer_id)
for i = observer_id, #self.observers do
@@ -98,7 +98,7 @@ function inv.RegisterInventory(tbl)
string.format("Attempted to register inventory with field %q of type %q when it should have been %q",v[1],type(tbl[v[1]]),v[2]))
end
assert(inventories[tbl.Name] == nil,
- "Attempted to register 2 inventories with the same name")
+ "Attempted to register 2 inventories with the same name:" .. tbl.Name)
assert((tbl.AddObserver == nil and tbl.RemoveObserver == nil) or
(tbl.AddObserver ~= nil and tbl.RemoveObserver ~= nil),
"AddObserver and RemoveObserver must be defined in pairs")
@@ -106,17 +106,19 @@ function inv.RegisterInventory(tbl)
SetDefaultObservers(tbl)
end
inventories[tbl.Name] = tbl
- log.debug("Registered item: " .. tbl.Name)
+ log.debug("Registered inventory: " .. tbl.Name .. "\n")
end
--Create an inventory
function inv.CreateInventory(name)
- return table_copy(inventories[name])
+ print("Createing inventory", name)
+ assert(inventories[name] ~= nil, string.format("Tried to create a copy of inventory that does not exist:%s\nValid inventories are:\n\t%s",name,table.concat(table.GetKeys(inventories),"\n\t")))
+ return TableCopy(inventories[name])
end
--Recreates an inventory from data
function inv.CreateInventoryFromData(name,data)
- return create_inventory(name):DeSerialize(data)
+ return inv.CreateInventory(name):DeSerialize(data)
end
--Must be called in a coroutine.
diff --git a/gamemode/core/inventory/item.lua b/gamemode/core/inventory/item.lua
index ef6ec1d..86bd105 100644
--- a/gamemode/core/inventory/item.lua
+++ b/gamemode/core/inventory/item.lua
@@ -18,6 +18,8 @@
Items may also have methods from one or more interfaces registered with RegisterInterface
]]
local log = nrequire("log.lua")
+print("in item.lua, log is:")
+PrintTable(log)
local itm = {}
local required_fields = {
@@ -30,7 +32,7 @@ function itm.RegisterItem(tbl)
assert(tbl[v] ~= nil, string.format("Attempted to register item without field %q",v))
end
assert(items[tbl.Name] == nil, string.format("Attempted to register 2 items with the same name %q",tbl.Name))
- log.debug("Registered item: " .. tbl.Name)
+ log.debug("Registered item: " .. tbl.Name .. "\n")
end
function itm.GetItemByName(name)
diff --git a/gamemode/core/inventory/sv_invtracker.lua b/gamemode/core/inventory/sv_invtracker.lua
new file mode 100644
index 0000000..3bb2b37
--- /dev/null
+++ b/gamemode/core/inventory/sv_invtracker.lua
@@ -0,0 +1,80 @@
+--[[
+ some accessability functions
+]]
+
+local inv = nrequire("inventory/inventory.lua")
+local itm = nrequire("item.lua")
+
+for k,v in pairs({
+ "art_ObserveInventory",
+ "art_UpdateInventory",
+ "art_CloseInventory",
+ "art_load_player_data",
+ "art_RequestInvMove",
+}) do util.AddNetworkString(v) end
+--[[
+net.Receive("art_ObserveInventory",function()
+ local id = net.ReadUInt(32)
+ local inv_type = net.ReadString()
+ local inital_data = net.ReadData(net.ReadUInt(32))
+ known_inventories[id] = inv.CreateInventoryFromData(inv_type,initaldata)
+end)
+]]
+
+--[[
+ Moves an item from one position to another, format:
+ froment ::entity
+ toent ::entity
+ frominvid ::int32
+ toinvid ::int32
+ frompos ::table
+ topos ::table
+]]
+net.Receive("art_RequestInvMove",function(len,ply)
+ print("ply",ply,"requested inv move")
+ local froment,toent = net.ReadEntity(),net.ReadEntity()
+ local frominvid,toinvid = net.ReadUInt(32),net.ReadUInt(32)
+ local frompos,topos = net.ReadTable(),net.ReadTable()
+ --Make sure the player is not stealing!
+ assert(not (froment:IsPlayer() and toent:IsPlayer()), "Tried to move item between players!")
+ assert(froment.data ~= nil and froment.data.inventories ~= nil and froment.data.inventories[frominvid] ~= nil, "From entity did not have that inventory!")
+ assert(toent.data ~= nil and toent.data.inventories ~= nil and toent.data.inventories[toinvid] ~= nil, "To entity did not have that inventory!")
+ local frominv = froment.data.inventories[frominvid]
+ local toinv = toent.data.inventories[toinvid]
+ local item = frominv:Get(frompos)
+ assert(item ~= nil, "Could not find an item at that position!")
+ assert(toinv:CanFitIn(topos,item), "Could not fit the item in that position!")
+ --If we've gotten here without error, we're all good! Move the item!
+ frominv:Remove(frompos)
+ toinv:Put(topos)
+end)
+
+local slots = {
+ "inv_Head",
+ "inv_Shoulders",
+ "inv_Chest",
+ "inv_Arms",
+ "inv_Hands",
+ "inv_Legs",
+ "inv_Belt",
+ "inv_Feet",
+ "inv_Back",
+}
+
+concommand.Add("SendMeData",function(ply,cmd,args)
+ local i = inv.CreateInventory("Equipment")
+ if not ply.data then ply.data = {} end
+ if not ply.data.inventories then ply.data.inventories = {} end
+ ply.data.inventories[1] = i
+ net.Start("art_ObserveInventory")
+ net.WriteUInt(1,32)
+ net.WriteString("Equipment")
+ local data = i:Serialize()
+ net.WriteUInt(#data,32)
+ net.WriteData(data,#data)
+ net.Send(ply)
+
+ net.Start("art_load_player_data")
+ net.WriteTable({})
+ net.Send(ply)
+end)
diff --git a/gamemode/core/npcmap/cl_npcmap.lua b/gamemode/core/npc/cl_npcmap.lua
index 5a9de7e..5a9de7e 100644
--- a/gamemode/core/npcmap/cl_npcmap.lua
+++ b/gamemode/core/npc/cl_npcmap.lua
diff --git a/gamemode/core/npcmap/sv_npcmap.lua b/gamemode/core/npc/sv_npcmap.lua
index 8368484..8368484 100644
--- a/gamemode/core/npcmap/sv_npcmap.lua
+++ b/gamemode/core/npc/sv_npcmap.lua
diff --git a/gamemode/core/npc/sv_npcsystem.lua b/gamemode/core/npc/sv_npcsystem.lua
new file mode 100644
index 0000000..b41f4e6
--- /dev/null
+++ b/gamemode/core/npc/sv_npcsystem.lua
@@ -0,0 +1,39 @@
+
+local f = nrequire("concommands.lua")
+local n = {}
+local npcs = {} --Master table of npcs
+local autocompletef
+
+function n.RegisterNPC(npc)
+ assert(npc ~= nil, "Attempted to register a nil npc")
+ assert(npc.Name ~= nil, "Attempted to register an npc without a name")
+ npcs[npc.Name] = npc
+ autocompletef = f.AutocompleteFunction(npcs)
+end
+
+function n.CreateNPCByName(npcname, pos)
+ print("Createing a " ,npcname ," at ", pos)
+ local npctbl = npcs[npcname]
+ local npc = ents.Create("npc_huntable")
+ npc:SetPos(pos)
+ for k,v in pairs(npctbl) do
+ npc[k] = v
+ end
+ npc:Spawn()
+ return npc
+end
+
+
+if SERVER then
+ autocompletef = nil
+else
+ autocompletef = f.AutocompleteFunction(npcs)
+end
+concommand.Add("artery_makenpc",function(ply,cmd,args)
+ if not ply:IsAdmin() then return end
+ local na = args[1]
+ n.CreateNPCByName(na,ply:GetEyeTrace().HitPos)
+end,
+autocompletef)
+
+return n
diff --git a/gamemode/inventorysystem/equipment.lua b/gamemode/inventorysystem/equipment.lua
deleted file mode 100644
index 710c6b8..0000000
--- a/gamemode/inventorysystem/equipment.lua
+++ /dev/null
@@ -1,67 +0,0 @@
---[[
- A simple inventory that holds 1 item
-]]
-local itm = nrequire("item.lua")
-local ste = nrequire("utility/stream.lua")
-local inventory = nrequire("inventory/inventory.lua")
-local slots = {
- "Head",
- "Shoulders",
- "Chest",
- "Arms",
- "Hands",
- "Legs",
- "Belt",
- "Feet",
- "Back",
-}
-
-for k,v in pairs(slots) do
- local inv = {}
- inv.Name = "inv_" .. v
- inv.FindPlaceFor = function(self, item)
- if self.item == nil then return {} else return nil end
- end
- inv.CanFitIn = function(self,position,item)
- if self.item == nil then return true else return "Inventory slot occupied by a(n)" .. self.item.Name end
- end
- inv.Put = function(self,pos,item)
- self.item = item
- end
- inv.Has = function(self,prt)
- if type(prt) == "string" then
- if self.item ~= nil and self.item.Name == prt then return {} else return nil end
- elseif type(prt) == "function" then
- if prt(self.item) then return {} else return nil end
- end
- error(string.format("Passed a %s to %s:Has(), expected string or function",type(prt),self.Name))
- end
- inv.Remove = function(self,pos)
- self.item = nil
- end
- inv.Get = function(self,pos)
- return self.item
- end
- inv.Serialize = function(self)
- if self.item then
- local data = ste.CreateStream()
- local itemname = self.item.Name
- local itemdata = self.item:Serialize()
- data:WriteString(itemname)
- data:WriteString(itemdata)
- return data:ToString()
- end
- return ""
- end
- inv.DeSerialize = function(self,str)
- if str == "" then
- return table.Copy(self)
- else
- local data = ste.CreateStream(str)
- local itemname = data:ReadString()
- local itemdata = data:ReadString()
- self.item = itm.GetItemFromData(itemname,itemdata)
- end
- end
- inventory.RegisterInventory(inv)
-end
diff --git a/gamemode/inventorysystem/equipment/cl_equipment.lua b/gamemode/inventorysystem/equipment/cl_equipment.lua
new file mode 100644
index 0000000..5ffcccc
--- /dev/null
+++ b/gamemode/inventorysystem/equipment/cl_equipment.lua
@@ -0,0 +1,140 @@
+
+local col = nrequire("colortheme.lua")
+local svg = nrequire("cl_svg.lua")
+local inv = {}
+
+local width, height = (ScrW() / 4) - 25, ScrH()
+local iconsize = width / 5
+
+local ringmat = svg.MaterialFromSVG("materials/svg/delapouite/originals/svg/000000/transparent/ring.svg")
+
+--Positions for the eqipment inventory
+local eqp = {
+ ["Head"] = {
+ x = (width / 2) - (iconsize / 2),
+ y = 0,
+ img = svg.MaterialFromSVG("materials/svg/lorc/originals/svg/000000/transparent/cracked-helm.svg"),
+ },
+ ["Shoulders"] = {
+ x = (width / 2) - (iconsize / 2),
+ y = iconsize,
+ img = svg.MaterialFromSVG("materials/svg/skoll/originals/svg/000000/transparent/pauldrons.svg")
+ },
+ ["Chest"] = {
+ x = width / 2,
+ y = iconsize * 2,
+ img = svg.MaterialFromSVG("materials/svg/willdabeast/deviations/svg/000000/transparent/chain-mail.svg")
+ },
+ ["Back"] = {
+ x = (width / 2) - iconsize,
+ y = iconsize * 2,
+ img = svg.MaterialFromSVG("materials/svg/lorc/originals/svg/000000/transparent/knapsack.svg"),
+ },
+ ["Arms"] = {
+ x = (width / 2) - (iconsize / 2),
+ y = iconsize * 3,
+ img = svg.MaterialFromSVG("materials/svg/skoll/originals/svg/000000/transparent/bracers.svg")
+ },
+ ["Belt"] = {
+ x = (width / 2) - (iconsize * 1.5),
+ y = iconsize * 3,
+ img = svg.MaterialFromSVG("materials/svg/lucasms/equipment/svg/000000/transparent/belt.svg")
+ },
+ ["Gloves"] = {
+ x = (width / 2) + (iconsize / 2),
+ y = iconsize * 3,
+ img = svg.MaterialFromSVG("materials/svg/delapouite/originals/svg/000000/transparent/gloves.svg")
+ },
+ ["Left Hand"] = {
+ x = width / 2,
+ y = iconsize * 4,
+ img = svg.MaterialFromSVG("materials/svg/sbed/originals/svg/000000/transparent/shield.svg")
+ },
+ ["Right Hand"] = {
+ x = (width / 2) - iconsize,
+ y = iconsize * 4,
+ img = svg.MaterialFromSVG("materials/svg/delapouite/originals/svg/000000/transparent/thor-hammer.svg")
+ },
+ ["Legs"] = {
+ x = (width / 2) - iconsize,
+ y = iconsize * 5,
+ img = svg.MaterialFromSVG("materials/svg/irongamer/originals/svg/000000/transparent/armored-pants.svg")
+ },
+ ["Feet"] = {
+ x = width / 2,
+ y = iconsize * 5,
+ img = svg.MaterialFromSVG("materials/svg/lorc/originals/svg/000000/transparent/boots.svg"),
+ },
+ ["Ring 1"] = {
+ x = 0,
+ y = iconsize,
+ img = ringmat
+ },
+ ["Ring 2"] = {
+ x = width - iconsize,
+ y = iconsize,
+ img = ringmat
+ },
+ ["Ring 3"] = {
+ x = 0,
+ y = iconsize * 2.5,
+ img = ringmat
+ },
+ ["Ring 4"] = {
+ x = width - iconsize,
+ y = iconsize * 2.5,
+ img = ringmat
+ },
+ ["Ring 5"] = {
+ x = 0,
+ y = iconsize * 4,
+ img = ringmat
+ },
+ ["Ring 6"] = {
+ x = width - iconsize,
+ y = iconsize * 4,
+ img = ringmat
+ },
+}
+
+inv.DrawOnDPanel = function(self,panel)
+ local prox = {}
+ for k,v in pairs(eqp) do
+ local pn = vgui.Create("DImage",panel)
+ pn:SetSize(iconsize,iconsize)
+ pn:SetPos(v.x,v.y)
+ if self.equiped[k] then
+ if self.equiped[k].OnPaint then
+ pn.Paint = self.equiped[k].OnPaint
+ else
+ pn.Paint = function(tp,w,h)
+ draw.RoundedBox( 8, 0, 0, w, h, Color( 255, 0, 0 ) )
+ end
+ end
+ else
+ if v.img and v.img.material then
+ local c = col.ui.border
+ pn.Paint = function(tp,w,h)
+ surface.SetDrawColor(c.r,c.g,c.b)
+ surface.DrawOutlinedRect(0, 0, w, h)
+ surface.SetDrawColor(255,255,255)
+ surface.SetMaterial( v.img.material )
+ surface.DrawTexturedRect( 0, 0, w, h )
+ end
+ else
+ pn.Paint = function(tp,w,h)
+ draw.RoundedBox( 8, 0, 0, w, h, Color( 0, 0, 0 ) )
+ end
+ end
+ end
+ prox[k] = pn
+ end
+ prox.Put = function(position,item)
+ print("Put was called!")
+ end
+ prox.Remove = function(position)
+ print("Remove was called!")
+ end
+end
+
+return inv
diff --git a/gamemode/inventorysystem/equipment/sh_equipment.lua b/gamemode/inventorysystem/equipment/sh_equipment.lua
new file mode 100644
index 0000000..ca7c22d
--- /dev/null
+++ b/gamemode/inventorysystem/equipment/sh_equipment.lua
@@ -0,0 +1,180 @@
+--[[
+ A simple inventory that holds 1 item
+]]
+local itm = nrequire("item.lua")
+local ste = nrequire("utility/stream.lua")
+local inventory = nrequire("inventory/inventory.lua")
+print("Got invnetory table, it is:")
+PrintTable(inventory)
+local slots = {
+ "Head",
+ "Shoulders",
+ "Chest",
+ "Arms",
+ "Left Hand",
+ "Right Hand",
+ "Dual",
+ "Legs",
+ "Belt",
+ "Gloves",
+ "Feet",
+ "Back",
+ "Ring 1",
+ "Ring 2",
+ "Ring 3",
+ "Ring 4",
+ "Ring 5",
+ "Ring 6",
+}
+
+local inv = {}
+if SERVER then inv = nrequire("sv_equipment.lua") end
+if CLIENT then inv = nrequire("cl_equipment.lua") end
+
+inv.Name = "Equipment"
+inv.equiped = {}
+inv.FindPlaceFor = function(self, item)
+ --Make sure it's equipable
+ if not item.Equipable then return nil end
+
+ --If this is a dual weielding weapon
+ if item.Equipable == "Dual" then
+ if self.equiped["Left Hand"] == nil and self.equiped["Right Hand"] == nil then
+ return {"Dual"}
+ else
+ return nil
+ end
+ end
+
+ --If this item is a left or right handed, make sure we don't have a dual equiped
+ if item.Equipable == "Left Hand" or item.Equipable == "Right Hand" then
+ if self.equiped["Dual"] ~= nil then return nil
+ elseif self.equiped[item.Equipable] ~= nil then return nil
+ else return {item.Equipable} end
+ end
+
+ --If this item is a ring
+ if item.Equipable == "Ring" then
+ for i = 1,6 do
+ if self.equiped["Ring " .. i] == nil then
+ return {"Ring " .. i}
+ end
+ end
+ return nil
+ end
+
+ --Otherwise, just check if the slot is empty
+ if self.equiped[item.Equipable] == nil then
+ return {item.Equipable}
+ else
+ return nil
+ end
+end
+
+inv.CanFitIn = function(self,position,item)
+ return (position[1] == item.Equipable) and (self.equiped[position[1]] == nil)
+end
+
+inv.Put = function(self,position,item)
+ self.equiped[position[1]] = item
+end
+
+inv.Has = function(self,string_or_compare_func)
+ if type(string_or_compare_func) == "string" then
+ for k,v in pairs(self.equiped) do
+ if v.Name == string_or_compare_func then return k end
+ end
+ return nil
+ elseif type(string_or_compare_func) == "function" then
+ for k,v in pairs(self.equiped) do
+ if string_or_compare_func(v.Name) then return k end
+ end
+ return nil
+ end
+ error(string.format("equipment:Has() called with a %s, expected string or function.",type(string_or_compare_func)))
+end
+
+inv.Remove = function(self,position)
+ self.equiped[position[1]] = nil
+end
+
+inv.Get = function(self,position)
+ return self.equiped[position[1]]
+end
+
+inv.Serialize = function(self)
+ local tbl = {}
+ for k,v in pairs(self.equiped) do
+ tbl[k] = v:Serialize()
+ end
+ return util.TableToJSON(tbl)
+end
+
+inv.DeSerialize = function(self,data)
+ print("deserializeing, data was",data)
+ if data ~= nil and data ~= "" then
+ local tbl = util.JSONToTable(data)
+ local cpy = table.Copy(self)
+ for k,v in pairs(tbl) do
+ cpy.equiped[k] = itm.GetItemFromData(v)
+ end
+ else
+ return table.Copy(self)
+ end
+end
+
+inventory.RegisterInventory(inv)
+
+--[[
+for k,v in pairs(slots) do
+ local inv = {}
+ inv.Name = "inv_" .. v
+ inv.FindPlaceFor = function(self, item)
+ if self.item == nil then return {} else return nil end
+ end
+ inv.CanFitIn = function(self,position,item)
+ if self.item == nil then return true else return "Inventory slot occupied by a(n)" .. self.item.Name end
+ end
+ inv.Put = function(self,pos,item)
+ self.item = item
+ end
+ inv.Has = function(self,prt)
+ if type(prt) == "string" then
+ if self.item ~= nil and self.item.Name == prt then return {} else return nil end
+ elseif type(prt) == "function" then
+ if prt(self.item) then return {} else return nil end
+ end
+ error(string.format("Passed a %s to %s:Has(), expected string or function",type(prt),self.Name))
+ end
+ inv.Remove = function(self,pos)
+ self.item = nil
+ end
+ inv.Get = function(self,pos)
+ return self.item
+ end
+ inv.Serialize = function(self)
+ if self.item then
+ local data = ste.CreateStream()
+ local itemname = self.item.Name
+ local itemdata = self.item:Serialize()
+ data:WriteString(itemname)
+ data:WriteString(itemdata)
+ return data:ToString()
+ end
+ return ""
+ end
+ inv.DeSerialize = function(self,str)
+ print("data was",str)
+ if str == "" or str == nil then
+ return table.Copy(self)
+ else
+ local data = ste.CreateStream(str)
+ local itemname = data:ReadString()
+ local itemdata = data:ReadString()
+ self.item = itm.GetItemFromData(itemname,itemdata)
+ end
+ end
+ print("Attempting to register inventory with the name " .. inv.Name)
+ inventory.RegisterInventory(inv)
+end
+]]
diff --git a/gamemode/inventorysystem/equipment/sv_equipment.lua b/gamemode/inventorysystem/equipment/sv_equipment.lua
new file mode 100644
index 0000000..2189122
--- /dev/null
+++ b/gamemode/inventorysystem/equipment/sv_equipment.lua
@@ -0,0 +1,5 @@
+--[[
+ Needed so the includer dosn't freak out
+]]
+
+return {}
diff --git a/gamemode/inventorysystem/prayers/sh_prayers.lua b/gamemode/inventorysystem/prayers/sh_prayers.lua
new file mode 100644
index 0000000..208540d
--- /dev/null
+++ b/gamemode/inventorysystem/prayers/sh_prayers.lua
@@ -0,0 +1,44 @@
+
+local reg = nrequire("inventory.lua")
+local itm = nrequire("item.lua")
+local inv = {}
+inv.Name = "Prayers"
+inv.track = {}
+function inv:FindPlaceFor(item)
+ return {#track}
+end
+function inv:CanFitIn(pos,item)
+ return pos[1] == #self.track
+end
+function inv:Put(pos,item)
+ self.track[pos[1]] = item
+end
+function inv:Has(a)
+ if type(a) == "string" then
+ for k,v in pairs(self.track) do
+ if v == a then return {k} end
+ end
+ elseif type(a) == "function" then
+ for k,v in pairs(self.track) do
+ if a(v) then return {k} end
+ end
+ end
+ return nil
+end
+function inv:Remove(pos)
+ for i = 1,pos[1] do
+ self.track[i] = self.track[i+1]
+ end
+end
+function inv:Get(pos)
+ return self.track[pos[1]]
+end
+function inv:Serialize()
+ local ret = {}
+ for k,v in pairs(self.track) do
+ ret[v.Name] = v:Serialize()
+ end
+end
+
+
+reg.RegisterInventory(inv)
diff --git a/gamemode/shared/itemsystem/armor/balaclava.lua b/gamemode/itemsystem/armor/balaclava.lua
index 8b4b8d2..dd0ec83 100644
--- a/gamemode/shared/itemsystem/armor/balaclava.lua
+++ b/gamemode/itemsystem/armor/balaclava.lua
@@ -11,32 +11,32 @@ item.Tooltip = "Something to cover your face"
--Required Returns the data needed to rebuild this item, should only contain the minimum data nessessary since this gets sent over the network
item.Serialize = function(self)
- print("Trying to serailize!")
- return ""
+ print("Trying to serailize!")
+ return ""
end
--Required, Rebuilds the item from data created in Serialize, if the item is different from the "main" copy of the item, it should retun a tabl.Copy(self), with the appropriate fields set.
item.DeSerialize = function(self,string)
- print("Trying to deserialize!")
- return self
+ print("Trying to deserialize!")
+ return self
end
--Optional, when the player clicks this item, a menu will show up, if the menu item is clicked, the function is ran. This is all run client side, so if you want it to do something, you'll need to use the net library.
function item.GetOptions(self)
- local options = {}
- options["test"] = function() print("You pressed test!") end
- options["toste"] = function() print("You pressed toste!") end
- options["drop"] = ART.DropItem(self)
- return options
+ local options = {}
+ options["test"] = function() print("You pressed test!") end
+ options["toste"] = function() print("You pressed toste!") end
+ options["drop"] = ART.DropItem(self)
+ return options
end
function item.DoOnPanel(dimagebutton)
- dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png")
+ dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png")
end
function item.DoOnEqupPanel(dimagebutton)
- print("called with panel:",panel)
- dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png")
+ print("called with panel:",panel)
+ dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png")
end
--[[
@@ -53,8 +53,8 @@ end
--Required, the shape of this item.
item.Shape = {
- {true,true},
- {true,true},
+ {true,true},
+ {true,true},
}
--Optional, If this item can be equiped in any player slots, put them here.
@@ -62,19 +62,19 @@ item.Equipable = "Head"
--Optional, if we should do something special on equip(like draw the PAC for this weapon)
item.onEquip = function(self,who)
- print("onEquip",who)
- if CLIENT then print("onEquip client!") end
- if SERVER then
- PrintTable(pac)
- ART.ApplyPAC(who,"balaclava")
- end
+ print("onEquip",who)
+ if CLIENT then print("onEquip client!") end
+ if SERVER then
+ PrintTable(pac)
+ ART.ApplyPAC(who,"balaclava")
+ end
end
--Optional, if we should do something speical on unequip(like setting animations back to normal)
item.onUnEquip = function(self,who)
- ART.RemovePAC(who,"balaclava")
+ ART.RemovePAC(who,"balaclava")
end
print("Hello from balaclava.lua")
--Don't forget to register the item!
-ART.RegisterItem(item)
+nrequire("item.lua").RegisterItem(item)
diff --git a/gamemode/shared/itemsystem/exampleitem.lua b/gamemode/itemsystem/exampleitem.lua
index 066e107..066e107 100644
--- a/gamemode/shared/itemsystem/exampleitem.lua
+++ b/gamemode/itemsystem/exampleitem.lua
diff --git a/gamemode/shared/itemsystem/foodstuffs/ratmeat.lua b/gamemode/itemsystem/foodstuffs/ratmeat.lua
index 5310fe2..0198e87 100644
--- a/gamemode/shared/itemsystem/foodstuffs/ratmeat.lua
+++ b/gamemode/itemsystem/foodstuffs/ratmeat.lua
@@ -43,4 +43,4 @@ item.onDropped = function(self, ent)
ART.ApplyPAC(ent,"ratmeat")
end
--Don't forget to register the item!
-ART.RegisterItem(item)
+nrequire("item.lua").RegisterItem(item)
diff --git a/gamemode/shared/itemsystem/foodstuffs/watermelon.lua b/gamemode/itemsystem/foodstuffs/watermelon.lua
index 2b9f7cb..851cf1f 100644
--- a/gamemode/shared/itemsystem/foodstuffs/watermelon.lua
+++ b/gamemode/itemsystem/foodstuffs/watermelon.lua
@@ -11,45 +11,45 @@ item.Tooltip = "Where do they grow these in an apocolyptic wasteland???"
--Required Returns the data needed to rebuild this item, should only contain the minimum data nessessary since this gets sent over the network
item.Serialize = function(self)
- print("Trying to serailize!")
- return ""
+ print("Trying to serailize!")
+ return ""
end
--Required, Rebuilds the item from data created in Serialize, if the item is different from the "main" copy of the item, it should retun a tabl.Copy(self), with the appropriate fields set.
item.DeSerialize = function(self,string)
- print("Trying to deserialize!")
- return self
+ print("Trying to deserialize!")
+ return self
end
if SERVER then
util.AddNetworkString("eat_watermelon")
net.Receive("eat_watermelon", function(len,ply)
local row,col,bp = ply:HasItem("Watermelon")
- if row and col and bp then
- ply:RemoveItemAt(bp,row,col)
+ if row and col and bp then
+ ply:RemoveItemAt(bp,row,col)
end
end)
end
--Optional, when the player clicks this item, a menu will show up, if the menu item is clicked, the function is ran. This is all run client side, so if you want it to do something server side, you'll need to use the net library. Remember that items are in the shared domain, so you can define what it does in the same file!
function item.GetOptions(self)
- local options = {}
- options["eat"] = function()
+ local options = {}
+ options["eat"] = function()
net.Start("eat_watermelon")
net.SendToServer()
end
- return options
+ return options
end
--Required, the shape of this item in a backpack.
item.Shape = {
- {true,true,true},
- {true,true,true},
- {true,true,true},
+ {true,true,true},
+ {true,true,true},
+ {true,true,true},
}
item.onDropped = function(self, ent)
- ART.ApplyPAC(ent,"Watermelon")
+ ART.ApplyPAC(ent,"Watermelon")
end
print("Hello from exampleitem.lua")
--Don't forget to register the item!
-ART.RegisterItem(item)
+nrequire("item.lua").RegisterItem(item)
diff --git a/gamemode/shared/itemsystem/item_common.lua b/gamemode/itemsystem/item_common.lua
index b4b7cce..b4b7cce 100644
--- a/gamemode/shared/itemsystem/item_common.lua
+++ b/gamemode/itemsystem/item_common.lua
diff --git a/gamemode/shared/itemsystem/quest/rougebadge.lua b/gamemode/itemsystem/quest/rougebadge.lua
index dad0f71..d5e2950 100644
--- a/gamemode/shared/itemsystem/quest/rougebadge.lua
+++ b/gamemode/itemsystem/quest/rougebadge.lua
@@ -35,4 +35,4 @@ item.Shape = {
}
-ART.RegisterItem(item)
+nrequire("item.lua").RegisterItem(item)
diff --git a/gamemode/shared/itemsystem/quest/rougebook.lua b/gamemode/itemsystem/quest/rougebook.lua
index 4eabe06..7afb5db 100644
--- a/gamemode/shared/itemsystem/quest/rougebook.lua
+++ b/gamemode/itemsystem/quest/rougebook.lua
@@ -65,4 +65,4 @@ item.onDropped = function(self, ent)
ART.ApplyPAC(ent,"book1")
end
-ART.RegisterItem(item)
+nrequire("item.lua").RegisterItem(item)
diff --git a/gamemode/shared/itemsystem/quest/togglechip.lua b/gamemode/itemsystem/quest/togglechip.lua
index 7b8ee04..d920497 100644
--- a/gamemode/shared/itemsystem/quest/togglechip.lua
+++ b/gamemode/itemsystem/quest/togglechip.lua
@@ -21,4 +21,4 @@ item.Shape = {
}
print("Hello from togglechip.lua")
-ART.RegisterItem(item)
+nrequire("item.lua").RegisterItem(item)
diff --git a/gamemode/shared/itemsystem/scrapgun.lua b/gamemode/itemsystem/scrapgun.lua
index bf21b42..66222d5 100644
--- a/gamemode/shared/itemsystem/scrapgun.lua
+++ b/gamemode/itemsystem/scrapgun.lua
@@ -57,4 +57,4 @@ end
print("Hello from scrapgun.lua")
--Don't forget to register the item!
-ART.RegisterItem(item)
+nrequire("item.lua").RegisterItem(item)
diff --git a/gamemode/shared/itemsystem/utility/flashlight.lua b/gamemode/itemsystem/utility/flashlight.lua
index 9f2cc69..9a87a75 100644
--- a/gamemode/shared/itemsystem/utility/flashlight.lua
+++ b/gamemode/itemsystem/utility/flashlight.lua
@@ -85,4 +85,4 @@ end
--Don't forget to register the item!
-ART.RegisterItem(item)
+nrequire("item.lua").RegisterItem(item)
diff --git a/gamemode/shared/itemsystem/weapons/knuckledclaw.lua b/gamemode/itemsystem/weapons/knuckledclaw.lua
index 2db8117..2f629f6 100644
--- a/gamemode/shared/itemsystem/weapons/knuckledclaw.lua
+++ b/gamemode/itemsystem/weapons/knuckledclaw.lua
@@ -160,4 +160,4 @@ end
print("Hello from scrapgun.lua")
--Don't forget to register the item!
-ART.RegisterItem(item)
+nrequire("item.lua").RegisterItem(item)
diff --git a/gamemode/shared/itemsystem/weapons/rustyaxe.lua b/gamemode/itemsystem/weapons/rustyaxe.lua
index b26597c..04e54de 100644
--- a/gamemode/shared/itemsystem/weapons/rustyaxe.lua
+++ b/gamemode/itemsystem/weapons/rustyaxe.lua
@@ -226,4 +226,4 @@ end
print("Hello from scrapgun.lua")
--Don't forget to register the item!
-ART.RegisterItem(item)
+nrequire("item.lua").RegisterItem(item)
diff --git a/gamemode/shared/itemsystem/weapons/scraphammer.lua b/gamemode/itemsystem/weapons/scraphammer.lua
index 299d4e2..586b331 100644
--- a/gamemode/shared/itemsystem/weapons/scraphammer.lua
+++ b/gamemode/itemsystem/weapons/scraphammer.lua
@@ -230,4 +230,4 @@ end
print("Hello from scrapgun.lua")
--Don't forget to register the item!
-ART.RegisterItem(item)
+nrequire("item.lua").RegisterItem(item)
diff --git a/gamemode/shared/itemsystem/weapons/seratedknife.lua b/gamemode/itemsystem/weapons/seratedknife.lua
index 2daec36..7248426 100644
--- a/gamemode/shared/itemsystem/weapons/seratedknife.lua
+++ b/gamemode/itemsystem/weapons/seratedknife.lua
@@ -196,4 +196,4 @@ item.onDropped = function(self, ent)
end
--Don't forget to register the item!
-ART.RegisterItem(item)
+nrequire("item.lua").RegisterItem(item)
diff --git a/gamemode/shared/itemsystem/weapons_common.lua b/gamemode/itemsystem/weapons_common.lua
index 6f553fa..6f553fa 100644
--- a/gamemode/shared/itemsystem/weapons_common.lua
+++ b/gamemode/itemsystem/weapons_common.lua
diff --git a/gamemode/shared/npcsystem/blockingdummy.lua b/gamemode/npcsystem/sv_blockingdummy.lua
index 5c6008c..2b98b97 100644
--- a/gamemode/shared/npcsystem/blockingdummy.lua
+++ b/gamemode/npcsystem/sv_blockingdummy.lua
@@ -1,3 +1,5 @@
+
+local n = nrequire("sv_npcsystem.lua")
local NPC = {}
NPC.Name = "Blocking Training Dummy"
NPC.Desc = "A man made of straw. His dream is to have a brain."
@@ -101,5 +103,5 @@ end
function NPC:OnAttack(target)
end
*/
-
-ART.RegisterNPC(NPC)
+n.RegisterNPC(NPC)
+--ART.RegisterNPC(NPC)
diff --git a/gamemode/shared/npcsystem/dummy.lua b/gamemode/npcsystem/sv_dummy.lua
index 869dd0e..6a7e894 100644
--- a/gamemode/shared/npcsystem/dummy.lua
+++ b/gamemode/npcsystem/sv_dummy.lua
@@ -1,3 +1,5 @@
+local n = nrequire("sv_npcsystem.lua")
+
local NPC = {}
NPC.Name = "Training Dummy"
NPC.Desc = "A man made of straw. His dream is to have a brain."
@@ -92,4 +94,4 @@ function NPC:OnAttack(target)
end
*/
-ART.RegisterNPC(NPC)
+n.RegisterNPC(NPC)
diff --git a/gamemode/shared/npcsystem/rat.lua b/gamemode/npcsystem/sv_rat.lua
index ab96883..fadbc8d 100644
--- a/gamemode/shared/npcsystem/rat.lua
+++ b/gamemode/npcsystem/sv_rat.lua
@@ -1,3 +1,4 @@
+local n = nrequire("sv_npcsystem.lua")
local NPC = {}
NPC.Name = "Rat"
NPC.Desc = "A nasty little guy"
@@ -39,7 +40,7 @@ local dorun = function(self,ply)
end
self:StartActivity(ACT_FLY)
self:SetSequence( runseq )
- if(not ply or not ply:IsValid()) then return end
+ if not ply or not ply:IsValid() then return end
--Find a position in roughly the oposite direction of the player
local tpos = self:GetPos()
local ppos = ply:GetPos()
@@ -110,4 +111,4 @@ function NPC:OnAttack(target)
end
*/
-ART.RegisterNPC(NPC)
+n.RegisterNPC(NPC)
diff --git a/gamemode/nrequire.lua b/gamemode/nrequire.lua
index ba71f17..c666332 100644
--- a/gamemode/nrequire.lua
+++ b/gamemode/nrequire.lua
@@ -1,9 +1,13 @@
--[[
A replacement for require
]]
+--Don't run ourselves, or we'll get stuck in a recursive loop!
if nrequire ~= nil then return end
print("hello from nrequire!")
local path = (GM or GAMEMODE).Folder:gsub("gamemodes/","") .. "/gamemode"
+--[[
+ Calls func on all the files under dir
+]]
local function TraverseFolder(dir, func)
local fpath = table.concat({path,dir,"/*"})
local files, directories = file.Find(fpath,"LUA")
@@ -19,6 +23,26 @@ local function TraverseFolder(dir, func)
end
end
+--[[
+ Creates a funny kind of table. The root points to tables with file names, each file name points to a table containing the folder name it is under. If that folder is under more folders, then the folder table points to more tables in reverse order. The leaf contains the file path.
+ Ex:
+ {
+ [file.lua] = {
+ [some] = {
+ [foldername] = "foldername/some/file.lua"
+ }
+ [other] = {
+ [foldername] = "foldername/other/file.lua"
+ }
+ }
+ }
+ is created from
+ foldername/
+ some/
+ file.lua
+ other/
+ file.lua
+]]
local function rebuild_include_table(f)
local ret = {}
for k,v in pairs(f) do
@@ -51,7 +75,7 @@ local function tbllen(tbl)
end
--[[
- Finds all the paths from a pretable
+ Finds all the paths from a include table
]]
local function collect_paths(pretbl)
local ret = {}
@@ -70,6 +94,7 @@ end
--[[
Scans the prefix table built by rebuild_include_table to find the file path for the partial name of an included file.
+ If two files are named the same, you will need to include part of the file path until it can be resolved.
]]
local function scan(pretbl, name)
local pathparts = {}
@@ -78,18 +103,19 @@ local function scan(pretbl, name)
end
local filename = name:gfind("[%w_]+%.lua")()
local cursor = pretbl[filename]
- assert(cursor ~= nil,string.format("Scan did not find a file named %q, valid files are:\n\t%s",filename,table.concat(pretbl,"\n\t")))
+ assert(cursor ~= nil,string.format("Scan did not find a file named %q, valid files are:\n\t%s",filename,table.concat(collect_paths(pretbl),"\n\t")))
local rev = {}
for i = 1, #pathparts do rev[#pathparts - i + 1] = pathparts[i] end
for k,v in ipairs(rev) do cursor = cursor[v] end
while type(cursor) ~= "string" do
assert(type(cursor) ~= "nil",string.format("Could not find a valid file for path %q, file paths:\n\t%s",name,table.concat(collect_paths(pretbl),"\n\t")))
- assert(tbllen(cursor) == 1,string.format("Ambiguous scan, there are two or more paths that match %q\n\t%s",name,table.concat(collect_paths(cursor),"\n\t")))
+ assert(tbllen(cursor) == 1,string.format("Ambiguous scan, there are two or more paths that match %q\n\t%s\nSpecify more of the file path.",name,table.concat(collect_paths(cursor),"\n\t")))
cursor = cursor[next(cursor)]
end
return cursor
end
+
local paths = {}
local ins = function(n) paths[#paths + 1] = n end
TraverseFolder("",ins)
@@ -102,32 +128,36 @@ for k,v in pairs(paths) do
end
end
+
local pathstack = {}
local incyields = {}
+--[[
+ Returns the table returned by executing a file. The table is cached after is is loaded, so calling nrequire() on a file twice will only run it once.
+]]
function nrequire(req)
- print("nrequire")
local tpath = scan(ntbl,req)
if reqtbl[tpath] then
- print("nrequire cache hit")
+ print("Cache hit! returning",reqtbl[tpath])
+ --for k,v in pairs(reqtbl[tpath]) do print(k,":",v) end
return reqtbl[tpath]
end
for k,v in pairs(pathstack) do
- assert(v ~= tpath,string.format("Circular dependancy detected:\n\t%s",table.concat(pathstack,"\n\t\t|\n\t\tv\n\t")))
+ assert(v ~= tpath,string.format("Circular dependancy detected:\n\t%s\n\t\t|\n\t\tV\n\t%s",table.concat(pathstack,"\n\t\t|\n\t\tV\n\t"),v))
end
- print(string.format("Including %q\n",tpath))
+ local tab_rep = {}
+ for k=1,#pathstack do tab_rep[k] = "\t" end
+ print(string.format("%sIncluding %q",table.concat(tab_rep),tpath))
pathstack[#pathstack + 1] = tpath
- reqtbl[#reqtbl + 1] = include(tpath)
- print(string.format("Included %q\n",tpath))
- return reqtbl[#reqtbl]
- --[[
- incyields[#incyields + 1] = coroutine.create(function()
- print(string.format("Including %q\n",tpath))
- reqtbl[#reqtbl + 1] = include(tpath)
- print(string.format("Included %q\n",tpath))
- end)
- ]]
+ reqtbl[tpath] = include(tpath)
+ pathstack[#pathstack] = nil
+ print(string.format("%sIncluded %q",table.concat(tab_rep),tpath))
+ return reqtbl[tpath]
end
+--[[
+ Automatically include all the files in the gamemode directory based on the file name.
+ If the file starts with cl_ it will only be included on the client, if it starts with sv_ it will only be included on the server. If it starts with anything else, it will be shared. Will detect and error on circuar dependancy.
+]]
local function doincludes()
print("doing includes")
paths = {}
diff --git a/gamemode/shared/concommands.lua b/gamemode/shared/concommands.lua
index b4e844a..64d9a35 100644
--- a/gamemode/shared/concommands.lua
+++ b/gamemode/shared/concommands.lua
@@ -2,7 +2,7 @@
Various console command helper functions
]]
-local fuzzel = include("fuzzel.lua")
+local fuzzel = nrequire("fuzzel.lua")
local concmd = {}
diff --git a/gamemode/shared/loaditems.lua b/gamemode/shared/loaditems.lua
index 7a4dd22..9975bb3 100644
--- a/gamemode/shared/loaditems.lua
+++ b/gamemode/shared/loaditems.lua
@@ -1,3 +1,5 @@
+do return end
+--[=[
--[[
This file loads in all the items
]]
@@ -56,3 +58,4 @@ concommand.Add("artery_giveitem",function(ply,cmd,args)
print("Trying to give an item:" .. args[1])
ART.GiveItem(ply,args[1])
end, concmd.AutocompleteFunction(table.GetKeys(ART.Items)), "Give an item to the specified player, or yourself if no player is specified.")
+]=]
diff --git a/gamemode/shared/log.lua b/gamemode/shared/log.lua
index 63d3e0e..1ede67f 100644
--- a/gamemode/shared/log.lua
+++ b/gamemode/shared/log.lua
@@ -3,7 +3,7 @@ local fn = nrequire("fn.lua")
local col = nrequire("colortheme.lua")
local log = {}
-log.debug = fn.curry(
+log.debug = fn.compose(
fn.curry(
MsgC,
col.console.cyan),
diff --git a/gamemode/shared/sh_setup.lua b/gamemode/shared/sh_setup.lua
index 9c44e57..66fb829 100644
--- a/gamemode/shared/sh_setup.lua
+++ b/gamemode/shared/sh_setup.lua
@@ -1,3 +1,5 @@
+do return end
+--[=[
--[[
Some values that need to be setup by the server owner
]]
@@ -163,3 +165,4 @@ if CLIENT then
scrollpanel:AddItem(savebutton)
end)
end
+]=]
diff --git a/gamemode/utility/fn.lua b/gamemode/utility/fn.lua
index 7c53150..343f27d 100644
--- a/gamemode/utility/fn.lua
+++ b/gamemode/utility/fn.lua
@@ -226,4 +226,5 @@ function fn.flatten(tbl)
end
return ret
end
+
return fn
diff --git a/gamemode/utility/stream.lua b/gamemode/utility/stream.lua
index cdf3933..75beb4c 100644
--- a/gamemode/utility/stream.lua
+++ b/gamemode/utility/stream.lua
@@ -1,4 +1,6 @@
--[[
+ Public functions:
+ CreateStream(data_or_nil)
A stream object, has the methods:
stream:WriteString(string) :: nil
stream:WriteInt(num,bytes) :: nil
diff --git a/gamemode/utility/svg/cl_svg.lua b/gamemode/utility/svg/cl_svg.lua
new file mode 100644
index 0000000..623c9e1
--- /dev/null
+++ b/gamemode/utility/svg/cl_svg.lua
@@ -0,0 +1,98 @@
+local svg = {}
+local fn = nrequire("fn.lua")
+local file_cache_max_size = 100
+local file_cache_size = 0
+local file_cache = {}
+
+local function readsvg(path)
+ if file_cache[path] == nil then
+ if file_cache_size > file_cache_max_size then
+ local k,_ = next(file_cache) --Random replacement
+ file_cache[k] = nil
+ end
+ file_cache[path] = file.Read(path,"GAME")
+ end
+ return file_cache[path]
+end
+
+local function updatesvg(self)
+ if self.path ~= self.svgpath then
+ self.svgdata = readsvg(self.path)
+ assert(self.svgdata ~= nil,"Could not open file:" .. self.path)
+ self.svgpath = self.path
+ end
+ local bgf = ""
+ local fgf = ""
+ if self.bg ~= nil then
+ bgf = string.format("svg{background:%s}",self.bg)
+ end
+ if self.fg ~= nil then
+ fgf = string.format("svg path{fill:%s}",self.fg)
+ end
+ self.html:SetHTML(string.format([[
+<style>%s%sbody{overflow:hidden}</style><body>%s</body>
+]],bgf,fgf,self.svgdata))
+end
+
+local function updatesvgimg(self,newpath)
+ self.path = newpath
+ self:Update()
+end
+
+local function updatesvgfg(self,fore)
+ self.fg = fore
+ self:Update()
+end
+
+local function updatesvgbg(self,back)
+ self.bg = back
+ self:Update()
+end
+
+local toprocess = {}
+function svg.MaterialFromSVG(spath,background,foreground)
+ local html = vgui.Create("DHTML")
+ local svgdata = readsvg(spath)
+ local bgf = ""
+ local fgf = ""
+ if background ~= nil then
+ bgf = string.format("svg{background:%s}",background)
+ end
+ if foreground ~= nil then
+ fgf = string.format("svg path{fill:%s}",foreground)
+ end
+ html:SetHTML(string.format([[
+<style>%s%sbody{overflow:hidden}</style><body>%s</body>
+]],bgf,fgf,svgdata))
+ local mat = {}
+ toprocess[#toprocess + 1] = {mat,html}
+ return mat
+end
+
+hook.Add("Think","process_svg_materials",function()
+ for k,v in ipairs(toprocess) do
+ local hm = v[2]:GetHTMLMaterial()
+ if hm then
+ v[1].material = hm
+ end
+ for i = k,#toprocess do
+ toprocess[i] = toprocess[i + 1]
+ end
+ end
+end)
+
+function svg.SvgOnDpanel(spath,background,foreground,dpanel)
+ local ret = {}
+ ret.html = vgui.Create("DHTML",dpanel)
+ ret.path = spath
+ ret.fg = foreground
+ ret.bg = background
+ ret.UpdateForeground = updatesvgfg
+ ret.UpdateBackground = updatesvgbg
+ ret.UpdateImage = updatesvgimg
+ ret.Update = updatesvg
+ ret:Update()
+ return ret
+end
+
+return svg