1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
--local tblf = include("/../gamemodes/artery/gamemode/utility/mapfuncs.lua")
local log = nrequire("log.lua")
local drawmap = false
hook.Add( "ScoreboardShow", "ShowNPCMap", function()
drawmap = true
return true
end )
hook.Add( "ScoreboardHide", "ShowNPCMap", function()
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)
if node.isleaf then
render.SetMaterial( node.material )
render.DrawSprite( node.pos, 64, 64, white )
else
if not node.icons then
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
cam.Start3D()
drawsubarea(mapicons["global"])
cam.End3D()
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")
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 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]
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
local function addmapicon(material, subarea, position)
log.debug("adding map icon, material:",material,"subarea:",subarea,"bordertbl:",bordertbl)
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 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!
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()
local matstr = net.ReadString()
local subarea = net.ReadString()
local matpos = net.ReadVector()
addmapicon(matstr,subarea,matpos)
end)
net.Receive("addmaparea",function()
--print("got receive for map area")
-- local matstr = net.ReadString()
-- local subarea = net.ReadString()
-- local boarders = net.ReadTable()
end)
|