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/core/npc/cl_npcmap.lua | 162 +++++++++++++++++++++++++++++++++++++ gamemode/core/npc/sv_npcmap.lua | 22 +++++ gamemode/core/npc/sv_npcsystem.lua | 39 +++++++++ 3 files changed, 223 insertions(+) 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 (limited to 'gamemode/core/npc') 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 -- cgit v1.2.3-70-g09d2