From 98e0462e4f6b13ff26af5211409352d45dd9453e Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sun, 8 Jan 2017 22:28:08 -0500 Subject: Add a ton of icons, more work on refactoring --- gamemode/client/cl_inventory.lua | 107 +++++----- gamemode/client/cl_weaponswitch.lua | 4 +- gamemode/client/hud/cl_svgtest.lua | 46 ++++ gamemode/client/qtabs/cl_qinventory.lua | 69 ++++++ gamemode/client/qtabs/cl_qprayers.lua | 8 + gamemode/client/vgui/vgui_DMultiModelPanel.lua | 161 -------------- gamemode/config/colortheme.lua | 4 + gamemode/core/inventory/inventory.lua | 14 +- gamemode/core/inventory/item.lua | 4 +- gamemode/core/inventory/sv_invtracker.lua | 80 +++++++ gamemode/core/npc/cl_npcmap.lua | 162 ++++++++++++++ gamemode/core/npc/sv_npcmap.lua | 22 ++ gamemode/core/npc/sv_npcsystem.lua | 39 ++++ gamemode/core/npcmap/cl_npcmap.lua | 162 -------------- gamemode/core/npcmap/sv_npcmap.lua | 22 -- gamemode/inventorysystem/equipment.lua | 67 ------ .../inventorysystem/equipment/cl_equipment.lua | 140 +++++++++++++ .../inventorysystem/equipment/sh_equipment.lua | 180 ++++++++++++++++ .../inventorysystem/equipment/sv_equipment.lua | 5 + gamemode/inventorysystem/prayers/sh_prayers.lua | 44 ++++ gamemode/itemsystem/armor/balaclava.lua | 80 +++++++ gamemode/itemsystem/exampleitem.lua | 85 ++++++++ gamemode/itemsystem/foodstuffs/ratmeat.lua | 46 ++++ gamemode/itemsystem/foodstuffs/watermelon.lua | 55 +++++ gamemode/itemsystem/item_common.lua | 76 +++++++ gamemode/itemsystem/quest/rougebadge.lua | 38 ++++ gamemode/itemsystem/quest/rougebook.lua | 68 ++++++ gamemode/itemsystem/quest/togglechip.lua | 24 +++ gamemode/itemsystem/scrapgun.lua | 60 ++++++ gamemode/itemsystem/utility/flashlight.lua | 88 ++++++++ gamemode/itemsystem/weapons/knuckledclaw.lua | 163 ++++++++++++++ gamemode/itemsystem/weapons/rustyaxe.lua | 229 ++++++++++++++++++++ gamemode/itemsystem/weapons/scraphammer.lua | 233 +++++++++++++++++++++ gamemode/itemsystem/weapons/seratedknife.lua | 199 ++++++++++++++++++ gamemode/itemsystem/weapons_common.lua | 70 +++++++ gamemode/npcsystem/sv_blockingdummy.lua | 107 ++++++++++ gamemode/npcsystem/sv_dummy.lua | 97 +++++++++ gamemode/npcsystem/sv_rat.lua | 114 ++++++++++ gamemode/nrequire.lua | 64 ++++-- gamemode/shared/concommands.lua | 2 +- gamemode/shared/itemsystem/armor/balaclava.lua | 80 ------- gamemode/shared/itemsystem/exampleitem.lua | 85 -------- gamemode/shared/itemsystem/foodstuffs/ratmeat.lua | 46 ---- .../shared/itemsystem/foodstuffs/watermelon.lua | 55 ----- gamemode/shared/itemsystem/item_common.lua | 76 ------- gamemode/shared/itemsystem/quest/rougebadge.lua | 38 ---- gamemode/shared/itemsystem/quest/rougebook.lua | 68 ------ gamemode/shared/itemsystem/quest/togglechip.lua | 24 --- gamemode/shared/itemsystem/scrapgun.lua | 60 ------ gamemode/shared/itemsystem/utility/flashlight.lua | 88 -------- .../shared/itemsystem/weapons/knuckledclaw.lua | 163 -------------- gamemode/shared/itemsystem/weapons/rustyaxe.lua | 229 -------------------- gamemode/shared/itemsystem/weapons/scraphammer.lua | 233 --------------------- .../shared/itemsystem/weapons/seratedknife.lua | 199 ------------------ gamemode/shared/itemsystem/weapons_common.lua | 70 ------- gamemode/shared/loaditems.lua | 3 + gamemode/shared/log.lua | 2 +- gamemode/shared/npcsystem/blockingdummy.lua | 105 ---------- gamemode/shared/npcsystem/dummy.lua | 95 --------- gamemode/shared/npcsystem/rat.lua | 113 ---------- gamemode/shared/sh_setup.lua | 3 + gamemode/utility/fn.lua | 1 + gamemode/utility/stream.lua | 2 + gamemode/utility/svg/cl_svg.lua | 98 +++++++++ 64 files changed, 2856 insertions(+), 2318 deletions(-) create mode 100644 gamemode/client/hud/cl_svgtest.lua create mode 100644 gamemode/client/qtabs/cl_qinventory.lua create mode 100644 gamemode/client/qtabs/cl_qprayers.lua delete mode 100644 gamemode/client/vgui/vgui_DMultiModelPanel.lua create mode 100644 gamemode/core/inventory/sv_invtracker.lua create mode 100644 gamemode/core/npc/cl_npcmap.lua create mode 100644 gamemode/core/npc/sv_npcmap.lua create mode 100644 gamemode/core/npc/sv_npcsystem.lua delete mode 100644 gamemode/core/npcmap/cl_npcmap.lua delete mode 100644 gamemode/core/npcmap/sv_npcmap.lua delete mode 100644 gamemode/inventorysystem/equipment.lua create mode 100644 gamemode/inventorysystem/equipment/cl_equipment.lua create mode 100644 gamemode/inventorysystem/equipment/sh_equipment.lua create mode 100644 gamemode/inventorysystem/equipment/sv_equipment.lua create mode 100644 gamemode/inventorysystem/prayers/sh_prayers.lua create mode 100644 gamemode/itemsystem/armor/balaclava.lua create mode 100644 gamemode/itemsystem/exampleitem.lua create mode 100644 gamemode/itemsystem/foodstuffs/ratmeat.lua create mode 100644 gamemode/itemsystem/foodstuffs/watermelon.lua create mode 100644 gamemode/itemsystem/item_common.lua create mode 100644 gamemode/itemsystem/quest/rougebadge.lua create mode 100644 gamemode/itemsystem/quest/rougebook.lua create mode 100644 gamemode/itemsystem/quest/togglechip.lua create mode 100644 gamemode/itemsystem/scrapgun.lua create mode 100644 gamemode/itemsystem/utility/flashlight.lua create mode 100644 gamemode/itemsystem/weapons/knuckledclaw.lua create mode 100644 gamemode/itemsystem/weapons/rustyaxe.lua create mode 100644 gamemode/itemsystem/weapons/scraphammer.lua create mode 100644 gamemode/itemsystem/weapons/seratedknife.lua create mode 100644 gamemode/itemsystem/weapons_common.lua create mode 100644 gamemode/npcsystem/sv_blockingdummy.lua create mode 100644 gamemode/npcsystem/sv_dummy.lua create mode 100644 gamemode/npcsystem/sv_rat.lua delete mode 100644 gamemode/shared/itemsystem/armor/balaclava.lua delete mode 100644 gamemode/shared/itemsystem/exampleitem.lua delete mode 100644 gamemode/shared/itemsystem/foodstuffs/ratmeat.lua delete mode 100644 gamemode/shared/itemsystem/foodstuffs/watermelon.lua delete mode 100644 gamemode/shared/itemsystem/item_common.lua delete mode 100644 gamemode/shared/itemsystem/quest/rougebadge.lua delete mode 100644 gamemode/shared/itemsystem/quest/rougebook.lua delete mode 100644 gamemode/shared/itemsystem/quest/togglechip.lua delete mode 100644 gamemode/shared/itemsystem/scrapgun.lua delete mode 100644 gamemode/shared/itemsystem/utility/flashlight.lua delete mode 100644 gamemode/shared/itemsystem/weapons/knuckledclaw.lua delete mode 100644 gamemode/shared/itemsystem/weapons/rustyaxe.lua delete mode 100644 gamemode/shared/itemsystem/weapons/scraphammer.lua delete mode 100644 gamemode/shared/itemsystem/weapons/seratedknife.lua delete mode 100644 gamemode/shared/itemsystem/weapons_common.lua delete mode 100644 gamemode/shared/npcsystem/blockingdummy.lua delete mode 100644 gamemode/shared/npcsystem/dummy.lua delete mode 100644 gamemode/shared/npcsystem/rat.lua create mode 100644 gamemode/utility/svg/cl_svg.lua (limited to 'gamemode') 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/npc/cl_npcmap.lua b/gamemode/core/npc/cl_npcmap.lua new file mode 100644 index 0000000..5a9de7e --- /dev/null +++ b/gamemode/core/npc/cl_npcmap.lua @@ -0,0 +1,162 @@ + +--local tblf = include("/../gamemodes/artery/gamemode/utility/mapfuncs.lua") +print("Hello from cl_ncpmap in core") +local drawmap = false +hook.Add( "ScoreboardShow", "ShowNPCMap", function() + print("Showing npc map") + drawmap = true + return true +end ) +hook.Add( "ScoreboardHide", "ShowNPCMap", function() + print("Hiding npc map") + drawmap = false +end ) +local white = Color( 255, 255, 255, 255 ) + +local mapicons = --[[mapicons or]] { + ["global"] = { + ["isleaf"] = false, + ["border"] = { {-10000,-10000}, + {-10000,10000}, + {10000,10000}, + {10000,-10000} + }, + } +} + +hook.Add( "HUDPaint", "paintsprites", function() + local function drawsubarea(node) + print("drawing") + PrintTable(node) + if node.isleaf then + render.SetMaterial( node.material ) + render.DrawSprite( node.pos, 64, 64, white ) + print("Actually drawing") + PrintTable(node) + else + if not node.icons then + print("found area without any icons!") + for k,v in pairs(node) do print(k,":",v) end + end + for k,v in pairs(node.icons or {}) do + drawsubarea(v) + end + end + end + if drawmap then + print("starting this draw") + cam.Start3D() + drawsubarea(mapicons["global"]) + cam.End3D() + print("done with this draw") + end +end ) + +--When the player loads in, load the npcmap for this map +hook.Add("Initialize","loadmapicons",function() + LocalPlayer().MapIcons = LocalPlayer().MapIcons or {} + local mapname = game.GetMap() + if not file.Exists("artery/client/"..mapname,"DATA") then + file.CreateDir("artery/client/"..mapname) + end + + local mapiconstxt = file.Read("artery/client/"..mapname.."/known.txt") + for k,v in pairs(string.Explode("\r?\n",mapiconstxt,true)) do + local isleaf = tobool(v[1]) + local ttbl = string.Explode(",",v) + if isleaf then + local subarea = ttbl[2] + local material = ttbl[3] + local pos = Vector(ttbl[4],ttbl[5],ttbl[6]) + else + local name = v[2] + local boundry = {} + for i = 3, #ttbl, 3 do + boundry[#boundry+1] = ttbl[i],ttbl[i + 1],ttbl[i + 2] + end + end + end +end) + +--When the player disconnects (or changes levels) save the npcmap + +--Add an icon to the map +local function addmapicon(material, subarea, position) + print("adding map icon, material:",material,"subarea:",subarea,"bordertbl:",bordertbl) + print("mat",material,"subarea",subarea,"position",position) + local parts = string.Explode(":",subarea) + print("parts:",parts) + PrintTable(parts) + local cursor = mapicons + for k,v in pairs(parts) do + print("Traverseing down tree:",k,v) + print("cursor was") + PrintTable(cursor) + if cursor[v] == nil then cursor[v] = {} end + cursor = cursor[v] + print("cursor is") + PrintTable(cursor) + end + if cursor.isleaf and v.pos == position then return end + cursor.icons = cursor.icons or {} + for k,v in pairs(cursor.icons) do + if v.pos == position then return end --This position already has an icon! + end + table.insert(cursor.icons,{ + ["isleaf"] = true, + ["material"] = Material(material), + ["pos"] = position, + }) + assert(type(cursor) == "table","Attempted to add subarea that dosen't exist:" .. subarea) +end + +local function addmaparea(material, subarea, bordertbl) + print("adding map area, material:",material,"subarea:",subarea,"bordertbl:",bordertbl) + local parts = string.Explode(":",subarea) + print("parts:",parts) + PrintTable(parts) + local cursor = mapicons + if #parts > 1 then + for k,v in pairs(parts) do + print("Traverseing down tree:",k,v) + cursor = cursor[v] + end + end + + print("Cursor is",cursor) + if cursor ~= nil then + cursor[subarea] = { + ["isleaf"] = false, + ["material"] = "", + ["border"] = bordertbl, + ["subparts"] = {} + } + else + print("Error, cursor was nil!") + end +end +--[[ +addmaparea("","global",{ + {-10000,-10000}, + {-10000,10000}, + {10000,10000}, + {10000,-10000} +}) +]] + +net.Receive("addmapicon",function() + print("got recieve for map icon") + local matstr = net.ReadString() + local subarea = net.ReadString() + local matpos = net.ReadVector() + addmapicon(matstr,subarea,matpos) + print("MapIcons is now") + PrintTable(mapicons) +end) + +net.Receive("addmaparea",function() + print("got receive for map area") + local matstr = net.ReadString() + local subarea = net.ReadString() + local boarders = net.ReadTable() +end) diff --git a/gamemode/core/npc/sv_npcmap.lua b/gamemode/core/npc/sv_npcmap.lua new file mode 100644 index 0000000..8368484 --- /dev/null +++ b/gamemode/core/npc/sv_npcmap.lua @@ -0,0 +1,22 @@ +if CLIENT then error("You're not supposed to be here!") end +local pmeta = FindMetaTable("Player") + +util.AddNetworkString("addmapicon") +util.AddNetworkString("addmaparea") + +function pmeta:AddMapIcon(icon,subarea,position) + print("adding map icon") + net.Start("addmapicon") + net.WriteString(icon) + net.WriteString(subarea) + net.WriteVector(position) + net.Send(self) +end + +function pmeta:AddMapArea(icon,subarea,bordertbl) + print("adding area") + net.Start("addmaparea") + net.WriteString(icon) + net.WriteString(subarea) + net.WriteTable(bordertbl) +end 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/core/npcmap/cl_npcmap.lua b/gamemode/core/npcmap/cl_npcmap.lua deleted file mode 100644 index 5a9de7e..0000000 --- a/gamemode/core/npcmap/cl_npcmap.lua +++ /dev/null @@ -1,162 +0,0 @@ - ---local tblf = include("/../gamemodes/artery/gamemode/utility/mapfuncs.lua") -print("Hello from cl_ncpmap in core") -local drawmap = false -hook.Add( "ScoreboardShow", "ShowNPCMap", function() - print("Showing npc map") - drawmap = true - return true -end ) -hook.Add( "ScoreboardHide", "ShowNPCMap", function() - print("Hiding npc map") - drawmap = false -end ) -local white = Color( 255, 255, 255, 255 ) - -local mapicons = --[[mapicons or]] { - ["global"] = { - ["isleaf"] = false, - ["border"] = { {-10000,-10000}, - {-10000,10000}, - {10000,10000}, - {10000,-10000} - }, - } -} - -hook.Add( "HUDPaint", "paintsprites", function() - local function drawsubarea(node) - print("drawing") - PrintTable(node) - if node.isleaf then - render.SetMaterial( node.material ) - render.DrawSprite( node.pos, 64, 64, white ) - print("Actually drawing") - PrintTable(node) - else - if not node.icons then - print("found area without any icons!") - for k,v in pairs(node) do print(k,":",v) end - end - for k,v in pairs(node.icons or {}) do - drawsubarea(v) - end - end - end - if drawmap then - print("starting this draw") - cam.Start3D() - drawsubarea(mapicons["global"]) - cam.End3D() - print("done with this draw") - end -end ) - ---When the player loads in, load the npcmap for this map -hook.Add("Initialize","loadmapicons",function() - LocalPlayer().MapIcons = LocalPlayer().MapIcons or {} - local mapname = game.GetMap() - if not file.Exists("artery/client/"..mapname,"DATA") then - file.CreateDir("artery/client/"..mapname) - end - - local mapiconstxt = file.Read("artery/client/"..mapname.."/known.txt") - for k,v in pairs(string.Explode("\r?\n",mapiconstxt,true)) do - local isleaf = tobool(v[1]) - local ttbl = string.Explode(",",v) - if isleaf then - local subarea = ttbl[2] - local material = ttbl[3] - local pos = Vector(ttbl[4],ttbl[5],ttbl[6]) - else - local name = v[2] - local boundry = {} - for i = 3, #ttbl, 3 do - boundry[#boundry+1] = ttbl[i],ttbl[i + 1],ttbl[i + 2] - end - end - end -end) - ---When the player disconnects (or changes levels) save the npcmap - ---Add an icon to the map -local function addmapicon(material, subarea, position) - print("adding map icon, material:",material,"subarea:",subarea,"bordertbl:",bordertbl) - print("mat",material,"subarea",subarea,"position",position) - local parts = string.Explode(":",subarea) - print("parts:",parts) - PrintTable(parts) - local cursor = mapicons - for k,v in pairs(parts) do - print("Traverseing down tree:",k,v) - print("cursor was") - PrintTable(cursor) - if cursor[v] == nil then cursor[v] = {} end - cursor = cursor[v] - print("cursor is") - PrintTable(cursor) - end - if cursor.isleaf and v.pos == position then return end - cursor.icons = cursor.icons or {} - for k,v in pairs(cursor.icons) do - if v.pos == position then return end --This position already has an icon! - end - table.insert(cursor.icons,{ - ["isleaf"] = true, - ["material"] = Material(material), - ["pos"] = position, - }) - assert(type(cursor) == "table","Attempted to add subarea that dosen't exist:" .. subarea) -end - -local function addmaparea(material, subarea, bordertbl) - print("adding map area, material:",material,"subarea:",subarea,"bordertbl:",bordertbl) - local parts = string.Explode(":",subarea) - print("parts:",parts) - PrintTable(parts) - local cursor = mapicons - if #parts > 1 then - for k,v in pairs(parts) do - print("Traverseing down tree:",k,v) - cursor = cursor[v] - end - end - - print("Cursor is",cursor) - if cursor ~= nil then - cursor[subarea] = { - ["isleaf"] = false, - ["material"] = "", - ["border"] = bordertbl, - ["subparts"] = {} - } - else - print("Error, cursor was nil!") - end -end ---[[ -addmaparea("","global",{ - {-10000,-10000}, - {-10000,10000}, - {10000,10000}, - {10000,-10000} -}) -]] - -net.Receive("addmapicon",function() - print("got recieve for map icon") - local matstr = net.ReadString() - local subarea = net.ReadString() - local matpos = net.ReadVector() - addmapicon(matstr,subarea,matpos) - print("MapIcons is now") - PrintTable(mapicons) -end) - -net.Receive("addmaparea",function() - print("got receive for map area") - local matstr = net.ReadString() - local subarea = net.ReadString() - local boarders = net.ReadTable() -end) diff --git a/gamemode/core/npcmap/sv_npcmap.lua b/gamemode/core/npcmap/sv_npcmap.lua deleted file mode 100644 index 8368484..0000000 --- a/gamemode/core/npcmap/sv_npcmap.lua +++ /dev/null @@ -1,22 +0,0 @@ -if CLIENT then error("You're not supposed to be here!") end -local pmeta = FindMetaTable("Player") - -util.AddNetworkString("addmapicon") -util.AddNetworkString("addmaparea") - -function pmeta:AddMapIcon(icon,subarea,position) - print("adding map icon") - net.Start("addmapicon") - net.WriteString(icon) - net.WriteString(subarea) - net.WriteVector(position) - net.Send(self) -end - -function pmeta:AddMapArea(icon,subarea,bordertbl) - print("adding area") - net.Start("addmaparea") - net.WriteString(icon) - net.WriteString(subarea) - net.WriteTable(bordertbl) -end 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/itemsystem/armor/balaclava.lua b/gamemode/itemsystem/armor/balaclava.lua new file mode 100644 index 0000000..dd0ec83 --- /dev/null +++ b/gamemode/itemsystem/armor/balaclava.lua @@ -0,0 +1,80 @@ +--[[ + An example item +]] +local item = {} + +--Required, a name, all item names must be unique +item.Name = "Balaclava" + +--Optional, a tooltip to display +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 "" +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 +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 +end + +function item.DoOnPanel(dimagebutton) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png") +end + +function item.DoOnEqupPanel(dimagebutton) + print("called with panel:",panel) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png") +end + +--[[ +function item.Paint(self,width,height) + --print("painting with values",self,width,height) + draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) +end + +function item.PaintEquiped(self,width,height) + --print("painting with values",self,width,height) + draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) +end +]] + +--Required, the shape of this item. +item.Shape = { + {true,true}, + {true,true}, +} + +--Optional, If this item can be equiped in any player slots, put them here. +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 +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") +end + +print("Hello from balaclava.lua") +--Don't forget to register the item! +nrequire("item.lua").RegisterItem(item) diff --git a/gamemode/itemsystem/exampleitem.lua b/gamemode/itemsystem/exampleitem.lua new file mode 100644 index 0000000..066e107 --- /dev/null +++ b/gamemode/itemsystem/exampleitem.lua @@ -0,0 +1,85 @@ +--[[ + An example item +]] +local item = {} + +--Required, a name, all item names must be unique +item.Name = "Test item" + +--Optional, a tooltip to display when hovered over +item.Tooltip = "An old axe, probably good for fighting." + +--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 "" +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 +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["test"] = function() print("You pressed test!") end + options["toste"] = function() print("You pressed toste!") end + return options +end + +--Optional. Something run once when this item is drawn in a backpack +function item.DoOnPanel(dimagebutton) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png") +end + +--Optional. Something run once when this item is drawn in an equiped slot +function item.DoOnEqupPanel(dimagebutton) + print("called with panel:",panel) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png") +end + +--Optional. Called continuously, use if you need the item to display different stuff at different tiems in the backpack. +function item.Paint(self,width,height) + draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) +end + +--Optional. Called continuously, use if you need the item to display different stuff at different tiems when equiped. +function item.PaintEquiped(self,width,height) + draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) +end + +--Required, the shape of this item in a backpack. +item.Shape = { + {true}, + {true}, + {true}, +} + +--Optional, If this item can be equiped in any player slots, put them here. +item.Equipable = "Right" + +--Optional, what to do when the player clicks, and this item is in the slot in inventory. only works for items equipable in left and right +item.onClick = function(self,owner) + print("pew pew!") +end + +--Optional, if we should do something special on equip(like draw the PAC for this weapon). See ART.ApplyPAC in /gamemode/shared/sh_pac.lua +item.onEquip = function(self,who) + print("Oh boy! I'm getting used!") +end + +--Optional, if we should do something speical on unequip(like setting PAC back to normal). Sett ART.RemovePAC in /gamemode/shared/sh_pac.lua +item.onUnEquip = function(self,who) + print("Aw, I'm being stored :(") +end + +--Technically optional, but item will display as a rock if you don't have it. If you want to do something other than drop on dropped, remove ent. +item.onDropped = function(self,ent) + print("I've been dropped!(BUVVV WUB WUB WUB WUB WUB)") +end + +print("Hello from exampleitem.lua") +--Don't forget to register the item! +nrequire("item.lua").RegisterItem(item) diff --git a/gamemode/itemsystem/foodstuffs/ratmeat.lua b/gamemode/itemsystem/foodstuffs/ratmeat.lua new file mode 100644 index 0000000..0198e87 --- /dev/null +++ b/gamemode/itemsystem/foodstuffs/ratmeat.lua @@ -0,0 +1,46 @@ +--[[ + An example item +]] +local item = {} + +--Required, a name, all item names must be unique +item.Name = "Rat Meat" + +--Optional, a tooltip to display when hovered over +item.Tooltip = "Disgusting, disease-ridden meat." + +--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 "" +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 +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["test"] = function() print("You pressed test!") end + options["toste"] = function() print("You pressed toste!") end + return options +end + +--Optional. Something run once when this item is drawn in a backpack +function item.DoOnPanel(dimagebutton) + --dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png") +end + +--Required, the shape of this item in a backpack. +item.Shape = { + {true} +} + +item.onDropped = function(self, ent) + ART.ApplyPAC(ent,"ratmeat") +end +--Don't forget to register the item! +nrequire("item.lua").RegisterItem(item) diff --git a/gamemode/itemsystem/foodstuffs/watermelon.lua b/gamemode/itemsystem/foodstuffs/watermelon.lua new file mode 100644 index 0000000..851cf1f --- /dev/null +++ b/gamemode/itemsystem/foodstuffs/watermelon.lua @@ -0,0 +1,55 @@ +--[[ + An example item +]] +local item = {} + +--Required, a name, all item names must be unique +item.Name = "Watermelon" + +--Optional, a tooltip to display when hovered over +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 "" +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 +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) + 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() + net.Start("eat_watermelon") + net.SendToServer() + end + return options +end + +--Required, the shape of this item in a backpack. +item.Shape = { + {true,true,true}, + {true,true,true}, + {true,true,true}, +} + +item.onDropped = function(self, ent) + ART.ApplyPAC(ent,"Watermelon") +end + +print("Hello from exampleitem.lua") +--Don't forget to register the item! +nrequire("item.lua").RegisterItem(item) diff --git a/gamemode/itemsystem/item_common.lua b/gamemode/itemsystem/item_common.lua new file mode 100644 index 0000000..b4b7cce --- /dev/null +++ b/gamemode/itemsystem/item_common.lua @@ -0,0 +1,76 @@ +if CLIENT then + ART.DropItem = function(item) + local i = item + print("Trying to drop item, Item was ") + PrintTable(item) + return function() + local data = item:Serialize() + net.Start("dropitem") + net.WriteString(item.Name) + net.WriteUInt(#data,32) + net.WriteData(data,#data) + net.SendToServer() + end + end + +else + util.AddNetworkString("dropitem") + + function gencompareto(item) + --Two items are equal if their Serialize()s are the same. + local tserialize = item:Serialize() + return function(otheritem) + local oserialize = otheritem:Serialize() + return tserialize == oserialize + end + end + + function ART.CreateDroppedItem(itemtbl, where) + local e = ents.Create("art_droppeditem") + e.Model = "models/props_junk/Rock001a.mdl" + e.Item = itemtbl + e:SetPos(where) + e:Spawn() + end + + net.Receive("dropitem",function(len,ply) + local itemtype = net.ReadString() + local itemdatalen = net.ReadUInt(32) + local itemdata = net.ReadData(itemdatalen) + local itemtbl = ART.GetItemByName(itemtype) + local item = itemtbl:DeSerialize(itemdata) + + print("I want to drop:") + PrintTable(item) + print("Do I have one?") + local row,col,n = ply:HasItem(gencompareto(item)) + print("row",row,"col",col,"n",n) + --To find out where to drop the item, go out from player's view, then down. + local pes = ply:GetPos()+Vector(0,0,64) + local pee = ply:GetForward()*50 + Vector(0,0,64) + ply:GetPos() + local tr1d = { + ["start"] = pes, + ["endpos"] = pee, + ["filter"] = ply, + } + local tr1r = util.TraceLine(tr1d) + local fes + if tr1r.hit then --Use where it hit and go down + fes = tr1r.HitPos + else --Use the spot 50 units in front of us + fes = pee + end + local tr2d = { + ["start"] = fes, + ["endpos"] = fes + Vector(0,0,-64), + } + local tr2r = util.TraceLine(tr2d) + local itempos = tr2r.HitPos + print("Dropping item at",itempos) + if row and col and n then + print("DropItem is",ART.DropItem) + ART.CreateDroppedItem(item,itempos) + ply:RemoveItemAt(n,row,col) + end + end) +end diff --git a/gamemode/itemsystem/quest/rougebadge.lua b/gamemode/itemsystem/quest/rougebadge.lua new file mode 100644 index 0000000..d5e2950 --- /dev/null +++ b/gamemode/itemsystem/quest/rougebadge.lua @@ -0,0 +1,38 @@ +--[[ + An example item +]] +local item = {} + +--Required, a name, all item names must be unique +item.Name = "Rouge Newbie Badge" + +--Optional, a tooltip to display when hovered over +item.Tooltip = "A tiny peice of metal, kinda looks like a dagger." + +--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 "" +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 +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["test"] = function() print("You pressed test!") end + options["toste"] = function() print("You pressed toste!") end + return options +end + +--Required, the shape of this item in a backpack. +item.Shape = { + {true} +} + + +nrequire("item.lua").RegisterItem(item) diff --git a/gamemode/itemsystem/quest/rougebook.lua b/gamemode/itemsystem/quest/rougebook.lua new file mode 100644 index 0000000..7afb5db --- /dev/null +++ b/gamemode/itemsystem/quest/rougebook.lua @@ -0,0 +1,68 @@ +--[[ + A quest item for the prayer book quest +]] +local item = {} + +item.Name = "Orders of the Silent Circle" + +item.Serialize = function(self) + print("Trying to serailize!") + return "" +end + +item.DeSerialize = function(self,string) + print("Trying to deserialize!") + return self +end + +item.Shape = { + {true,true}, + {true,true}, +} + +local rougeadvice = { + "He who refuses to trim his beard will find himself in a hairy situation.", + "You'll get tired defending from a man in a car", + "You'll get exhaused attacking a man in a car.", + "Sex is not the answer, it is the question. And the answer is 'yes'.", + "The 'Darkest Hour' is when you can't find the matches.", + "If you eat beans before church, you will sit in your own pew.", + "He who seeks challenges will be puzzeled.", + "He who fishes in another man's well is likely to catch crabs.", + "Enjoy masturbation, it's sex with someone you love.", +} + +local lhint = 1 + +function item.GetOptions(self) + local options = {} + options["Read"] = function() + local readframe = vgui.Create( "DFrame" ) + readframe:SetPos( ScrW()/2 - 100, ScrH()/2 - 100) + readframe:SetSize(200,200) + readframe:SetTitle("Orders of the Silent Circle") + readframe:MakePopup() + + + local readpanel = vgui.Create( "DPanel", readframe ) + readpanel:SetPos( 5, 30 ) + readpanel:SetSize( 190, 170 ) + function readpanel:Paint(w,h) end + + + local readtext = vgui.Create( "DLabel", readpanel ) + readtext:SetPos( 40, 40 ) + readtext:SetText(rougeadvice[lhint]) + readtext:SetDark() + readtext:Dock(FILL) + readtext:SetWrap(true) + lhint = (lhint % #rougeadvice) + 1 + end + return options +end + +item.onDropped = function(self, ent) + ART.ApplyPAC(ent,"book1") +end + +nrequire("item.lua").RegisterItem(item) diff --git a/gamemode/itemsystem/quest/togglechip.lua b/gamemode/itemsystem/quest/togglechip.lua new file mode 100644 index 0000000..d920497 --- /dev/null +++ b/gamemode/itemsystem/quest/togglechip.lua @@ -0,0 +1,24 @@ +--[[ + A toggle chip (quest item) for subterr_generator quest +]] +local item = {} + +item.Name = "Toggle Chip" + +item.Serialize = function(self) + print("Trying to serailize!") + return "" +end + +item.DeSerialize = function(self,string) + print("Trying to deserialize!") + return self +end + +item.Shape = { + {true,true}, + {true,true}, +} + +print("Hello from togglechip.lua") +nrequire("item.lua").RegisterItem(item) diff --git a/gamemode/itemsystem/scrapgun.lua b/gamemode/itemsystem/scrapgun.lua new file mode 100644 index 0000000..66222d5 --- /dev/null +++ b/gamemode/itemsystem/scrapgun.lua @@ -0,0 +1,60 @@ +--[[ + An example item +]] +local item = {} + +--Required, a name, all item names must be unique +item.Name = "Scrap gun" + +--Optional, a tooltip to display +item.Tooltip = "A gun made from bits of scrap" + +--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 "" +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 +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 + return options +end + +--Required, the shape of this item. +item.Shape = { + {true,true}, + {true}, +} + +--Optional, If this item can be equiped in any player slots, put them here. +item.Equipable = "Left" + +--Optional, what to do when the player clicks, and this item is in the slot in inventory +item.onClick = function(self,owner) + print("pew pew!") +end + +--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) + --local outfit = pac.luadata.ReadFile("pac3/mech.txt") + --who:AttachPACPart(outfit) + --print("onEquip server!") + end +end + +print("Hello from scrapgun.lua") +--Don't forget to register the item! +nrequire("item.lua").RegisterItem(item) diff --git a/gamemode/itemsystem/utility/flashlight.lua b/gamemode/itemsystem/utility/flashlight.lua new file mode 100644 index 0000000..9a87a75 --- /dev/null +++ b/gamemode/itemsystem/utility/flashlight.lua @@ -0,0 +1,88 @@ +--[[ + An example item +]] +local item = {} + +--Required, a name, all item names must be unique +item.Name = "Flashlight" + +--Optional, a tooltip to display when hovered over +item.Tooltip = "An old axe, probably good for fighting." + +--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 "" +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 +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["test"] = function() print("You pressed test!") end + options["toste"] = function() print("You pressed toste!") end + return options +end + +--Optional. Something run once when this item is drawn in a backpack +function item.DoOnPanel(dimagebutton) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png") +end + +--Optional. Something run once when this item is drawn in an equiped slot +function item.DoOnEqupPanel(dimagebutton) + print("called with panel:",panel) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png") +end + +--Optional. Called continuously, use if you need the item to display different stuff at different tiems in the backpack. +function item.Paint(self,width,height) + draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) +end + +--Optional. Called continuously, use if you need the item to display different stuff at different tiems when equiped. +function item.PaintEquiped(self,width,height) + draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) +end + +--Required, the shape of this item in a backpack. +item.Shape = { + {true,true}, +} + +--Optional, If this item can be equiped in any player slots, put them here. +item.Equipable = "Left" + +--Optional, what to do when the player clicks, and this item is in the slot in inventory. only works for items equipable in left and right +local lastontime = {} +item.onClick = function(self,owner) + if CLIENT then return end + if lastontime[owner] then return end + lastontime[owner] = true + timer.Simple(5,function() + lastontime[owner] = nil + end) + owner:Flashlight( not owner:FlashlightIsOn() ) +end + +--Optional, if we should do something special on equip(like draw the PAC for this weapon). See ART.ApplyPAC in /gamemode/shared/sh_pac.lua +item.onEquip = function(self,who) + if CLIENT then return end + who:AllowFlashlight(true) +end + +--Optional, if we should do something speical on unequip(like setting PAC back to normal). Sett ART.RemovePAC in /gamemode/shared/sh_pac.lua +item.onUnEquip = function(self,who) + if CLIENT then return end + who:Flashlight(false) + who:AllowFlashlight(false) +end + + +--Don't forget to register the item! +nrequire("item.lua").RegisterItem(item) diff --git a/gamemode/itemsystem/weapons/knuckledclaw.lua b/gamemode/itemsystem/weapons/knuckledclaw.lua new file mode 100644 index 0000000..2f629f6 --- /dev/null +++ b/gamemode/itemsystem/weapons/knuckledclaw.lua @@ -0,0 +1,163 @@ +--[[ + An example item +]] +local item = {} + +--Required, a name, all item names must be unique +item.Name = "Knuckled Claws" + +--Optional, a tooltip to display +item.Tooltip = "Bits of scrap put togeather to resembel a hammer" + +--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 "" +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 +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 + return options +end + +function item.DoOnPanel(dimagebutton) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png") +end + +function item.DoOnEqupPanel(dimagebutton) + print("called with panel:",panel) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png") +end + +--[[ +function item.Paint(self,width,height) + --print("painting with values",self,width,height) + draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) +end + +function item.PaintEquiped(self,width,height) + --print("painting with values",self,width,height) + draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) +end +]] + +--Required, the shape of this item. +item.Shape = { + {true,true}, +} + +--Optional, If this item can be equiped in any player slots, put them here. +item.Equipable = "Right" + + + +--Optional, what to do when the player clicks, and this item is in the slot in inventory. only works for items equipable in left and right +item.lastSwing = {} +item.onClick = function(self,owner) + item.lastSwing[owner] = item.lastSwing[owner] or 0 + if item.lastSwing[owner] > CurTime() then + print("returning because item.lastSwing is " .. item.lastSwing[owner], "but Curtime is",CurTime()) + return end + item.lastSwing[owner] = CurTime()+1.25 + local fow,rig,up = owner:GetForward(),owner:GetRight(),owner:GetUp() + local movementtbl = { + ["forward"] = function() + owner:SetLuaAnimation("fist_swing_up") + timer.Simple(1.75,function() + owner:StopLuaAnimation("fist_swing_up") + end) + local hits = ART.swingarc(owner,{ + 0.5,0.57,0.65,0.73 + },{ + fow*20 + up*90, + fow*45 + up*70, + fow*35 + up*45, + fow*20 + up*30, + },function(tr) + if tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + tr.Entity:TakeDamage(4, owner, owner:GetActiveWeapon()) + end + print("Hit",tr.Entity) + end) + end, + ["backward"] = function() + owner:SetLuaAnimation("fist_swing_down") + timer.Simple(1.75,function() + owner:StopLuaAnimation("fist_swing_down") + end) + local hits = ART.swingarc(owner,{ + 0.5,0.57,0.65,0.73 + },{ + fow*15 + up*30, + fow*35 + up*45, + fow*25 + up*70, + fow*15 + up*90, + },function(tr) + if tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + tr.Entity:TakeDamage(4, owner, owner:GetActiveWeapon()) + end + print("Hit",tr.Entity) + end) + end, + ["left"] = function() + owner:SetLuaAnimation("fist_swing_left") + timer.Simple(2,function() + owner:StopLuaAnimation("fist_swing_left") + end) + local hits = ART.swingarc(owner,{ + 0.5,0.57,0.65,0.73 + },{ + rig*-30 + up*59, + rig*-10 + fow*30 + up*55, + rig*10 + fow*30 + up*54, + rig*30 + up*50, + },function(tr) + if tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + tr.Entity:TakeDamage(4, owner, owner:GetActiveWeapon()) + end + print("Hit",tr.Entity) + end) + end, + ["right"] = function() + + end, + } + movementtbl[ART.playermovedir(owner)]() +end + +--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) + who:GetActiveWeapon():SetHoldType("fist") + ART.ApplyPAC(who,"knuckledclaws") + --local outfit = pac.luadata.ReadFile("pac3/mech.txt") + --who:AttachPACPart(outfit) + --print("onEquip server!") + end +end + +--Optional, if we should do something speical on unequip(like setting animations back to normal) +item.onUnEquip = function(self,who) + who:GetActiveWeapon():SetHoldType("normal") + ART.RemovePAC(who,"knuckledclaws") +end + +item.onDropped = function(self, ent) + ART.ApplyPAC(ent,"knuckledclaws") +end + +print("Hello from scrapgun.lua") +--Don't forget to register the item! +nrequire("item.lua").RegisterItem(item) diff --git a/gamemode/itemsystem/weapons/rustyaxe.lua b/gamemode/itemsystem/weapons/rustyaxe.lua new file mode 100644 index 0000000..04e54de --- /dev/null +++ b/gamemode/itemsystem/weapons/rustyaxe.lua @@ -0,0 +1,229 @@ +--[[ + An example item +]] +local item = {} + +--Required, a name, all item names must be unique +item.Name = "Rusty Axe" + +--Optional, a tooltip to display +item.Tooltip = "An old axe, probably good for fighting." + +--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 "" +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 +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 +end + +function item.DoOnPanel(dimagebutton) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png") +end + +function item.DoOnEqupPanel(dimagebutton) + print("called with panel:",panel) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png") +end + +--Required, the shape of this item. +item.Shape = { + {true,true}, + {true}, + {true}, +} + +--Optional, If this item can be equiped in any player slots, put them here. +item.Equipable = "Right" + +local swingdata = { + ["fwd"] = { + {0.011,Vector(-25,-3,-11)}, + {0.020,Vector(-25,-1,-3)}, + {0.031,Vector(-21,0,7)}, + {0.040,Vector(-13,-1,16)}, + {0.051,Vector(0,-5,22)}, + {0.060,Vector(17,-12,19)}, + {0.069,Vector(27,-18,11)}, + {0.077,Vector(31,-22,2)}, + {0.087,Vector(32,-26,-6)}, + {0.098,Vector(32,-28,-12)}, + {0.107,Vector(31,-29,-16)}, + {0.117,Vector(31,-29,-17)}, + {0.128,Vector(31,-29,-16)}, + {0.141,Vector(31,-29,-16)}, + }, + ["lft"] = { + {0.009,Vector(-34,-25,3)}, + {0.021,Vector(-29,-33,3)}, + {0.031,Vector(-21,-41,2)}, + {0.042,Vector(-9,-47,0)}, + {0.053,Vector(5,-48,-2)}, + {0.064,Vector(20,-44,-6)}, + {0.075,Vector(31,-34,-10)}, + {0.086,Vector(37,-24,-15)}, + {0.095,Vector(39,-16,-17)}, + {0.106,Vector(39,-10,-19)}, + {0.116,Vector(39,-8,-20)}, + {0.126,Vector(39,-8,-19)}, + {0.134,Vector(39,-9,-19)}, + {0.146,Vector(39,-10,-18)}, + }, + ["rig"] = { + {0.021,Vector(-2,9,11)}, + {0.031,Vector(5,10,10)}, + {0.042,Vector(12,8,9)}, + {0.053,Vector(19,4,6)}, + {0.062,Vector(26,-4,2)}, + {0.072,Vector(29,-12,-4)}, + {0.083,Vector(29,-21,-12)}, + {0.093,Vector(25,-27,-18)}, + {0.102,Vector(22,-30,-22)}, + {0.113,Vector(20,-31,-25)}, + {0.123,Vector(19,-32,-25)}, + {0.133,Vector(19,-32,-25)}, + }, +} + +--Optional, what to do when the player clicks, and this item is in the slot in inventory. only works for items equipable in left and right +item.lastSwing = {} +item.onClick = function(self,owner) + item.lastSwing[owner] = item.lastSwing[owner] or 0 + if item.lastSwing[owner] > CurTime() then + print("returning because item.lastSwing is " .. item.lastSwing[owner], "but Curtime is",CurTime()) + return end + item.lastSwing[owner] = CurTime()+1.33 + local fwd,rig,up = owner:GetForward(),owner:GetRight(),owner:GetUp() + local movementtbl = { + ["forward"] = function() + owner:SetLuaAnimation("axe_swing_up") + timer.Simple(2.33,function() + owner:StopLuaAnimation("axe_swing_up") + end) + timer.Simple(1,function() + ART.TraceWeapon = true + end) + timer.Simple(1.33,function() + ART.TraceWeapon = false + end) + + local times,pos = {},{} + for k,v in ipairs(swingdata["fwd"]) do + times[k] = 1 + v[1] + pos[k] = Vector(v[2]) + pos[k]:Rotate(owner:GetAimVector():Angle()) + end + if pos[1] == nil then return end + local hits = ART.swingarc(owner,times,pos,function(tr) + if not tr.Hit then return end + if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "forward" then + ART.ApplyEffect(owner,"weapon_blocked") + elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) + end + end) + + end, + ["backward"] = function() + + end, + ["left"] = function() + owner:SetLuaAnimation("axe_swing_left") + timer.Simple(2.33,function() + owner:StopLuaAnimation("axe_swing_left") + end) + timer.Simple(1,function() + ART.TraceWeapon = true + end) + timer.Simple(1.33,function() + ART.TraceWeapon = false + end) + + local times,pos = {},{} + for k,v in ipairs(swingdata["lft"]) do + times[k] = 1 + v[1] + pos[k] = Vector(v[2]) + pos[k]:Rotate(owner:GetAimVector():Angle()) + end + if pos[1] == nil then return end + local hits = ART.swingarc(owner,times,pos,function(tr) + if not tr.Hit then return end + if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "left" then + ART.ApplyEffect(owner,"weapon_blocked") + elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) + end + end) + end, + ["right"] = function() + owner:SetLuaAnimation("axe_swing_right") + timer.Simple(2.33,function() + owner:StopLuaAnimation("axe_swing_right") + end) + timer.Simple(1,function() + ART.TraceWeapon = true + end) + timer.Simple(1.33,function() + ART.TraceWeapon = false + end) + + local times,pos = {},{} + for k,v in ipairs(swingdata["rig"]) do + times[k] = 1 + v[1] + pos[k] = Vector(v[2]) + pos[k]:Rotate(owner:GetAimVector():Angle()) + end + if pos[1] == nil then return end + local hits = ART.swingarc(owner,times,pos,function(tr) + if not tr.Hit then return end + if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "right" then + ART.ApplyEffect(owner,"weapon_blocked") + elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) + end + end) + end, + } + movementtbl[ART.playermovedir(owner)]() +end + +--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) + who:GetActiveWeapon():SetHoldType("melee") + ART.ApplyPAC(who,"rustyaxe") + --local outfit = pac.luadata.ReadFile("pac3/mech.txt") + --who:AttachPACPart(outfit) + --print("onEquip server!") + end +end + +--Optional, if we should do something speical on unequip(like setting animations back to normal) +item.onUnEquip = function(self,who) + who:GetActiveWeapon():SetHoldType("normal") + ART.RemovePAC(who,"rustyaxe") +end + +item.onDropped = function(self, ent) + ART.ApplyPAC(ent,"rustyaxe") +end + +print("Hello from scrapgun.lua") +--Don't forget to register the item! +nrequire("item.lua").RegisterItem(item) diff --git a/gamemode/itemsystem/weapons/scraphammer.lua b/gamemode/itemsystem/weapons/scraphammer.lua new file mode 100644 index 0000000..586b331 --- /dev/null +++ b/gamemode/itemsystem/weapons/scraphammer.lua @@ -0,0 +1,233 @@ +--[[ + An example item +]] +local item = {} + +--Required, a name, all item names must be unique +item.Name = "Scrap Hammer" + +--Optional, a tooltip to display +item.Tooltip = "Bits of scrap put togeather to resembel a hammer" + +--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 "" +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 +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 +end + +function item.DoOnPanel(dimagebutton) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png") +end + +function item.DoOnEqupPanel(dimagebutton) + print("called with panel:",panel) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png") +end + +--[[ +function item.Paint(self,width,height) + --print("painting with values",self,width,height) + draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) +end + +function item.PaintEquiped(self,width,height) + --print("painting with values",self,width,height) + draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) +end +]] + +--Required, the shape of this item. +item.Shape = { + {true,true,true}, + {false,true}, + {false,true}, +} + +--Optional, If this item can be equiped in any player slots, put them here. +item.Equipable = "Right" + +local swingdata = { + ["fwd"] = { + {0.007,Vector(-27,1,9)}, + {0.014,Vector(-20,3,16)}, + {0.020,Vector(-11,6,22)}, + {0.027,Vector(0,7,26)}, + {0.032,Vector(15,7,25)}, + {0.039,Vector(28,6,21)}, + {0.045,Vector(38,4,14)}, + {0.052,Vector(46,0,3)}, + {0.059,Vector(50,-3,-6)}, + {0.065,Vector(52,-6,-15)}, + {0.072,Vector(52,-8,-22)}, + {0.078,Vector(51,-10,-28)}, + {0.084,Vector(50,-11,-31)}, + {0.091,Vector(50,-11,-32)}, + {0.097,Vector(50,-11,-32)} + }, + ["lft"] = { + {0.007,Vector(-6,24,2)}, + {0.014,Vector(-1,26,2)}, + {0.020,Vector(5,28,1)}, + {0.027,Vector(12,28,-1)}, + {0.035,Vector(19,27,-4)}, + {0.042,Vector(27,24,-7)}, + {0.048,Vector(37,17,-13)}, + {0.055,Vector(42,12,-17)}, + {0.061,Vector(45,5,-20)}, + {0.068,Vector(48,-2,-23)}, + {0.075,Vector(49,-8,-25)}, + {0.084,Vector(49,-14,-26)}, + {0.091,Vector(49,-19,-27)}, + {0.097,Vector(48,-22,-27)}, + {0.104,Vector(48,-25,-27)}, + {0.110,Vector(48,-26,-27)}, + {0.117,Vector(48,-27,-27)}, + {0.123,Vector(48,-26,-27)}, + {0.131,Vector(48,-26,-27)} + }, + ["rig"] = { + {0.009,Vector(-3,25,2)}, + {0.017,Vector(3,27,1)}, + {0.025,Vector(11,28,-1)}, + {0.032,Vector(20,27,-4)}, + {0.040,Vector(28,24,-7)}, + {0.051,Vector(36,19,-12)}, + {0.059,Vector(42,11,-17)}, + {0.067,Vector(47,2,-22)}, + {0.075,Vector(49,-5,-25)}, + {0.083,Vector(49,-13,-27)}, + {0.090,Vector(49,-19,-28)}, + {0.098,Vector(48,-24,-28)}, + {0.106,Vector(48,-27,-28)}, + {0.114,Vector(48,-28,-28)}, + {0.121,Vector(48,-27,-28)}, + {0.129,Vector(48,-27,-27)} + }, +} + +--Optional, what to do when the player clicks, and this item is in the slot in inventory. only works for items equipable in left and right +item.lastSwing = {} +item.onClick = function(self,owner) + item.lastSwing[owner] = item.lastSwing[owner] or 0 + if item.lastSwing[owner] > CurTime() then + print("returning because item.lastSwing is " .. item.lastSwing[owner], "but Curtime is",CurTime()) + return end + item.lastSwing[owner] = CurTime()+1.33 + local fwd,rig,up = owner:GetForward(),owner:GetRight(),owner:GetUp() + local movementtbl = { + ["forward"] = function() + owner:SetLuaAnimation("hammer_swing_up") + timer.Simple(2.33,function() + owner:StopLuaAnimation("hammer_swing_up") + end) + + local times,pos = {},{} + for k,v in ipairs(swingdata["fwd"]) do + times[k] = 1 + v[1] + pos[k] = Vector(v[2]) + pos[k]:Rotate(owner:GetAimVector():Angle()) + end + if pos[1] == nil then return end + local hits = ART.swingarc(owner,times,pos,function(tr) + if not tr.Hit then return end + if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "forward" then + ART.ApplyEffect(owner,"weapon_blocked") + elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) + end + end) + + end, + ["backward"] = function() + + end, + ["left"] = function() + owner:SetLuaAnimation("hammer_swing_left") + timer.Simple(2.33,function() + owner:StopLuaAnimation("hammer_swing_left") + end) + + local times,pos = {},{} + for k,v in ipairs(swingdata["lft"]) do + times[k] = 1 + v[1] + pos[k] = Vector(v[2]) + pos[k]:Rotate(owner:GetAimVector():Angle()) + end + if pos[1] == nil then return end + local hits = ART.swingarc(owner,times,pos,function(tr) + if not tr.Hit then return end + if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "left" then + ART.ApplyEffect(owner,"weapon_blocked") + elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) + end + end) + end, + ["right"] = function() + owner:SetLuaAnimation("hammer_swing_right") + timer.Simple(2.33,function() + owner:StopLuaAnimation("hammer_swing_right") + end) + + local times,pos = {},{} + for k,v in ipairs(swingdata["rig"]) do + times[k] = 1 + v[1] + pos[k] = Vector(v[2]) + pos[k]:Rotate(owner:GetAimVector():Angle()) + end + if pos[1] == nil then return end + local hits = ART.swingarc(owner,times,pos,function(tr) + if not tr.Hit then return end + if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "right" then + ART.ApplyEffect(owner,"weapon_blocked") + elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) + end + end) + end, + } + movementtbl[ART.playermovedir(owner)]() +end + +--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) + who:GetActiveWeapon():SetHoldType("melee2") + ART.ApplyPAC(who,"scraphammer") + --local outfit = pac.luadata.ReadFile("pac3/mech.txt") + --who:AttachPACPart(outfit) + --print("onEquip server!") + end +end + +--Optional, if we should do something speical on unequip(like setting animations back to normal) +item.onUnEquip = function(self,who) + who:GetActiveWeapon():SetHoldType("normal") + ART.RemovePAC(who,"scraphammer") +end + +item.onDropped = function(self, ent) + ART.ApplyPAC(ent,"scraphammer") +end + +print("Hello from scrapgun.lua") +--Don't forget to register the item! +nrequire("item.lua").RegisterItem(item) diff --git a/gamemode/itemsystem/weapons/seratedknife.lua b/gamemode/itemsystem/weapons/seratedknife.lua new file mode 100644 index 0000000..7248426 --- /dev/null +++ b/gamemode/itemsystem/weapons/seratedknife.lua @@ -0,0 +1,199 @@ +--[[ + An example item +]] +local item = {} + +--Required, a name, all item names must be unique +item.Name = "Serated Knife" + +--Optional, a tooltip to display +item.Tooltip = "Bits of scrap put togeather to resembel a hammer" + +--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 "" +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 +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 +end + +function item.DoOnPanel(dimagebutton) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png") +end + +function item.DoOnEqupPanel(dimagebutton) + print("called with panel:",panel) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png") +end + +--[[ +function item.Paint(self,width,height) + --print("painting with values",self,width,height) + draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) +end + +function item.PaintEquiped(self,width,height) + --print("painting with values",self,width,height) + draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) +end +]] + +--Required, the shape of this item. +item.Shape = { + {true,true}, +} + +--Optional, If this item can be equiped in any player slots, put them here. +item.Equipable = "Right" + +local function attacktrace(tr,owner) + if not tr.Hit then return end + if tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) + end +end + + +--Optional, what to do when the player clicks, and this item is in the slot in inventory. only works for items equipable in left and right +item.lastSwing = {} +local animationtime = 1.833333 +item.onClick = function(self,owner) + item.lastSwing[owner] = item.lastSwing[owner] or 0 + if item.lastSwing[owner] > CurTime() then + print("returning because item.lastSwing is " .. item.lastSwing[owner], "but Curtime is",CurTime()) + return end + item.lastSwing[owner] = CurTime()+animationtime + local fow,rig,up = owner:GetForward(),owner:GetRight(),owner:GetUp() + local movementtbl = { + ["forward"] = function() + owner:SetLuaAnimation("knife_swing_up") + timer.Simple(animationtime,function() + owner:StopLuaAnimation("knife_swing_up") + end) + local hits = ART.swingarc(owner,{ + 0.5,0.611,0.722,0.833 + },{ + fow*20 + up*90, + fow*45 + up*70, + fow*35 + up*45, + fow*20 + up*30, + },function(tr) + if not tr.Hit then return end + if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "forward" then + print("Entity blocked!") + ART.ApplyEffect(owner,"weapon_blocked") + elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + print("Got past blocking, it was",tr.Entity.Blocking) + tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) + end + end) + end, + ["backward"] = function() + owner:SetLuaAnimation("knife_swing_down") + timer.Simple(animationtime,function() + owner:StopLuaAnimation("knife_swing_down") + end) + local hits = ART.swingarc(owner,{ + 0.5,0.611,0.722,0.833 + },{ + fow*15 + up*30, + fow*35 + up*45, + fow*25 + up*70, + fow*15 + up*90, + },function(tr) + if not tr.Hit then return end + if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "backward" then + print("Entity blocked!") + elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + print("Got past blocking, it was",tr.Entity.Blocking) + tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) + end + end) + end, + ["left"] = function() + owner:SetLuaAnimation("knife_swing_left") + timer.Simple(animationtime,function() + owner:StopLuaAnimation("knife_swing_left") + end) + local hits = ART.swingarc(owner,{ + 0.5,0.611,0.722,0.833 + },{ + rig*30 + up*59, + rig*10 + fow*30 + up*55, + rig*-10 + fow*30 + up*54, + rig*-30 + up*50, + },function(tr) + if not tr.Hit then return end + if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "left" then + print("Entity blocked!") + elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + print("Got past blocking, it was",tr.Entity.Blocking) + tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) + end + end) + end, + ["right"] = function() + owner:SetLuaAnimation("knife_swing_right") + timer.Simple(animationtime,function() + owner:StopLuaAnimation("knife_swing_right") + end) + local hits = ART.swingarc(owner,{ + 0.5,0.611,0.722,0.833 + },{ + rig*-30 + up*59, + rig*-10 + fow*30 + up*55, + rig*10 + fow*30 + up*54, + rig*30 + up*50, + },function(tr) + if not tr.Hit then return end + if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "right" then + print("Entity blocked!") + elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + print("Got past blocking, it was",tr.Entity.Blocking) + tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) + end + end) + end, + } + movementtbl[ART.playermovedir(owner)]() +end + +--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) + who:GetActiveWeapon():SetHoldType("knife") + ART.ApplyPAC(who,"seratedknife") + --local outfit = pac.luadata.ReadFile("pac3/mech.txt") + --who:AttachPACPart(outfit) + --print("onEquip server!") + end +end + +--Optional, if we should do something speical on unequip(like setting animations back to normal) +item.onUnEquip = function(self,who) + who:GetActiveWeapon():SetHoldType("normal") + ART.RemovePAC(who,"seratedknife") +end + +item.onDropped = function(self, ent) + ART.ApplyPAC(ent,"seratedknife") +end + +--Don't forget to register the item! +nrequire("item.lua").RegisterItem(item) diff --git a/gamemode/itemsystem/weapons_common.lua b/gamemode/itemsystem/weapons_common.lua new file mode 100644 index 0000000..6f553fa --- /dev/null +++ b/gamemode/itemsystem/weapons_common.lua @@ -0,0 +1,70 @@ + +ART = ART or {} + +--- Finds the direction a player is moveing. +-- @param player The player to find the move direction of +-- @return The string "forward", "backward", "right", or "left" +function ART.playermovedir(player) + local vel = player:GetVelocity():GetNormalized() + vel.z = 0 + local swings = { + {player:GetForward(),"forward"}, + {-player:GetForward(),"backward"}, + {player:GetRight(),"right"}, + {-player:GetRight(),"left"} + } + table.sort(swings,function(a,b) + return vel:Dot(a[1]) > vel:Dot(b[1]) + end) + return swings[1][2] +end + + +local positionset = {} +--- The arc swing of a weapon. +-- Finds anything that a weapon should hit in it's swing, and calls a function on it. +-- @param player The player that's swinging the weapon +-- @param tiems A table of times that the trace calculations should be done at, this table needs to be the same length as the positions table +-- @param positions The position offsets from the player that swung that should be the start/end points of the arc +-- @param onhit A function to call on any entities that were hit in the swing of the weapon. +function ART.swingarc(player,times,positions,onhit) + local positionpoints = {} + table.insert(positionset,positionpoints) + for k,v in ipairs(times) do + timer.Simple(v,function() + ART.TraceWeapon = true + ART.TraceStart = CurTime() + print("positions[k]",positions[k],"playerpos",player:GetPos(),"add",Vector(0,0,64)) + local weaponpos = positions[k] + player:GetPos() + Vector(0,0,64) + table.insert(positionpoints,weaponpos) + if #positionpoints > 1 then + --print("Trace from ", positionpoints[#positionpoints-1], " to ", positionpoints[#positionpoints]) + local tr = util.TraceLine({ + start = positionpoints[#positionpoints-1], + endpos = positionpoints[#positionpoints], + }) + onhit(tr) + end + end) + end + timer.Simple(times[#times],function() + print("Inserted swing, drawn positions are now:") + PrintTable(positionset) + ART.TraceWeapon = false + end) +end + +hook.Add( "HUDPaint", "weaponswings", function() + cam.Start3D() -- Start the 3D function so we can draw onto the screen. + for k,v in pairs(positionset) do + for i = 1,#v-1 do + render.DrawLine( v[i], v[i+1], Color(255,0,0,255), false ) + render.DrawLine( v[i], v[i]+Vector(0,0,20),Color(0,255,0,255),false) + end + end + --render.SetMaterial( material ) -- Tell render what material we want, in this case the flash from the gravgun + --render.DrawSprite( pos, 16, 16, white ) -- Draw the sprite in the middle of the map, at 16x16 in it's original colour with full alpha. + cam.End3D() +end ) + +return wcommon diff --git a/gamemode/npcsystem/sv_blockingdummy.lua b/gamemode/npcsystem/sv_blockingdummy.lua new file mode 100644 index 0000000..2b98b97 --- /dev/null +++ b/gamemode/npcsystem/sv_blockingdummy.lua @@ -0,0 +1,107 @@ + +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." +NPC.Class = "Ambient" --Ambient, Agressive, Boss +NPC.Model = "models/headcrab.mdl" + +NPC.Stats = { + ["Vitality"] = 100000, + ["Speed"] = 400, + ["AwareDist"] = 1000, + ["Accel"] = 100, + ["Decel"] = 200, + ["Step"] = 20, --Step height + ["Hull"] = HULL_TINY +} + +--Some npc's like birds have diffent names for their idle sequences +NPC.IdleSequences = { + [0] = "lookaround", + [1] = "Idle01", +} + +--Drops should be formated as [index]={["item name"], percent_drop} where percent_drop is a number from 0 to 100 + +NPC.Drops = { +} + +--Attacks should be formated as [i]={function attackpriority() = function doattack()} +local checknothing = function(self,ply) + return 1 +end + +local donothing = function(self,ply) +end +NPC.Attacks = { + [1] = {--run away from the player + [checknothing] = donothing + }, +} + +--A function that takes a position and returns true if this is an acceptable place to spawn +function NPC:SpawnLocations(pos) + return true +end + +--The entity that is this npc's current target, if it has one. Nil otherwise +NPC.Target = nil + +--All enemies that this NPC is aware of +NPC.AwareEnemies = {} +--Attack priority is a fucntion that takes a player, and returns an int describing it's prority to attack (higher = more important) NPC will always attack the player with the highest priority +function NPC:AttackPriority(ply) + if not ply then return 0 end + return 1 +end + +--What to replace the ENT:RunBehaviour with +function NPC:Act(deltat) +end + +--What to replace ENT:OnStuck with +function NPC:Stuck() + +end + +local blockorder = { + "forward", + "right", + "backward", + "left" +} +local cursor = 0 +function NPC:OnDammage(ammount) + self.Blocking = blockorder[cursor + 1] + cursor = (cursor + 1) % 4 + print("A dummy was hit for",ammount:GetDamage(),"!") + print("Blocking is now",self.Blocking) +end + +--These are just here to tell the editors/develoeprs what functions are available.. dont un-comment them out, as this could affect all the items. +/* +function NPC:OnSpawn() +end + +--If we need to do more than just reduce health on dammage +function NPC:OnDammage(ammount) +end + +--If we need to do more than just drop items on death +function NPC:OnDeath() +end + +--A particular spell was cast on this npc by player +function NPC:OnSpell(spell, player) +end + +function NPC:OnFindEnemy(enemy) +end + +--Called when the npc is attacking anything with any attack +function NPC:OnAttack(target) +end +*/ +n.RegisterNPC(NPC) +--ART.RegisterNPC(NPC) diff --git a/gamemode/npcsystem/sv_dummy.lua b/gamemode/npcsystem/sv_dummy.lua new file mode 100644 index 0000000..6a7e894 --- /dev/null +++ b/gamemode/npcsystem/sv_dummy.lua @@ -0,0 +1,97 @@ +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." +NPC.Class = "Ambient" --Ambient, Agressive, Boss +NPC.Model = "models/headcrab.mdl" + +NPC.Stats = { + ["Vitality"] = 100000, + ["Speed"] = 400, + ["AwareDist"] = 1000, + ["Accel"] = 100, + ["Decel"] = 200, + ["Step"] = 20, --Step height + ["Hull"] = HULL_TINY +} + +--Some npc's like birds have diffent names for their idle sequences +NPC.IdleSequences = { + [0] = "lookaround", + [1] = "Idle01", +} + +--Drops should be formated as [index]={["item name"], percent_drop} where percent_drop is a number from 0 to 100 + +NPC.Drops = { +} + +--Attacks should be formated as [i]={function attackpriority() = function doattack()} +local checknothing = function(self,ply) + return 1 +end + +local donothing = function(self,ply) +end +NPC.Attacks = { + [1] = {--run away from the player + [checknothing] = donothing + }, +} + +--A function that takes a position and returns true if this is an acceptable place to spawn +function NPC:SpawnLocations(pos) + return true +end + +--The entity that is this npc's current target, if it has one. Nil otherwise +NPC.Target = nil + +--All enemies that this NPC is aware of +NPC.AwareEnemies = {} +--Attack priority is a fucntion that takes a player, and returns an int describing it's prority to attack (higher = more important) NPC will always attack the player with the highest priority +function NPC:AttackPriority(ply) + if not ply then return 0 end + return 1 +end + +--What to replace the ENT:RunBehaviour with +function NPC:Act(deltat) +end + +--What to replace ENT:OnStuck with +function NPC:Stuck() + +end + +function NPC:OnDammage(ammount) + print("A dummy was hit for",ammount:GetDamage(),"!") +end + +--These are just here to tell the editors/develoeprs what functions are available.. dont un-comment them out, as this could affect all the items. +/* +function NPC:OnSpawn() +end + +--If we need to do more than just reduce health on dammage +function NPC:OnDammage(ammount) +end + +--If we need to do more than just drop items on death +function NPC:OnDeath() +end + +--A particular spell was cast on this npc by player +function NPC:OnSpell(spell, player) +end + +function NPC:OnFindEnemy(enemy) +end + +--Called when the npc is attacking anything with any attack +function NPC:OnAttack(target) +end +*/ + +n.RegisterNPC(NPC) diff --git a/gamemode/npcsystem/sv_rat.lua b/gamemode/npcsystem/sv_rat.lua new file mode 100644 index 0000000..fadbc8d --- /dev/null +++ b/gamemode/npcsystem/sv_rat.lua @@ -0,0 +1,114 @@ +local n = nrequire("sv_npcsystem.lua") +local NPC = {} +NPC.Name = "Rat" +NPC.Desc = "A nasty little guy" +NPC.Class = "Ambient" --Ambient, Agressive, Boss +NPC.Model = "models/headcrab.mdl" + +NPC.Stats = { + ["Vitality"] = 10, + ["Speed"] = 400, + ["AwareDist"] = 1000, + ["Accel"] = 100, + ["Decel"] = 200, + ["Step"] = 20, --Step height + ["Hull"] = HULL_TINY +} + +--Some npc's like birds have diffent names for their idle sequences +NPC.IdleSequences = { + [0] = "lookaround", + [1] = "Idle01", +} + +--Drops should be formated as [index]={["item name"], percent_drop} where percent_drop is a number from 0 to 100 + +NPC.Drops = { + [0] = {"Rat Meat",100},--Rats will drop at least 1 meat, and have a 50% chance of dropping 2 + [1] = {"Rat Meat",50}, +} + +--Attacks should be formated as [i]={function attackpriority() = function doattack()} +local checkrun = function(self,ply) + --If we're aware of any enemies, run away! + return 1 +end +local runseq +local dorun = function(self,ply) + if runseq == nil then + runseq = self:LookupSequence("Run1") + end + self:StartActivity(ACT_FLY) + self:SetSequence( runseq ) + 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() + local direction = Vector(tpos.x - ppos.x, tpos.y - ppos.y, tpos.z - ppos.z) + direction:Normalize() + local addition = direction * 1000 + local topos = self:GetPos() + addition + --print("I want to go to ", topos) + self.TargetPos = topos +end +NPC.Attacks = { + [1] = {--run away from the player + [checkrun] = dorun + }, +} + +--A function that takes a position and returns true if this is an acceptable place to spawn +function NPC:SpawnLocations(pos) + return true +end + +--The entity that is this npc's current target, if it has one. Nil otherwise +NPC.Target = nil + +--All enemies that this NPC is aware of +NPC.AwareEnemies = {} +--Attack priority is a fucntion that takes a player, and returns an int describing it's prority to attack (higher = more important) NPC will always attack the player with the highest priority +function NPC:AttackPriority(ply) + if not ply then return 0 end + local plypos = ply:GetPos() + local mypos = self:GetPos() + if not plypos then return 0 end + local dist = plypos:Distance(mypos) + return self.Stats["AwareDist"] - dist +end + +--What to replace the ENT:RunBehaviour with +function NPC:Act(deltat) +end + +--What to replace ENT:OnStuck with +function NPC:Stuck() + +end + +--These are just here to tell the editors/develoeprs what functions are available.. dont un-comment them out, as this could affect all the items. +/* +function NPC:OnSpawn() +end + +--If we need to do more than just reduce health on dammage +function NPC:OnDammage(ammount) +end + +--If we need to do more than just drop items on death +function NPC:OnDeath() +end + +--A particular spell was cast on this npc by player +function NPC:OnSpell(spell, player) +end + +function NPC:OnFindEnemy(enemy) +end + +--Called when the npc is attacking anything with any attack +function NPC:OnAttack(target) +end +*/ + +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/itemsystem/armor/balaclava.lua b/gamemode/shared/itemsystem/armor/balaclava.lua deleted file mode 100644 index 8b4b8d2..0000000 --- a/gamemode/shared/itemsystem/armor/balaclava.lua +++ /dev/null @@ -1,80 +0,0 @@ ---[[ - An example item -]] -local item = {} - ---Required, a name, all item names must be unique -item.Name = "Balaclava" - ---Optional, a tooltip to display -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 "" -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 -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 -end - -function item.DoOnPanel(dimagebutton) - dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png") -end - -function item.DoOnEqupPanel(dimagebutton) - print("called with panel:",panel) - dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png") -end - ---[[ -function item.Paint(self,width,height) - --print("painting with values",self,width,height) - draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) -end - -function item.PaintEquiped(self,width,height) - --print("painting with values",self,width,height) - draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) -end -]] - ---Required, the shape of this item. -item.Shape = { - {true,true}, - {true,true}, -} - ---Optional, If this item can be equiped in any player slots, put them here. -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 -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") -end - -print("Hello from balaclava.lua") ---Don't forget to register the item! -ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/exampleitem.lua b/gamemode/shared/itemsystem/exampleitem.lua deleted file mode 100644 index 066e107..0000000 --- a/gamemode/shared/itemsystem/exampleitem.lua +++ /dev/null @@ -1,85 +0,0 @@ ---[[ - An example item -]] -local item = {} - ---Required, a name, all item names must be unique -item.Name = "Test item" - ---Optional, a tooltip to display when hovered over -item.Tooltip = "An old axe, probably good for fighting." - ---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 "" -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 -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["test"] = function() print("You pressed test!") end - options["toste"] = function() print("You pressed toste!") end - return options -end - ---Optional. Something run once when this item is drawn in a backpack -function item.DoOnPanel(dimagebutton) - dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png") -end - ---Optional. Something run once when this item is drawn in an equiped slot -function item.DoOnEqupPanel(dimagebutton) - print("called with panel:",panel) - dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png") -end - ---Optional. Called continuously, use if you need the item to display different stuff at different tiems in the backpack. -function item.Paint(self,width,height) - draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) -end - ---Optional. Called continuously, use if you need the item to display different stuff at different tiems when equiped. -function item.PaintEquiped(self,width,height) - draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) -end - ---Required, the shape of this item in a backpack. -item.Shape = { - {true}, - {true}, - {true}, -} - ---Optional, If this item can be equiped in any player slots, put them here. -item.Equipable = "Right" - ---Optional, what to do when the player clicks, and this item is in the slot in inventory. only works for items equipable in left and right -item.onClick = function(self,owner) - print("pew pew!") -end - ---Optional, if we should do something special on equip(like draw the PAC for this weapon). See ART.ApplyPAC in /gamemode/shared/sh_pac.lua -item.onEquip = function(self,who) - print("Oh boy! I'm getting used!") -end - ---Optional, if we should do something speical on unequip(like setting PAC back to normal). Sett ART.RemovePAC in /gamemode/shared/sh_pac.lua -item.onUnEquip = function(self,who) - print("Aw, I'm being stored :(") -end - ---Technically optional, but item will display as a rock if you don't have it. If you want to do something other than drop on dropped, remove ent. -item.onDropped = function(self,ent) - print("I've been dropped!(BUVVV WUB WUB WUB WUB WUB)") -end - -print("Hello from exampleitem.lua") ---Don't forget to register the item! -nrequire("item.lua").RegisterItem(item) diff --git a/gamemode/shared/itemsystem/foodstuffs/ratmeat.lua b/gamemode/shared/itemsystem/foodstuffs/ratmeat.lua deleted file mode 100644 index 5310fe2..0000000 --- a/gamemode/shared/itemsystem/foodstuffs/ratmeat.lua +++ /dev/null @@ -1,46 +0,0 @@ ---[[ - An example item -]] -local item = {} - ---Required, a name, all item names must be unique -item.Name = "Rat Meat" - ---Optional, a tooltip to display when hovered over -item.Tooltip = "Disgusting, disease-ridden meat." - ---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 "" -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 -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["test"] = function() print("You pressed test!") end - options["toste"] = function() print("You pressed toste!") end - return options -end - ---Optional. Something run once when this item is drawn in a backpack -function item.DoOnPanel(dimagebutton) - --dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png") -end - ---Required, the shape of this item in a backpack. -item.Shape = { - {true} -} - -item.onDropped = function(self, ent) - ART.ApplyPAC(ent,"ratmeat") -end ---Don't forget to register the item! -ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/foodstuffs/watermelon.lua b/gamemode/shared/itemsystem/foodstuffs/watermelon.lua deleted file mode 100644 index 2b9f7cb..0000000 --- a/gamemode/shared/itemsystem/foodstuffs/watermelon.lua +++ /dev/null @@ -1,55 +0,0 @@ ---[[ - An example item -]] -local item = {} - ---Required, a name, all item names must be unique -item.Name = "Watermelon" - ---Optional, a tooltip to display when hovered over -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 "" -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 -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) - 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() - net.Start("eat_watermelon") - net.SendToServer() - end - return options -end - ---Required, the shape of this item in a backpack. -item.Shape = { - {true,true,true}, - {true,true,true}, - {true,true,true}, -} - -item.onDropped = function(self, ent) - ART.ApplyPAC(ent,"Watermelon") -end - -print("Hello from exampleitem.lua") ---Don't forget to register the item! -ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/item_common.lua b/gamemode/shared/itemsystem/item_common.lua deleted file mode 100644 index b4b7cce..0000000 --- a/gamemode/shared/itemsystem/item_common.lua +++ /dev/null @@ -1,76 +0,0 @@ -if CLIENT then - ART.DropItem = function(item) - local i = item - print("Trying to drop item, Item was ") - PrintTable(item) - return function() - local data = item:Serialize() - net.Start("dropitem") - net.WriteString(item.Name) - net.WriteUInt(#data,32) - net.WriteData(data,#data) - net.SendToServer() - end - end - -else - util.AddNetworkString("dropitem") - - function gencompareto(item) - --Two items are equal if their Serialize()s are the same. - local tserialize = item:Serialize() - return function(otheritem) - local oserialize = otheritem:Serialize() - return tserialize == oserialize - end - end - - function ART.CreateDroppedItem(itemtbl, where) - local e = ents.Create("art_droppeditem") - e.Model = "models/props_junk/Rock001a.mdl" - e.Item = itemtbl - e:SetPos(where) - e:Spawn() - end - - net.Receive("dropitem",function(len,ply) - local itemtype = net.ReadString() - local itemdatalen = net.ReadUInt(32) - local itemdata = net.ReadData(itemdatalen) - local itemtbl = ART.GetItemByName(itemtype) - local item = itemtbl:DeSerialize(itemdata) - - print("I want to drop:") - PrintTable(item) - print("Do I have one?") - local row,col,n = ply:HasItem(gencompareto(item)) - print("row",row,"col",col,"n",n) - --To find out where to drop the item, go out from player's view, then down. - local pes = ply:GetPos()+Vector(0,0,64) - local pee = ply:GetForward()*50 + Vector(0,0,64) + ply:GetPos() - local tr1d = { - ["start"] = pes, - ["endpos"] = pee, - ["filter"] = ply, - } - local tr1r = util.TraceLine(tr1d) - local fes - if tr1r.hit then --Use where it hit and go down - fes = tr1r.HitPos - else --Use the spot 50 units in front of us - fes = pee - end - local tr2d = { - ["start"] = fes, - ["endpos"] = fes + Vector(0,0,-64), - } - local tr2r = util.TraceLine(tr2d) - local itempos = tr2r.HitPos - print("Dropping item at",itempos) - if row and col and n then - print("DropItem is",ART.DropItem) - ART.CreateDroppedItem(item,itempos) - ply:RemoveItemAt(n,row,col) - end - end) -end diff --git a/gamemode/shared/itemsystem/quest/rougebadge.lua b/gamemode/shared/itemsystem/quest/rougebadge.lua deleted file mode 100644 index dad0f71..0000000 --- a/gamemode/shared/itemsystem/quest/rougebadge.lua +++ /dev/null @@ -1,38 +0,0 @@ ---[[ - An example item -]] -local item = {} - ---Required, a name, all item names must be unique -item.Name = "Rouge Newbie Badge" - ---Optional, a tooltip to display when hovered over -item.Tooltip = "A tiny peice of metal, kinda looks like a dagger." - ---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 "" -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 -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["test"] = function() print("You pressed test!") end - options["toste"] = function() print("You pressed toste!") end - return options -end - ---Required, the shape of this item in a backpack. -item.Shape = { - {true} -} - - -ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/quest/rougebook.lua b/gamemode/shared/itemsystem/quest/rougebook.lua deleted file mode 100644 index 4eabe06..0000000 --- a/gamemode/shared/itemsystem/quest/rougebook.lua +++ /dev/null @@ -1,68 +0,0 @@ ---[[ - A quest item for the prayer book quest -]] -local item = {} - -item.Name = "Orders of the Silent Circle" - -item.Serialize = function(self) - print("Trying to serailize!") - return "" -end - -item.DeSerialize = function(self,string) - print("Trying to deserialize!") - return self -end - -item.Shape = { - {true,true}, - {true,true}, -} - -local rougeadvice = { - "He who refuses to trim his beard will find himself in a hairy situation.", - "You'll get tired defending from a man in a car", - "You'll get exhaused attacking a man in a car.", - "Sex is not the answer, it is the question. And the answer is 'yes'.", - "The 'Darkest Hour' is when you can't find the matches.", - "If you eat beans before church, you will sit in your own pew.", - "He who seeks challenges will be puzzeled.", - "He who fishes in another man's well is likely to catch crabs.", - "Enjoy masturbation, it's sex with someone you love.", -} - -local lhint = 1 - -function item.GetOptions(self) - local options = {} - options["Read"] = function() - local readframe = vgui.Create( "DFrame" ) - readframe:SetPos( ScrW()/2 - 100, ScrH()/2 - 100) - readframe:SetSize(200,200) - readframe:SetTitle("Orders of the Silent Circle") - readframe:MakePopup() - - - local readpanel = vgui.Create( "DPanel", readframe ) - readpanel:SetPos( 5, 30 ) - readpanel:SetSize( 190, 170 ) - function readpanel:Paint(w,h) end - - - local readtext = vgui.Create( "DLabel", readpanel ) - readtext:SetPos( 40, 40 ) - readtext:SetText(rougeadvice[lhint]) - readtext:SetDark() - readtext:Dock(FILL) - readtext:SetWrap(true) - lhint = (lhint % #rougeadvice) + 1 - end - return options -end - -item.onDropped = function(self, ent) - ART.ApplyPAC(ent,"book1") -end - -ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/quest/togglechip.lua b/gamemode/shared/itemsystem/quest/togglechip.lua deleted file mode 100644 index 7b8ee04..0000000 --- a/gamemode/shared/itemsystem/quest/togglechip.lua +++ /dev/null @@ -1,24 +0,0 @@ ---[[ - A toggle chip (quest item) for subterr_generator quest -]] -local item = {} - -item.Name = "Toggle Chip" - -item.Serialize = function(self) - print("Trying to serailize!") - return "" -end - -item.DeSerialize = function(self,string) - print("Trying to deserialize!") - return self -end - -item.Shape = { - {true,true}, - {true,true}, -} - -print("Hello from togglechip.lua") -ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/scrapgun.lua b/gamemode/shared/itemsystem/scrapgun.lua deleted file mode 100644 index bf21b42..0000000 --- a/gamemode/shared/itemsystem/scrapgun.lua +++ /dev/null @@ -1,60 +0,0 @@ ---[[ - An example item -]] -local item = {} - ---Required, a name, all item names must be unique -item.Name = "Scrap gun" - ---Optional, a tooltip to display -item.Tooltip = "A gun made from bits of scrap" - ---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 "" -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 -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 - return options -end - ---Required, the shape of this item. -item.Shape = { - {true,true}, - {true}, -} - ---Optional, If this item can be equiped in any player slots, put them here. -item.Equipable = "Left" - ---Optional, what to do when the player clicks, and this item is in the slot in inventory -item.onClick = function(self,owner) - print("pew pew!") -end - ---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) - --local outfit = pac.luadata.ReadFile("pac3/mech.txt") - --who:AttachPACPart(outfit) - --print("onEquip server!") - end -end - -print("Hello from scrapgun.lua") ---Don't forget to register the item! -ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/utility/flashlight.lua b/gamemode/shared/itemsystem/utility/flashlight.lua deleted file mode 100644 index 9f2cc69..0000000 --- a/gamemode/shared/itemsystem/utility/flashlight.lua +++ /dev/null @@ -1,88 +0,0 @@ ---[[ - An example item -]] -local item = {} - ---Required, a name, all item names must be unique -item.Name = "Flashlight" - ---Optional, a tooltip to display when hovered over -item.Tooltip = "An old axe, probably good for fighting." - ---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 "" -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 -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["test"] = function() print("You pressed test!") end - options["toste"] = function() print("You pressed toste!") end - return options -end - ---Optional. Something run once when this item is drawn in a backpack -function item.DoOnPanel(dimagebutton) - dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png") -end - ---Optional. Something run once when this item is drawn in an equiped slot -function item.DoOnEqupPanel(dimagebutton) - print("called with panel:",panel) - dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png") -end - ---Optional. Called continuously, use if you need the item to display different stuff at different tiems in the backpack. -function item.Paint(self,width,height) - draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) -end - ---Optional. Called continuously, use if you need the item to display different stuff at different tiems when equiped. -function item.PaintEquiped(self,width,height) - draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) -end - ---Required, the shape of this item in a backpack. -item.Shape = { - {true,true}, -} - ---Optional, If this item can be equiped in any player slots, put them here. -item.Equipable = "Left" - ---Optional, what to do when the player clicks, and this item is in the slot in inventory. only works for items equipable in left and right -local lastontime = {} -item.onClick = function(self,owner) - if CLIENT then return end - if lastontime[owner] then return end - lastontime[owner] = true - timer.Simple(5,function() - lastontime[owner] = nil - end) - owner:Flashlight( not owner:FlashlightIsOn() ) -end - ---Optional, if we should do something special on equip(like draw the PAC for this weapon). See ART.ApplyPAC in /gamemode/shared/sh_pac.lua -item.onEquip = function(self,who) - if CLIENT then return end - who:AllowFlashlight(true) -end - ---Optional, if we should do something speical on unequip(like setting PAC back to normal). Sett ART.RemovePAC in /gamemode/shared/sh_pac.lua -item.onUnEquip = function(self,who) - if CLIENT then return end - who:Flashlight(false) - who:AllowFlashlight(false) -end - - ---Don't forget to register the item! -ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/weapons/knuckledclaw.lua b/gamemode/shared/itemsystem/weapons/knuckledclaw.lua deleted file mode 100644 index 2db8117..0000000 --- a/gamemode/shared/itemsystem/weapons/knuckledclaw.lua +++ /dev/null @@ -1,163 +0,0 @@ ---[[ - An example item -]] -local item = {} - ---Required, a name, all item names must be unique -item.Name = "Knuckled Claws" - ---Optional, a tooltip to display -item.Tooltip = "Bits of scrap put togeather to resembel a hammer" - ---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 "" -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 -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 - return options -end - -function item.DoOnPanel(dimagebutton) - dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png") -end - -function item.DoOnEqupPanel(dimagebutton) - print("called with panel:",panel) - dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png") -end - ---[[ -function item.Paint(self,width,height) - --print("painting with values",self,width,height) - draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) -end - -function item.PaintEquiped(self,width,height) - --print("painting with values",self,width,height) - draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) -end -]] - ---Required, the shape of this item. -item.Shape = { - {true,true}, -} - ---Optional, If this item can be equiped in any player slots, put them here. -item.Equipable = "Right" - - - ---Optional, what to do when the player clicks, and this item is in the slot in inventory. only works for items equipable in left and right -item.lastSwing = {} -item.onClick = function(self,owner) - item.lastSwing[owner] = item.lastSwing[owner] or 0 - if item.lastSwing[owner] > CurTime() then - print("returning because item.lastSwing is " .. item.lastSwing[owner], "but Curtime is",CurTime()) - return end - item.lastSwing[owner] = CurTime()+1.25 - local fow,rig,up = owner:GetForward(),owner:GetRight(),owner:GetUp() - local movementtbl = { - ["forward"] = function() - owner:SetLuaAnimation("fist_swing_up") - timer.Simple(1.75,function() - owner:StopLuaAnimation("fist_swing_up") - end) - local hits = ART.swingarc(owner,{ - 0.5,0.57,0.65,0.73 - },{ - fow*20 + up*90, - fow*45 + up*70, - fow*35 + up*45, - fow*20 + up*30, - },function(tr) - if tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then - tr.Entity:TakeDamage(4, owner, owner:GetActiveWeapon()) - end - print("Hit",tr.Entity) - end) - end, - ["backward"] = function() - owner:SetLuaAnimation("fist_swing_down") - timer.Simple(1.75,function() - owner:StopLuaAnimation("fist_swing_down") - end) - local hits = ART.swingarc(owner,{ - 0.5,0.57,0.65,0.73 - },{ - fow*15 + up*30, - fow*35 + up*45, - fow*25 + up*70, - fow*15 + up*90, - },function(tr) - if tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then - tr.Entity:TakeDamage(4, owner, owner:GetActiveWeapon()) - end - print("Hit",tr.Entity) - end) - end, - ["left"] = function() - owner:SetLuaAnimation("fist_swing_left") - timer.Simple(2,function() - owner:StopLuaAnimation("fist_swing_left") - end) - local hits = ART.swingarc(owner,{ - 0.5,0.57,0.65,0.73 - },{ - rig*-30 + up*59, - rig*-10 + fow*30 + up*55, - rig*10 + fow*30 + up*54, - rig*30 + up*50, - },function(tr) - if tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then - tr.Entity:TakeDamage(4, owner, owner:GetActiveWeapon()) - end - print("Hit",tr.Entity) - end) - end, - ["right"] = function() - - end, - } - movementtbl[ART.playermovedir(owner)]() -end - ---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) - who:GetActiveWeapon():SetHoldType("fist") - ART.ApplyPAC(who,"knuckledclaws") - --local outfit = pac.luadata.ReadFile("pac3/mech.txt") - --who:AttachPACPart(outfit) - --print("onEquip server!") - end -end - ---Optional, if we should do something speical on unequip(like setting animations back to normal) -item.onUnEquip = function(self,who) - who:GetActiveWeapon():SetHoldType("normal") - ART.RemovePAC(who,"knuckledclaws") -end - -item.onDropped = function(self, ent) - ART.ApplyPAC(ent,"knuckledclaws") -end - -print("Hello from scrapgun.lua") ---Don't forget to register the item! -ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/weapons/rustyaxe.lua b/gamemode/shared/itemsystem/weapons/rustyaxe.lua deleted file mode 100644 index b26597c..0000000 --- a/gamemode/shared/itemsystem/weapons/rustyaxe.lua +++ /dev/null @@ -1,229 +0,0 @@ ---[[ - An example item -]] -local item = {} - ---Required, a name, all item names must be unique -item.Name = "Rusty Axe" - ---Optional, a tooltip to display -item.Tooltip = "An old axe, probably good for fighting." - ---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 "" -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 -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 -end - -function item.DoOnPanel(dimagebutton) - dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png") -end - -function item.DoOnEqupPanel(dimagebutton) - print("called with panel:",panel) - dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png") -end - ---Required, the shape of this item. -item.Shape = { - {true,true}, - {true}, - {true}, -} - ---Optional, If this item can be equiped in any player slots, put them here. -item.Equipable = "Right" - -local swingdata = { - ["fwd"] = { - {0.011,Vector(-25,-3,-11)}, - {0.020,Vector(-25,-1,-3)}, - {0.031,Vector(-21,0,7)}, - {0.040,Vector(-13,-1,16)}, - {0.051,Vector(0,-5,22)}, - {0.060,Vector(17,-12,19)}, - {0.069,Vector(27,-18,11)}, - {0.077,Vector(31,-22,2)}, - {0.087,Vector(32,-26,-6)}, - {0.098,Vector(32,-28,-12)}, - {0.107,Vector(31,-29,-16)}, - {0.117,Vector(31,-29,-17)}, - {0.128,Vector(31,-29,-16)}, - {0.141,Vector(31,-29,-16)}, - }, - ["lft"] = { - {0.009,Vector(-34,-25,3)}, - {0.021,Vector(-29,-33,3)}, - {0.031,Vector(-21,-41,2)}, - {0.042,Vector(-9,-47,0)}, - {0.053,Vector(5,-48,-2)}, - {0.064,Vector(20,-44,-6)}, - {0.075,Vector(31,-34,-10)}, - {0.086,Vector(37,-24,-15)}, - {0.095,Vector(39,-16,-17)}, - {0.106,Vector(39,-10,-19)}, - {0.116,Vector(39,-8,-20)}, - {0.126,Vector(39,-8,-19)}, - {0.134,Vector(39,-9,-19)}, - {0.146,Vector(39,-10,-18)}, - }, - ["rig"] = { - {0.021,Vector(-2,9,11)}, - {0.031,Vector(5,10,10)}, - {0.042,Vector(12,8,9)}, - {0.053,Vector(19,4,6)}, - {0.062,Vector(26,-4,2)}, - {0.072,Vector(29,-12,-4)}, - {0.083,Vector(29,-21,-12)}, - {0.093,Vector(25,-27,-18)}, - {0.102,Vector(22,-30,-22)}, - {0.113,Vector(20,-31,-25)}, - {0.123,Vector(19,-32,-25)}, - {0.133,Vector(19,-32,-25)}, - }, -} - ---Optional, what to do when the player clicks, and this item is in the slot in inventory. only works for items equipable in left and right -item.lastSwing = {} -item.onClick = function(self,owner) - item.lastSwing[owner] = item.lastSwing[owner] or 0 - if item.lastSwing[owner] > CurTime() then - print("returning because item.lastSwing is " .. item.lastSwing[owner], "but Curtime is",CurTime()) - return end - item.lastSwing[owner] = CurTime()+1.33 - local fwd,rig,up = owner:GetForward(),owner:GetRight(),owner:GetUp() - local movementtbl = { - ["forward"] = function() - owner:SetLuaAnimation("axe_swing_up") - timer.Simple(2.33,function() - owner:StopLuaAnimation("axe_swing_up") - end) - timer.Simple(1,function() - ART.TraceWeapon = true - end) - timer.Simple(1.33,function() - ART.TraceWeapon = false - end) - - local times,pos = {},{} - for k,v in ipairs(swingdata["fwd"]) do - times[k] = 1 + v[1] - pos[k] = Vector(v[2]) - pos[k]:Rotate(owner:GetAimVector():Angle()) - end - if pos[1] == nil then return end - local hits = ART.swingarc(owner,times,pos,function(tr) - if not tr.Hit then return end - if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "forward" then - ART.ApplyEffect(owner,"weapon_blocked") - elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then - tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) - end - end) - - end, - ["backward"] = function() - - end, - ["left"] = function() - owner:SetLuaAnimation("axe_swing_left") - timer.Simple(2.33,function() - owner:StopLuaAnimation("axe_swing_left") - end) - timer.Simple(1,function() - ART.TraceWeapon = true - end) - timer.Simple(1.33,function() - ART.TraceWeapon = false - end) - - local times,pos = {},{} - for k,v in ipairs(swingdata["lft"]) do - times[k] = 1 + v[1] - pos[k] = Vector(v[2]) - pos[k]:Rotate(owner:GetAimVector():Angle()) - end - if pos[1] == nil then return end - local hits = ART.swingarc(owner,times,pos,function(tr) - if not tr.Hit then return end - if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "left" then - ART.ApplyEffect(owner,"weapon_blocked") - elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then - tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) - end - end) - end, - ["right"] = function() - owner:SetLuaAnimation("axe_swing_right") - timer.Simple(2.33,function() - owner:StopLuaAnimation("axe_swing_right") - end) - timer.Simple(1,function() - ART.TraceWeapon = true - end) - timer.Simple(1.33,function() - ART.TraceWeapon = false - end) - - local times,pos = {},{} - for k,v in ipairs(swingdata["rig"]) do - times[k] = 1 + v[1] - pos[k] = Vector(v[2]) - pos[k]:Rotate(owner:GetAimVector():Angle()) - end - if pos[1] == nil then return end - local hits = ART.swingarc(owner,times,pos,function(tr) - if not tr.Hit then return end - if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "right" then - ART.ApplyEffect(owner,"weapon_blocked") - elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then - tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) - end - end) - end, - } - movementtbl[ART.playermovedir(owner)]() -end - ---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) - who:GetActiveWeapon():SetHoldType("melee") - ART.ApplyPAC(who,"rustyaxe") - --local outfit = pac.luadata.ReadFile("pac3/mech.txt") - --who:AttachPACPart(outfit) - --print("onEquip server!") - end -end - ---Optional, if we should do something speical on unequip(like setting animations back to normal) -item.onUnEquip = function(self,who) - who:GetActiveWeapon():SetHoldType("normal") - ART.RemovePAC(who,"rustyaxe") -end - -item.onDropped = function(self, ent) - ART.ApplyPAC(ent,"rustyaxe") -end - -print("Hello from scrapgun.lua") ---Don't forget to register the item! -ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/weapons/scraphammer.lua b/gamemode/shared/itemsystem/weapons/scraphammer.lua deleted file mode 100644 index 299d4e2..0000000 --- a/gamemode/shared/itemsystem/weapons/scraphammer.lua +++ /dev/null @@ -1,233 +0,0 @@ ---[[ - An example item -]] -local item = {} - ---Required, a name, all item names must be unique -item.Name = "Scrap Hammer" - ---Optional, a tooltip to display -item.Tooltip = "Bits of scrap put togeather to resembel a hammer" - ---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 "" -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 -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 -end - -function item.DoOnPanel(dimagebutton) - dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png") -end - -function item.DoOnEqupPanel(dimagebutton) - print("called with panel:",panel) - dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png") -end - ---[[ -function item.Paint(self,width,height) - --print("painting with values",self,width,height) - draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) -end - -function item.PaintEquiped(self,width,height) - --print("painting with values",self,width,height) - draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) -end -]] - ---Required, the shape of this item. -item.Shape = { - {true,true,true}, - {false,true}, - {false,true}, -} - ---Optional, If this item can be equiped in any player slots, put them here. -item.Equipable = "Right" - -local swingdata = { - ["fwd"] = { - {0.007,Vector(-27,1,9)}, - {0.014,Vector(-20,3,16)}, - {0.020,Vector(-11,6,22)}, - {0.027,Vector(0,7,26)}, - {0.032,Vector(15,7,25)}, - {0.039,Vector(28,6,21)}, - {0.045,Vector(38,4,14)}, - {0.052,Vector(46,0,3)}, - {0.059,Vector(50,-3,-6)}, - {0.065,Vector(52,-6,-15)}, - {0.072,Vector(52,-8,-22)}, - {0.078,Vector(51,-10,-28)}, - {0.084,Vector(50,-11,-31)}, - {0.091,Vector(50,-11,-32)}, - {0.097,Vector(50,-11,-32)} - }, - ["lft"] = { - {0.007,Vector(-6,24,2)}, - {0.014,Vector(-1,26,2)}, - {0.020,Vector(5,28,1)}, - {0.027,Vector(12,28,-1)}, - {0.035,Vector(19,27,-4)}, - {0.042,Vector(27,24,-7)}, - {0.048,Vector(37,17,-13)}, - {0.055,Vector(42,12,-17)}, - {0.061,Vector(45,5,-20)}, - {0.068,Vector(48,-2,-23)}, - {0.075,Vector(49,-8,-25)}, - {0.084,Vector(49,-14,-26)}, - {0.091,Vector(49,-19,-27)}, - {0.097,Vector(48,-22,-27)}, - {0.104,Vector(48,-25,-27)}, - {0.110,Vector(48,-26,-27)}, - {0.117,Vector(48,-27,-27)}, - {0.123,Vector(48,-26,-27)}, - {0.131,Vector(48,-26,-27)} - }, - ["rig"] = { - {0.009,Vector(-3,25,2)}, - {0.017,Vector(3,27,1)}, - {0.025,Vector(11,28,-1)}, - {0.032,Vector(20,27,-4)}, - {0.040,Vector(28,24,-7)}, - {0.051,Vector(36,19,-12)}, - {0.059,Vector(42,11,-17)}, - {0.067,Vector(47,2,-22)}, - {0.075,Vector(49,-5,-25)}, - {0.083,Vector(49,-13,-27)}, - {0.090,Vector(49,-19,-28)}, - {0.098,Vector(48,-24,-28)}, - {0.106,Vector(48,-27,-28)}, - {0.114,Vector(48,-28,-28)}, - {0.121,Vector(48,-27,-28)}, - {0.129,Vector(48,-27,-27)} - }, -} - ---Optional, what to do when the player clicks, and this item is in the slot in inventory. only works for items equipable in left and right -item.lastSwing = {} -item.onClick = function(self,owner) - item.lastSwing[owner] = item.lastSwing[owner] or 0 - if item.lastSwing[owner] > CurTime() then - print("returning because item.lastSwing is " .. item.lastSwing[owner], "but Curtime is",CurTime()) - return end - item.lastSwing[owner] = CurTime()+1.33 - local fwd,rig,up = owner:GetForward(),owner:GetRight(),owner:GetUp() - local movementtbl = { - ["forward"] = function() - owner:SetLuaAnimation("hammer_swing_up") - timer.Simple(2.33,function() - owner:StopLuaAnimation("hammer_swing_up") - end) - - local times,pos = {},{} - for k,v in ipairs(swingdata["fwd"]) do - times[k] = 1 + v[1] - pos[k] = Vector(v[2]) - pos[k]:Rotate(owner:GetAimVector():Angle()) - end - if pos[1] == nil then return end - local hits = ART.swingarc(owner,times,pos,function(tr) - if not tr.Hit then return end - if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "forward" then - ART.ApplyEffect(owner,"weapon_blocked") - elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then - tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) - end - end) - - end, - ["backward"] = function() - - end, - ["left"] = function() - owner:SetLuaAnimation("hammer_swing_left") - timer.Simple(2.33,function() - owner:StopLuaAnimation("hammer_swing_left") - end) - - local times,pos = {},{} - for k,v in ipairs(swingdata["lft"]) do - times[k] = 1 + v[1] - pos[k] = Vector(v[2]) - pos[k]:Rotate(owner:GetAimVector():Angle()) - end - if pos[1] == nil then return end - local hits = ART.swingarc(owner,times,pos,function(tr) - if not tr.Hit then return end - if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "left" then - ART.ApplyEffect(owner,"weapon_blocked") - elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then - tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) - end - end) - end, - ["right"] = function() - owner:SetLuaAnimation("hammer_swing_right") - timer.Simple(2.33,function() - owner:StopLuaAnimation("hammer_swing_right") - end) - - local times,pos = {},{} - for k,v in ipairs(swingdata["rig"]) do - times[k] = 1 + v[1] - pos[k] = Vector(v[2]) - pos[k]:Rotate(owner:GetAimVector():Angle()) - end - if pos[1] == nil then return end - local hits = ART.swingarc(owner,times,pos,function(tr) - if not tr.Hit then return end - if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "right" then - ART.ApplyEffect(owner,"weapon_blocked") - elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then - tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) - end - end) - end, - } - movementtbl[ART.playermovedir(owner)]() -end - ---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) - who:GetActiveWeapon():SetHoldType("melee2") - ART.ApplyPAC(who,"scraphammer") - --local outfit = pac.luadata.ReadFile("pac3/mech.txt") - --who:AttachPACPart(outfit) - --print("onEquip server!") - end -end - ---Optional, if we should do something speical on unequip(like setting animations back to normal) -item.onUnEquip = function(self,who) - who:GetActiveWeapon():SetHoldType("normal") - ART.RemovePAC(who,"scraphammer") -end - -item.onDropped = function(self, ent) - ART.ApplyPAC(ent,"scraphammer") -end - -print("Hello from scrapgun.lua") ---Don't forget to register the item! -ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/weapons/seratedknife.lua b/gamemode/shared/itemsystem/weapons/seratedknife.lua deleted file mode 100644 index 2daec36..0000000 --- a/gamemode/shared/itemsystem/weapons/seratedknife.lua +++ /dev/null @@ -1,199 +0,0 @@ ---[[ - An example item -]] -local item = {} - ---Required, a name, all item names must be unique -item.Name = "Serated Knife" - ---Optional, a tooltip to display -item.Tooltip = "Bits of scrap put togeather to resembel a hammer" - ---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 "" -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 -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 -end - -function item.DoOnPanel(dimagebutton) - dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png") -end - -function item.DoOnEqupPanel(dimagebutton) - print("called with panel:",panel) - dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png") -end - ---[[ -function item.Paint(self,width,height) - --print("painting with values",self,width,height) - draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) -end - -function item.PaintEquiped(self,width,height) - --print("painting with values",self,width,height) - draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) -end -]] - ---Required, the shape of this item. -item.Shape = { - {true,true}, -} - ---Optional, If this item can be equiped in any player slots, put them here. -item.Equipable = "Right" - -local function attacktrace(tr,owner) - if not tr.Hit then return end - if tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then - tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) - end -end - - ---Optional, what to do when the player clicks, and this item is in the slot in inventory. only works for items equipable in left and right -item.lastSwing = {} -local animationtime = 1.833333 -item.onClick = function(self,owner) - item.lastSwing[owner] = item.lastSwing[owner] or 0 - if item.lastSwing[owner] > CurTime() then - print("returning because item.lastSwing is " .. item.lastSwing[owner], "but Curtime is",CurTime()) - return end - item.lastSwing[owner] = CurTime()+animationtime - local fow,rig,up = owner:GetForward(),owner:GetRight(),owner:GetUp() - local movementtbl = { - ["forward"] = function() - owner:SetLuaAnimation("knife_swing_up") - timer.Simple(animationtime,function() - owner:StopLuaAnimation("knife_swing_up") - end) - local hits = ART.swingarc(owner,{ - 0.5,0.611,0.722,0.833 - },{ - fow*20 + up*90, - fow*45 + up*70, - fow*35 + up*45, - fow*20 + up*30, - },function(tr) - if not tr.Hit then return end - if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "forward" then - print("Entity blocked!") - ART.ApplyEffect(owner,"weapon_blocked") - elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then - print("Got past blocking, it was",tr.Entity.Blocking) - tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) - end - end) - end, - ["backward"] = function() - owner:SetLuaAnimation("knife_swing_down") - timer.Simple(animationtime,function() - owner:StopLuaAnimation("knife_swing_down") - end) - local hits = ART.swingarc(owner,{ - 0.5,0.611,0.722,0.833 - },{ - fow*15 + up*30, - fow*35 + up*45, - fow*25 + up*70, - fow*15 + up*90, - },function(tr) - if not tr.Hit then return end - if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "backward" then - print("Entity blocked!") - elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then - print("Got past blocking, it was",tr.Entity.Blocking) - tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) - end - end) - end, - ["left"] = function() - owner:SetLuaAnimation("knife_swing_left") - timer.Simple(animationtime,function() - owner:StopLuaAnimation("knife_swing_left") - end) - local hits = ART.swingarc(owner,{ - 0.5,0.611,0.722,0.833 - },{ - rig*30 + up*59, - rig*10 + fow*30 + up*55, - rig*-10 + fow*30 + up*54, - rig*-30 + up*50, - },function(tr) - if not tr.Hit then return end - if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "left" then - print("Entity blocked!") - elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then - print("Got past blocking, it was",tr.Entity.Blocking) - tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) - end - end) - end, - ["right"] = function() - owner:SetLuaAnimation("knife_swing_right") - timer.Simple(animationtime,function() - owner:StopLuaAnimation("knife_swing_right") - end) - local hits = ART.swingarc(owner,{ - 0.5,0.611,0.722,0.833 - },{ - rig*-30 + up*59, - rig*-10 + fow*30 + up*55, - rig*10 + fow*30 + up*54, - rig*30 + up*50, - },function(tr) - if not tr.Hit then return end - if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "right" then - print("Entity blocked!") - elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then - print("Got past blocking, it was",tr.Entity.Blocking) - tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) - end - end) - end, - } - movementtbl[ART.playermovedir(owner)]() -end - ---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) - who:GetActiveWeapon():SetHoldType("knife") - ART.ApplyPAC(who,"seratedknife") - --local outfit = pac.luadata.ReadFile("pac3/mech.txt") - --who:AttachPACPart(outfit) - --print("onEquip server!") - end -end - ---Optional, if we should do something speical on unequip(like setting animations back to normal) -item.onUnEquip = function(self,who) - who:GetActiveWeapon():SetHoldType("normal") - ART.RemovePAC(who,"seratedknife") -end - -item.onDropped = function(self, ent) - ART.ApplyPAC(ent,"seratedknife") -end - ---Don't forget to register the item! -ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/weapons_common.lua b/gamemode/shared/itemsystem/weapons_common.lua deleted file mode 100644 index 6f553fa..0000000 --- a/gamemode/shared/itemsystem/weapons_common.lua +++ /dev/null @@ -1,70 +0,0 @@ - -ART = ART or {} - ---- Finds the direction a player is moveing. --- @param player The player to find the move direction of --- @return The string "forward", "backward", "right", or "left" -function ART.playermovedir(player) - local vel = player:GetVelocity():GetNormalized() - vel.z = 0 - local swings = { - {player:GetForward(),"forward"}, - {-player:GetForward(),"backward"}, - {player:GetRight(),"right"}, - {-player:GetRight(),"left"} - } - table.sort(swings,function(a,b) - return vel:Dot(a[1]) > vel:Dot(b[1]) - end) - return swings[1][2] -end - - -local positionset = {} ---- The arc swing of a weapon. --- Finds anything that a weapon should hit in it's swing, and calls a function on it. --- @param player The player that's swinging the weapon --- @param tiems A table of times that the trace calculations should be done at, this table needs to be the same length as the positions table --- @param positions The position offsets from the player that swung that should be the start/end points of the arc --- @param onhit A function to call on any entities that were hit in the swing of the weapon. -function ART.swingarc(player,times,positions,onhit) - local positionpoints = {} - table.insert(positionset,positionpoints) - for k,v in ipairs(times) do - timer.Simple(v,function() - ART.TraceWeapon = true - ART.TraceStart = CurTime() - print("positions[k]",positions[k],"playerpos",player:GetPos(),"add",Vector(0,0,64)) - local weaponpos = positions[k] + player:GetPos() + Vector(0,0,64) - table.insert(positionpoints,weaponpos) - if #positionpoints > 1 then - --print("Trace from ", positionpoints[#positionpoints-1], " to ", positionpoints[#positionpoints]) - local tr = util.TraceLine({ - start = positionpoints[#positionpoints-1], - endpos = positionpoints[#positionpoints], - }) - onhit(tr) - end - end) - end - timer.Simple(times[#times],function() - print("Inserted swing, drawn positions are now:") - PrintTable(positionset) - ART.TraceWeapon = false - end) -end - -hook.Add( "HUDPaint", "weaponswings", function() - cam.Start3D() -- Start the 3D function so we can draw onto the screen. - for k,v in pairs(positionset) do - for i = 1,#v-1 do - render.DrawLine( v[i], v[i+1], Color(255,0,0,255), false ) - render.DrawLine( v[i], v[i]+Vector(0,0,20),Color(0,255,0,255),false) - end - end - --render.SetMaterial( material ) -- Tell render what material we want, in this case the flash from the gravgun - --render.DrawSprite( pos, 16, 16, white ) -- Draw the sprite in the middle of the map, at 16x16 in it's original colour with full alpha. - cam.End3D() -end ) - -return wcommon 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/npcsystem/blockingdummy.lua b/gamemode/shared/npcsystem/blockingdummy.lua deleted file mode 100644 index 5c6008c..0000000 --- a/gamemode/shared/npcsystem/blockingdummy.lua +++ /dev/null @@ -1,105 +0,0 @@ -local NPC = {} -NPC.Name = "Blocking Training Dummy" -NPC.Desc = "A man made of straw. His dream is to have a brain." -NPC.Class = "Ambient" --Ambient, Agressive, Boss -NPC.Model = "models/headcrab.mdl" - -NPC.Stats = { - ["Vitality"] = 100000, - ["Speed"] = 400, - ["AwareDist"] = 1000, - ["Accel"] = 100, - ["Decel"] = 200, - ["Step"] = 20, --Step height - ["Hull"] = HULL_TINY -} - ---Some npc's like birds have diffent names for their idle sequences -NPC.IdleSequences = { - [0] = "lookaround", - [1] = "Idle01", -} - ---Drops should be formated as [index]={["item name"], percent_drop} where percent_drop is a number from 0 to 100 - -NPC.Drops = { -} - ---Attacks should be formated as [i]={function attackpriority() = function doattack()} -local checknothing = function(self,ply) - return 1 -end - -local donothing = function(self,ply) -end -NPC.Attacks = { - [1] = {--run away from the player - [checknothing] = donothing - }, -} - ---A function that takes a position and returns true if this is an acceptable place to spawn -function NPC:SpawnLocations(pos) - return true -end - ---The entity that is this npc's current target, if it has one. Nil otherwise -NPC.Target = nil - ---All enemies that this NPC is aware of -NPC.AwareEnemies = {} ---Attack priority is a fucntion that takes a player, and returns an int describing it's prority to attack (higher = more important) NPC will always attack the player with the highest priority -function NPC:AttackPriority(ply) - if not ply then return 0 end - return 1 -end - ---What to replace the ENT:RunBehaviour with -function NPC:Act(deltat) -end - ---What to replace ENT:OnStuck with -function NPC:Stuck() - -end - -local blockorder = { - "forward", - "right", - "backward", - "left" -} -local cursor = 0 -function NPC:OnDammage(ammount) - self.Blocking = blockorder[cursor + 1] - cursor = (cursor + 1) % 4 - print("A dummy was hit for",ammount:GetDamage(),"!") - print("Blocking is now",self.Blocking) -end - ---These are just here to tell the editors/develoeprs what functions are available.. dont un-comment them out, as this could affect all the items. -/* -function NPC:OnSpawn() -end - ---If we need to do more than just reduce health on dammage -function NPC:OnDammage(ammount) -end - ---If we need to do more than just drop items on death -function NPC:OnDeath() -end - ---A particular spell was cast on this npc by player -function NPC:OnSpell(spell, player) -end - -function NPC:OnFindEnemy(enemy) -end - ---Called when the npc is attacking anything with any attack -function NPC:OnAttack(target) -end -*/ - -ART.RegisterNPC(NPC) diff --git a/gamemode/shared/npcsystem/dummy.lua b/gamemode/shared/npcsystem/dummy.lua deleted file mode 100644 index 869dd0e..0000000 --- a/gamemode/shared/npcsystem/dummy.lua +++ /dev/null @@ -1,95 +0,0 @@ -local NPC = {} -NPC.Name = "Training Dummy" -NPC.Desc = "A man made of straw. His dream is to have a brain." -NPC.Class = "Ambient" --Ambient, Agressive, Boss -NPC.Model = "models/headcrab.mdl" - -NPC.Stats = { - ["Vitality"] = 100000, - ["Speed"] = 400, - ["AwareDist"] = 1000, - ["Accel"] = 100, - ["Decel"] = 200, - ["Step"] = 20, --Step height - ["Hull"] = HULL_TINY -} - ---Some npc's like birds have diffent names for their idle sequences -NPC.IdleSequences = { - [0] = "lookaround", - [1] = "Idle01", -} - ---Drops should be formated as [index]={["item name"], percent_drop} where percent_drop is a number from 0 to 100 - -NPC.Drops = { -} - ---Attacks should be formated as [i]={function attackpriority() = function doattack()} -local checknothing = function(self,ply) - return 1 -end - -local donothing = function(self,ply) -end -NPC.Attacks = { - [1] = {--run away from the player - [checknothing] = donothing - }, -} - ---A function that takes a position and returns true if this is an acceptable place to spawn -function NPC:SpawnLocations(pos) - return true -end - ---The entity that is this npc's current target, if it has one. Nil otherwise -NPC.Target = nil - ---All enemies that this NPC is aware of -NPC.AwareEnemies = {} ---Attack priority is a fucntion that takes a player, and returns an int describing it's prority to attack (higher = more important) NPC will always attack the player with the highest priority -function NPC:AttackPriority(ply) - if not ply then return 0 end - return 1 -end - ---What to replace the ENT:RunBehaviour with -function NPC:Act(deltat) -end - ---What to replace ENT:OnStuck with -function NPC:Stuck() - -end - -function NPC:OnDammage(ammount) - print("A dummy was hit for",ammount:GetDamage(),"!") -end - ---These are just here to tell the editors/develoeprs what functions are available.. dont un-comment them out, as this could affect all the items. -/* -function NPC:OnSpawn() -end - ---If we need to do more than just reduce health on dammage -function NPC:OnDammage(ammount) -end - ---If we need to do more than just drop items on death -function NPC:OnDeath() -end - ---A particular spell was cast on this npc by player -function NPC:OnSpell(spell, player) -end - -function NPC:OnFindEnemy(enemy) -end - ---Called when the npc is attacking anything with any attack -function NPC:OnAttack(target) -end -*/ - -ART.RegisterNPC(NPC) diff --git a/gamemode/shared/npcsystem/rat.lua b/gamemode/shared/npcsystem/rat.lua deleted file mode 100644 index ab96883..0000000 --- a/gamemode/shared/npcsystem/rat.lua +++ /dev/null @@ -1,113 +0,0 @@ -local NPC = {} -NPC.Name = "Rat" -NPC.Desc = "A nasty little guy" -NPC.Class = "Ambient" --Ambient, Agressive, Boss -NPC.Model = "models/headcrab.mdl" - -NPC.Stats = { - ["Vitality"] = 10, - ["Speed"] = 400, - ["AwareDist"] = 1000, - ["Accel"] = 100, - ["Decel"] = 200, - ["Step"] = 20, --Step height - ["Hull"] = HULL_TINY -} - ---Some npc's like birds have diffent names for their idle sequences -NPC.IdleSequences = { - [0] = "lookaround", - [1] = "Idle01", -} - ---Drops should be formated as [index]={["item name"], percent_drop} where percent_drop is a number from 0 to 100 - -NPC.Drops = { - [0] = {"Rat Meat",100},--Rats will drop at least 1 meat, and have a 50% chance of dropping 2 - [1] = {"Rat Meat",50}, -} - ---Attacks should be formated as [i]={function attackpriority() = function doattack()} -local checkrun = function(self,ply) - --If we're aware of any enemies, run away! - return 1 -end -local runseq -local dorun = function(self,ply) - if runseq == nil then - runseq = self:LookupSequence("Run1") - end - self:StartActivity(ACT_FLY) - self:SetSequence( runseq ) - 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() - local direction = Vector(tpos.x - ppos.x, tpos.y - ppos.y, tpos.z - ppos.z) - direction:Normalize() - local addition = direction * 1000 - local topos = self:GetPos() + addition - --print("I want to go to ", topos) - self.TargetPos = topos -end -NPC.Attacks = { - [1] = {--run away from the player - [checkrun] = dorun - }, -} - ---A function that takes a position and returns true if this is an acceptable place to spawn -function NPC:SpawnLocations(pos) - return true -end - ---The entity that is this npc's current target, if it has one. Nil otherwise -NPC.Target = nil - ---All enemies that this NPC is aware of -NPC.AwareEnemies = {} ---Attack priority is a fucntion that takes a player, and returns an int describing it's prority to attack (higher = more important) NPC will always attack the player with the highest priority -function NPC:AttackPriority(ply) - if not ply then return 0 end - local plypos = ply:GetPos() - local mypos = self:GetPos() - if not plypos then return 0 end - local dist = plypos:Distance(mypos) - return self.Stats["AwareDist"] - dist -end - ---What to replace the ENT:RunBehaviour with -function NPC:Act(deltat) -end - ---What to replace ENT:OnStuck with -function NPC:Stuck() - -end - ---These are just here to tell the editors/develoeprs what functions are available.. dont un-comment them out, as this could affect all the items. -/* -function NPC:OnSpawn() -end - ---If we need to do more than just reduce health on dammage -function NPC:OnDammage(ammount) -end - ---If we need to do more than just drop items on death -function NPC:OnDeath() -end - ---A particular spell was cast on this npc by player -function NPC:OnSpell(spell, player) -end - -function NPC:OnFindEnemy(enemy) -end - ---Called when the npc is attacking anything with any attack -function NPC:OnAttack(target) -end -*/ - -ART.RegisterNPC(NPC) 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([[ +%s +]],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([[ +%s +]],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 -- cgit v1.2.3-70-g09d2