aboutsummaryrefslogtreecommitdiff
path: root/gamemode/core/npc
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode/core/npc')
-rw-r--r--gamemode/core/npc/cl_npcmap.lua124
-rw-r--r--gamemode/core/npc/cl_shop.lua2
-rw-r--r--gamemode/core/npc/sv_huntingspawner.lua20
-rw-r--r--gamemode/core/npc/sv_npcsystem.lua24
-rw-r--r--gamemode/core/npc/sv_shop.lua18
5 files changed, 98 insertions, 90 deletions
diff --git a/gamemode/core/npc/cl_npcmap.lua b/gamemode/core/npc/cl_npcmap.lua
index ea7293e..ddbd3cd 100644
--- a/gamemode/core/npc/cl_npcmap.lua
+++ b/gamemode/core/npc/cl_npcmap.lua
@@ -17,11 +17,11 @@ local mapicons = --[[mapicons or]] {
["global"] = {
["isleaf"] = false,
["border"] = { {-10000,-10000},
- {-10000,10000},
- {10000,10000},
- {10000,-10000}
- },
- }
+ {-10000,10000},
+ {10000,10000},
+ {10000,-10000}
+ },
+}
}
hook.Add( "HUDPaint", "paintsprites", function()
@@ -56,29 +56,37 @@ end )
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)
+ if not file.Exists("artery/client/" .. mapname,"DATA") then
+ file.CreateDir("artery/client/" .. mapname)
end
- local mapiconstxt = file.Read("artery/client/"..mapname.."/known.txt")
- if not mapiconstxt then return end --File does not exist!
+ local mapiconstxt = file.Read("artery/client/" .. mapname .. "/known.txt")
+ if not mapiconstxt then return end --File does not exist!
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]
+ if not isleaf then
+ --local name = v[2]
local boundry = {}
for i = 3, #ttbl, 3 do
- boundry[#boundry+1] = ttbl[i],ttbl[i + 1],ttbl[i + 2]
+ boundry[#boundry + 1] = ttbl[i],ttbl[i + 1],ttbl[i + 2]
end
end
+ -- 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
@@ -86,19 +94,21 @@ 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)
+ -- 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
+ -- 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)
+ -- print("cursor is")
+ -- PrintTable(cursor)
end
- if cursor.isleaf and v.pos == position then return end
+ if cursor.isleaf and cursor.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!
@@ -111,37 +121,37 @@ local function addmapicon(material, subarea, 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
+-- 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}
+{-10000,-10000},
+{-10000,10000},
+{10000,10000},
+{10000,-10000}
})
]]
@@ -157,7 +167,7 @@ end)
net.Receive("addmaparea",function()
print("got receive for map area")
- local matstr = net.ReadString()
- local subarea = net.ReadString()
- local boarders = net.ReadTable()
+ -- local matstr = net.ReadString()
+ -- local subarea = net.ReadString()
+ -- local boarders = net.ReadTable()
end)
diff --git a/gamemode/core/npc/cl_shop.lua b/gamemode/core/npc/cl_shop.lua
index c2c71bc..de8ec23 100644
--- a/gamemode/core/npc/cl_shop.lua
+++ b/gamemode/core/npc/cl_shop.lua
@@ -61,7 +61,7 @@ local function DrawShopItemOnDPanel(dp,itemtbl,cost)
end
end
end
-
+
local buybutton = vgui.Create("DButton",dp)
buybutton:Dock(RIGHT)
buybutton:SetText("Buy\n(" .. cost .. ")")
diff --git a/gamemode/core/npc/sv_huntingspawner.lua b/gamemode/core/npc/sv_huntingspawner.lua
index d13ec36..f6bf827 100644
--- a/gamemode/core/npc/sv_huntingspawner.lua
+++ b/gamemode/core/npc/sv_huntingspawner.lua
@@ -4,10 +4,9 @@
local track = nrequire("core/inventory/sv_invtracker.lua")
local itm = nrequire("core/inventory/item.lua")
local o = {}
-local playerhunted = {}
local huntablenodes = {}
function o.CreateSpawnNode(tbl)
- huntablenodes[#huntablenodes+1] = tbl
+ huntablenodes[#huntablenodes + 1] = tbl
local e = ents.Create("info_huntablespawn")
e:SetPos(tbl.Position)
e:Spawn()
@@ -33,13 +32,13 @@ local function SpawnMonsterFor(ply,zone)
break
end
end
-
+
if npctype == nil then
print(ply,"got lucky this time...")
return
end
--print("I will spawn a ",npctype,"to attack ",ply,"!")
-
+
--Find a place for the npc to spawn that's out of sight!
local potentialspots = ents.FindInSphere( ply:GetPos(), 4000 )
for k,v in pairs(potentialspots) do
@@ -54,17 +53,17 @@ local function SpawnMonsterFor(ply,zone)
})
if tr.Hit and tr.Entity == ply then
potentialspots[k] = nil
- print("Player could see this point")
+ --print("Player could see this point")
end
end
end
-
+
local a = {}
- for k,v in pairs(potentialspots) do a[#a+1] = v end
-
+ for k,v in pairs(potentialspots) do a[#a + 1] = v end
+
--Choose a random spot!
local spawnpos = a[math.random(1,#a)]
-
+
--print("I want to spawn a monster at", spawnpos)
if spawnpos == nil then
--print("Couldn't find a spot to spawn an NPC around",ply,"at",ply:GetPos(),"make sure there are enough info_huntablespawn entities around in little corners and stuff")
@@ -108,12 +107,11 @@ hook.Add("OnNPCKilled","droplootforexnpcs",function(npc,attacker,inflictor)
local rng = math.random(0, 100)
local itemname = v[1]
local itemchance = v[2]
- local heightoffset = 10
if rng < itemchance then
local drop = itm.GetItemByName(itemname)
print("Createing a drop of",drop)
- track.CreateDroppedItem(drop, npc:GetPos()+Vector(math.random(20),math.random(20),20))
+ track.CreateDroppedItem(drop, npc:GetPos() + Vector(math.random(20),math.random(20),20))
end
end
end)
diff --git a/gamemode/core/npc/sv_npcsystem.lua b/gamemode/core/npc/sv_npcsystem.lua
index 1051c64..d5182d7 100644
--- a/gamemode/core/npc/sv_npcsystem.lua
+++ b/gamemode/core/npc/sv_npcsystem.lua
@@ -68,18 +68,18 @@ for k, v in pairs(removeents) do
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
+ 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()
diff --git a/gamemode/core/npc/sv_shop.lua b/gamemode/core/npc/sv_shop.lua
index 2825996..c0e2153 100644
--- a/gamemode/core/npc/sv_shop.lua
+++ b/gamemode/core/npc/sv_shop.lua
@@ -36,20 +36,20 @@ end
net.Receive("art_buyitem",function(len,ply)
local itemname = net.ReadString()
-
+
--Find the shop near the player
local es = ents.FindInSphere(ply:GetPos(),500)
- local shop
+ local tshop
for k,v in pairs(es) do
if IsValid(v) and v:GetClass() == "npc_shop" then
- shop = v
+ tshop = v
break
end
end
- print("Shop was", shop)
- print("Items:", shop.shopitems)
- PrintTable(shop.shopitems)
-
+ print("Shop was", tshop)
+ print("Items:", tshop.shopitems)
+ PrintTable(tshop.shopitems)
+
--Find the price of the item we want to buy
local price
for k,v in pairs(shop.shopitems) do
@@ -58,9 +58,9 @@ net.Receive("art_buyitem",function(len,ply)
break
end
end
-
+
--Make sure we have enough credits to buy it
- if ply:GetCredits() < price then
+ if ply:GetCredits() < price then
print(ply, " didn't have enough credits to buy a ", itemname, "(" .. price .. ")")
else
xpcall(function()