diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2018-11-03 18:23:45 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2018-11-03 18:23:45 -0400 |
| commit | 28affa22541b9ef251707793f6b1c1a26d663592 (patch) | |
| tree | 622754894d75c74dc5e8516ccf184ad4bf328fef /gamemode/core | |
| parent | c639e7c7c6ab1595fdce39f56312e3d6a886bbe8 (diff) | |
| download | artery-28affa22541b9ef251707793f6b1c1a26d663592.tar.gz artery-28affa22541b9ef251707793f6b1c1a26d663592.tar.bz2 artery-28affa22541b9ef251707793f6b1c1a26d663592.zip | |
Started on new npc system
Started work on the new npc system
Diffstat (limited to 'gamemode/core')
| -rw-r--r-- | gamemode/core/animation/cl_animate.lua | 7 | ||||
| -rw-r--r-- | gamemode/core/config/sv_config.lua | 7 | ||||
| -rw-r--r-- | gamemode/core/inventory/cl_invtracker.lua | 23 | ||||
| -rw-r--r-- | gamemode/core/inventory/common/items.lua | 40 | ||||
| -rw-r--r-- | gamemode/core/mapstich/cl_mapstich.lua | 4 | ||||
| -rw-r--r-- | gamemode/core/npc/sh_common.lua | 7 | ||||
| -rw-r--r-- | gamemode/core/npc/sh_npcsystem.lua | 160 | ||||
| -rw-r--r-- | gamemode/core/npc/sv_common.lua | 38 | ||||
| -rw-r--r-- | gamemode/core/npc/sv_npcsystem.lua | 150 |
9 files changed, 204 insertions, 232 deletions
diff --git a/gamemode/core/animation/cl_animate.lua b/gamemode/core/animation/cl_animate.lua index c7dc19d..4b86234 100644 --- a/gamemode/core/animation/cl_animate.lua +++ b/gamemode/core/animation/cl_animate.lua @@ -1,3 +1,7 @@ +--- Client side of the animation subsystem +-- Stores the code to run animations client side. +-- Also see @{sh_animations.lua} and @{sv_animate.lua} +-- @client cl_animate.lua net.Receive("art_start_animation",function() local what = net.ReadEntity() @@ -12,6 +16,9 @@ net.Receive("art_stop_animation",function() what:StopLuaAnimation(anim) end) +--- All visible players and their sequences. +-- @table sequences +-- Stores all the sequences for all visible players local sequences = {} net.Receive("art_start_sequence",function() local who = net.ReadEntity() diff --git a/gamemode/core/config/sv_config.lua b/gamemode/core/config/sv_config.lua index 6eb5394..2173dc0 100644 --- a/gamemode/core/config/sv_config.lua +++ b/gamemode/core/config/sv_config.lua @@ -8,12 +8,13 @@ local config = {} local addons = {} local function config_number(panel) - + error("TODO") end local config_types = { ["number"] = config_number, - "text", - "textbox" + ["boolean"] = config_boolean, + ["option"] = config_option, + ["text"] = config_text, } function config.RegisterConfig(name,t,func) assert(config_types[t],string.format("Attempted to register unknown config type %q, allowed types are %s"),t,table.concat(table.GetKeys(config_types))) diff --git a/gamemode/core/inventory/cl_invtracker.lua b/gamemode/core/inventory/cl_invtracker.lua index e6633f9..2591e96 100644 --- a/gamemode/core/inventory/cl_invtracker.lua +++ b/gamemode/core/inventory/cl_invtracker.lua @@ -4,6 +4,7 @@ local inv = nrequire("inventory/inventory.lua") local itm = nrequire("item.lua") +local log = nrequire("log.lua") -- nrequire("cl_loadglobals.lua") --local state = nrequire("cl_state.lua") @@ -122,4 +123,26 @@ concommand.Add("PrintKnownInventories",function(ply,cmd,args) PrintTable(known_inventories) end) +---Drops an item. +-- Client side only, will error if you try to use it server side +--@tparam entity ent_or_tbl the entity that wants to drop the item +--@tparam number invid The inventory number the entity wants to drop from +--@tparam table frompos The position in the inventory the item was in. +function q.DropItem(ent_or_tbl,invid,frompos) + --[[ + if type(ent_or_tbl) == "table" then + drop_self(ent_or_tbl) + else + drop_provided(ent_or_tbl,invid,frompos) + end + ]] + assert(CLIENT,"requested to drop an item when we are not the client!") + log.debug("Drop item was requested, ent_or_tbl is" .. tostring(ent_or_tbl)) + net.Start("art_RequestInvDrop") + net.WriteEntity(ent_or_tbl) + net.WriteUInt(invid,32) + net.WriteTable(frompos) + net.SendToServer() +end + return q diff --git a/gamemode/core/inventory/common/items.lua b/gamemode/core/inventory/common/items.lua deleted file mode 100644 index 65d8e4a..0000000 --- a/gamemode/core/inventory/common/items.lua +++ /dev/null @@ -1,40 +0,0 @@ ----Some common functions for working with items. --- Just one function for now ---@shared items.lua ---@alias items - -local log = nrequire("log.lua") -local items = {} - --- local function drop_provided(ent,invid,frompos) --- assert(CLIENT,"requested to drop an item when we are not the client!") --- net.Start("art_RequestInvDrop") --- net.WriteEntity(ent) --- net.WriteUInt(invid,32) --- net.WriteTable(frompos) --- net.SendToServer() --- end - ----Drops an item. --- Client side only, will error if you try to use it server side ---@tparam entity ent_or_tbl the entity that wants to drop the item ---@tparam number invid The inventory number the entity wants to drop from ---@tparam table frompos The position in the inventory the item was in. -function items.DropItem(ent_or_tbl,invid,frompos) - --[[ - if type(ent_or_tbl) == "table" then - drop_self(ent_or_tbl) - else - drop_provided(ent_or_tbl,invid,frompos) - end - ]] - assert(CLIENT,"requested to drop an item when we are not the client!") - log.debug("Drop item was requested, ent_or_tbl is" .. tostring(ent_or_tbl)) - net.Start("art_RequestInvDrop") - net.WriteEntity(ent_or_tbl) - net.WriteUInt(invid,32) - net.WriteTable(frompos) - net.SendToServer() -end - -return items diff --git a/gamemode/core/mapstich/cl_mapstich.lua b/gamemode/core/mapstich/cl_mapstich.lua index 6f85eeb..dbd332d 100644 --- a/gamemode/core/mapstich/cl_mapstich.lua +++ b/gamemode/core/mapstich/cl_mapstich.lua @@ -2,6 +2,7 @@ The client constantly cheks to see if we're in a serverchnage zone ]] if not nrequire("sh_zones.lua") then return end +local log = nrequire("log.lua") hook.Add("Think","artery_checklevelchange",function() local z pcall(function() @@ -18,5 +19,6 @@ end) net.Receive("art_sendtoserver",function() local where = net.ReadString() - LocalPlayer():ConCommand("connect " .. where) + log.debug("Being sent to another server:" .. where) + --LocalPlayer():ConCommand("connect " .. where) end) diff --git a/gamemode/core/npc/sh_common.lua b/gamemode/core/npc/sh_common.lua new file mode 100644 index 0000000..cd72a61 --- /dev/null +++ b/gamemode/core/npc/sh_common.lua @@ -0,0 +1,7 @@ +--[[ + Some common functions that a lot of npcs use, take out here to make fixing bugs easier. +]] +do return end +local com = {} + +return com diff --git a/gamemode/core/npc/sh_npcsystem.lua b/gamemode/core/npc/sh_npcsystem.lua new file mode 100644 index 0000000..501f21c --- /dev/null +++ b/gamemode/core/npc/sh_npcsystem.lua @@ -0,0 +1,160 @@ +---Various functions for npcs. +-- Helps you spawn monsters, townies, and shopkeepers +--@server sv_npcsystem.lua +--@alias n + +local f = nrequire("concommands.lua") +local log = nrequire("log.lua") +local n = {} +local npcs = {} --Master table of npcs +local autocompletef + +---Registers an NPC. +-- Adds an npc to the global table. NPC's should have unique .Name fields, if they don't, this function will error. +--@see npctbl +--@tparam table npc The npc's table. +function n.RegisterNPC(npc) + assert(npc ~= nil, "Attempted to register a nil npc") + assert(type(npc) == "table", "Attempted to regsiter an npc that was not a table, it was a " .. type(npc)) + assert(npc.Name ~= nil, "Attempted to register an npc without a name") + npcs[npc.Name] = npc + autocompletef = f.AutocompleteFunction(npcs) +end + +function n.GetNPC(name) + assert(npcs[name] ~= nil, "Tried to get npc without name") + return npcs[name] +end + +--Ents to remove when refreshing the npc map +local removeents = {"art_npc", "info_townienode", "npc_shop"} + +if SERVER then + ---Creates an NPC. + -- Creates an npc, by name + --@tparam string npcname The npc's name + --@tparam vector3 pos The position to spawn the npc + function n.CreateNPCByName(npcname, pos) + assert(npcs[npcname],string.format("No npc named %q, valid names are:\n%s",npcname,table.concat(table.GetKeys(npcs),"\n"))) + --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 + + ---Creats a shop npc. + -- Creates a shop npc from a shop npc table + --@see shopnpctbl + --@tparam table npc The shop npc's table. + function n.CreateShop(npc) + --print("Createing shop npc") + local npcent = ents.Create("art_npc") + local shopkeep = n.GetNPC("Shopkeep") + setmetatable(npc,{__index = function(self,key) + return shopkeep[key] or npcent[key] + end}) + npc:Spawn() + --print("Called spawn") + end + + ---Creates a townie. + -- Creates a new townie that wanders around his areas of intrest + --@see townienpctbl + --@tparam table npc The townie npc's table. + function n.CreateTownie(tbl) + local npcent = ents.Create("art_npc") + local townie = n.GetNPC("Townie") + setmetatable(tbl,{__index = function(self,key) + return townie[key] or npcent[key] + end}) + tbl:Spawn() + end + + ---Create an area of intrest. + -- Creates an point that you can use in a townie's locations of intrest. + --@see navnodetbl + --@tparam table tbl The table for the nav node + function n.CreateNavNode(tbl) + local nodeent = ents.Create("info_townienode") + assert(tbl ~= nil, "Tried to create a nil navnode") + for k, v in pairs(tbl) do + nodeent[k] = v + end + nodeent:Spawn() + end + + for k, v in pairs(removeents) do + local eot = ents.FindByClass(v) + for i, j in pairs(eot) do + j:Remove() + end + end +end + +local function ExecuteOnFolder(dir, recursive, func) + local path = "" + local fpath = table.concat({path,dir,"/*"}) + local files, directories = file.Find(fpath,"DATA") + for k,v in pairs(files) do + local callpath = table.concat({path,dir,"/",v}) + func(callpath) + end + if not recursive then return end + for k,v in pairs(directories) do + local npath = table.concat({dir,"/",v}) + ExecuteOnFolder(npath,true,func) + end +end + +local function loadMap() + local mapname = game.GetMap() + + local foldername = "artery/maps/" .. mapname + ExecuteOnFolder(foldername,true,function(path) + print("I want to run",path) + local filetxt = file.Read(path,"DATA") + --print("File text is", filetxt) + CompileString(filetxt,path)() + --print("I want to execute",path) + end) +end + +hook.Add("InitPostEntity", "artery_spawnmapnpcs", function() + loadMap() +end) + +---Reloads the entities on the map. +-- Removes and then reload all of the entities on the level +--@concommand artery_reloadmap +concommand.Add("artery_reloadmap", function(ply,cmd,args) + if not ply:IsAdmin() then return end + for k, v in pairs(removeents) do + local eot = ents.FindByClass(v) + + for i, j in pairs(eot) do + j:Remove() + end + end + + loadMap() +end) + +---Create a new npc. +-- Creates a new npc a the point the player is looking +--@usage artery_makenpc <npc_name> +--@concommand artery_makenpc +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/npc/sv_common.lua b/gamemode/core/npc/sv_common.lua deleted file mode 100644 index e37a5f8..0000000 --- a/gamemode/core/npc/sv_common.lua +++ /dev/null @@ -1,38 +0,0 @@ ---[[ - Some common functions that a lot of npcs use, take out here to make fixing bugs easier. -]] - -local com = {} - -com.pausefor10sec = function(npc) - npc.StartActionTime = CurTime() + 10 - npc:SetSequence(npc:LookupSequence("idle")) - npc.loco:FaceTowards(Vector(-343, 148, 565)) - local oyaw,oacc = npc.loco:GetMaxYawRate(), npc.loco:GetAcceleration() - timer.Simple(0,function() - npc.loco:SetMaxYawRate(0) - npc.loco:SetAcceleration(0) - npc.loco:SetVelocity(Vector(0,0,0)) - end) - timer.Simple(10, function() - npc.loco:SetMaxYawRate(oyaw) - npc.loco:SetAcceleration(oacc) - end) -end - -com.is10secdone = function(npc) - return npc.StartActionTime < CurTime() -end - -com.Rumors = { - "This is a rumor!", - "Here is another!", - "And yet another!", -} - -com.GetRumor = function() - local rng = math.random(#com.Rumors) - return com.Rumors[rng] -end - -return com diff --git a/gamemode/core/npc/sv_npcsystem.lua b/gamemode/core/npc/sv_npcsystem.lua deleted file mode 100644 index eb149f2..0000000 --- a/gamemode/core/npc/sv_npcsystem.lua +++ /dev/null @@ -1,150 +0,0 @@ ----Various functions for npcs. --- Helps you spawn monsters, townies, and shopkeepers ---@server sv_npcsystem.lua ---@alias n - -local f = nrequire("concommands.lua") -local n = {} -local npcs = {} --Master table of npcs -local autocompletef - ----Registers an NPC. --- Adds an npc to the global table. NPC's should have unique .Name fields, if they don't, this function will error. ---@see npctbl ---@tparam table npc The npc's table. -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 - ----Creates an NPC. --- Creates an npc, by name ---@tparam string npcname The npc's name ---@tparam vector3 pos The position to spawn the npc -function n.CreateNPCByName(npcname, pos) - assert(npcs[npcname],string.format("No npc named %q, valid names are:\n%s",npcname,table.concat(table.GetKeys(npcs),"\n"))) - --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 - ----Creats a shop npc. --- Creates a shop npc from a shop npc table ---@see shopnpctbl ---@tparam table npc The shop npc's table. -function n.CreateShop(npc) - --print("Createing shop npc") - local npcent = ents.Create("npc_shop") - for k,v in pairs(npc) do - npcent[k] = v - end - npcent:Spawn() - --print("Called spawn") -end - ----Creates a townie. --- Creates a new townie that wanders around his areas of intrest ---@see townienpctbl ---@tparam table npc The townie npc's table. -function n.CreateTownie(tbl) - local npcent = ents.Create("npc_townie") - for k, v in pairs(tbl) do - npcent[k] = v - end - npcent:Spawn() -end - ----Create an area of intrest. --- Creates an point that you can use in a townie's locations of intrest. ---@see navnodetbl ---@tparam table tbl The table for the nav node -function n.CreateNavNode(tbl) - local nodeent = ents.Create("info_townienode") - assert(tbl ~= nil, "Tried to create a nil navnode") - for k, v in pairs(tbl) do - nodeent[k] = v - end - nodeent:Spawn() -end - ---Ents to remove when refreshing the npc map -local removeents = {"npc_townie", "info_townienode", "npc_shop"} - --- "art_chest", -for k, v in pairs(removeents) do - local eot = ents.FindByClass(v) - for i, j in pairs(eot) do - j:Remove() - end -end - -local function ExecuteOnFolder(dir, recursive, func) - local path = "" - local fpath = table.concat({path,dir,"/*"}) - local files, directories = file.Find(fpath,"DATA") - for k,v in pairs(files) do - local callpath = table.concat({path,dir,"/",v}) - func(callpath) - end - if not recursive then return end - for k,v in pairs(directories) do - local npath = table.concat({dir,"/",v}) - ExecuteOnFolder(npath,true,func) - end -end - -local function loadMap() - local mapname = game.GetMap() - - local foldername = "artery/maps/" .. mapname - ExecuteOnFolder(foldername,true,function(path) - print("I want to run",path) - local filetxt = file.Read(path,"DATA") - --print("File text is", filetxt) - CompileString(filetxt,path)() - --print("I want to execute",path) - end) -end - -hook.Add("InitPostEntity", "artery_spawnmapnpcs", function() - loadMap() -end) - ----Reloads the entities on the map. --- Removes and then reload all of the entities on the level ---@concommand artery_reloadmap -concommand.Add("artery_reloadmap", function(ply,cmd,args) - if not ply:IsAdmin() then return end - for k, v in pairs(removeents) do - local eot = ents.FindByClass(v) - - for i, j in pairs(eot) do - j:Remove() - end - end - - loadMap() -end) - ----Create a new npc. --- Creates a new npc a the point the player is looking ---@usage artery_makenpc <npc_name> ---@concommand artery_makenpc -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 |
