Advertisement
Epilepsys

Untitled

Jan 14th, 2019
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.87 KB | None | 0 0
  1.  
  2. if game.GetMap() != "rp_rockford_v1b" then return end
  3.  
  4. nmap = {}
  5.  
  6.  
  7. function util.ProjectToAxis2D( level, x1, y1, x2 ,y2 )
  8. local fc = (y1-level)/(y1-y2)
  9. return x2*fc+x1*(1-fc)
  10. end
  11.  
  12. local meta = {}
  13. meta.__index = meta
  14.  
  15. local mat = {
  16. arrow = Material("gui/minimap/player_arrow.png", "smooth noclamp"),
  17. dot = Material("gui/minimap/icon_circle"),
  18.  
  19. area = Material("gui/minimap/image.png"),
  20. nmarea = Material("gui/minimap/image.png"),
  21. solid = Material("gui/minimap/image.png"),
  22. nmsolid = Material("gui/minimap/image.png"),
  23. solidShadow = Material("gui/minimap/image.png"),
  24. nmsolidShadow = Material("gui/minimap/image.png"),
  25.  
  26. radius = Material("gui/minimap/radar_radius"),
  27. }
  28.  
  29. local color_shadow = Color(0,0,0,65)
  30. local color_solidmap = Color(255,255,255,200)
  31.  
  32. function nmap.new()
  33. return setmetatable({
  34. x = 32,
  35. y = 32,
  36. w = 256,
  37. h = 256,
  38. pos = Vector(),
  39. ratio = 1,
  40. top = 0,
  41. bottom = 32 + 256,
  42. numsec = 32768 / 256,
  43. scale = 1,
  44. mx = Matrix(),
  45. yaw = 0,
  46. area = mat.area,
  47. solid = mat.solid,
  48. iconScale = 1,
  49. solidShadow = mat.solidShadow
  50. }, meta)
  51. end
  52.  
  53. function meta:applySize(x, y, w, h, ratio)
  54. self.x = x
  55. self.y = y
  56. self.w = w
  57. self.h = h
  58.  
  59. self.numsec = 32768 / w
  60. self.ratio = ratio
  61.  
  62. self.top = y + h * 0.5 - w * ratio * 0.5
  63. self.bottom = y + h * 0.5 + w * ratio * 0.5
  64. end
  65.  
  66. function meta:worldToMap(vec)
  67. local o = vec
  68. local vec = vec - self.pos
  69. local ang = (vec):Angle().y * -1
  70. vec.z = 0
  71.  
  72. local dist = vec:Length() / (self.numsec / self.scale)
  73.  
  74. local ang = ang + self.yaw - 90
  75.  
  76. vec.x = self.x + self.w * 0.5 + math.cos(math.rad(ang)) * dist
  77. vec.y = self.y + self.h * 0.5 + math.sin(math.rad(ang)) * dist
  78.  
  79. local newy, newx = vec.y, vec.x
  80.  
  81. if vec.y <= self.top then
  82. newx = util.ProjectToAxis2D(self.top, self.x + self.w * 0.5, self.y + self.h * 0.5, vec.x, vec.y)
  83. elseif vec.y >= self.bottom then
  84. newx = util.ProjectToAxis2D(self.bottom, self.x + self.w * 0.5, self.y + self.h * 0.5, vec.x, vec.y)
  85. end
  86.  
  87. if vec.x <= self.x then
  88. newy = util.ProjectToAxis2D(self.x, self.y + self.h * 0.5, self.x + self.w * 0.5, vec.y, vec.x)
  89. elseif vec.x >= self.x + self.w then
  90. newy = util.ProjectToAxis2D(self.x + self.w, self.y + self.h * 0.5, self.x + self.w * 0.5, vec.y, vec.x)
  91. end
  92.  
  93. vec.y = math.Clamp(newy, self.top, self.bottom)
  94. vec.x = math.Clamp(newx, self.x, self.x + self.w)
  95.  
  96. return vec
  97. end
  98.  
  99. function meta:worldToMapDirection(vec)
  100. vec.x = -vec.x
  101. vec:Rotate( Angle(0,self.yaw+90,0))
  102. local H2 = self.h*0.5*self.ratio
  103. local W2 = self.w*0.5
  104. local newy, newx = vec.y, vec.x
  105.  
  106. if vec.y < 0 then
  107. newy = -H2
  108. else
  109. newy = H2
  110. end
  111. newx = util.ProjectToAxis2D(newy, 0, 0, vec.x, vec.y)
  112.  
  113. if newx > W2 then
  114. newx = W2
  115. elseif newx < -W2 then
  116. newx = -W2
  117. end
  118. newy = util.ProjectToAxis2D(newx,0,0, vec.y, vec.x)
  119.  
  120. vec.x = self.x + self.w * 0.5 + newx
  121. vec.y = self.y + self.h * 0.5 + newy
  122.  
  123. return vec
  124. end
  125.  
  126. function meta:worldToMapAngles(angOrEnt)
  127. if IsEntity(angOrEnt) then
  128. local ent = angOrEnt
  129.  
  130. return self:worldToMapAngles(ent:InVehicle() and ent:GetVehicle():GetAngles().y + 90 or ent:EyeAngles().y)
  131. elseif isangle(angOrEnt) then
  132. local ang = angOrEnt
  133. return self:worldToMapAngles(ang.y)
  134. elseif isnumber(angOrEnt) then
  135. local yaw = angOrEnt
  136.  
  137. return -90 + yaw - self.yaw
  138. end
  139. end
  140.  
  141. function meta:calculateMatrix()
  142. local pos = Vector()
  143. pos:Set(self.pos)
  144. pos.x = pos.x / 32768 + 1
  145. pos.y = 1 - pos.y / 32768
  146. pos.z = 0
  147.  
  148. self.mx:Identity()
  149. self.mx:Translate(Vector(-0.5, -0.5, 0))
  150. self.mx:Translate(pos)
  151. self.mx:Scale(Vector(1/self.scale, 1/self.scale, 1))
  152. self.mx:Rotate(Angle(0, -self.yaw + 90, 0))
  153. self.mx:Translate(Vector(-0.5, -0.5, 0))
  154. end
  155.  
  156. function meta:draw()
  157. self:calculateMatrix()
  158.  
  159. self.area:SetMatrix("$basetexturetransform", self.mx)
  160. self.solid:SetMatrix("$basetexturetransform", self.mx)
  161. self.solidShadow:SetMatrix("$basetexturetransform", self.mx)
  162.  
  163. surface.SetDrawColor(ColorAlpha(color_white, 200))
  164. surface.SetMaterial(self.area)
  165. surface.DrawTexturedRect(self.x, self.y, self.w, self.h)
  166.  
  167. surface.SetDrawColor(color_shadow)
  168. surface.SetMaterial(self.solidShadow)
  169. surface.DrawTexturedRect(self.x, self.y + 3, self.w, self.h)
  170.  
  171. surface.SetDrawColor(color_solidmap)
  172. surface.SetMaterial(self.solid)
  173. surface.DrawTexturedRect(self.x, self.y, self.w, self.h)
  174.  
  175. surface.SetDrawColor( Color( 0, 0, 0, 165 ) )
  176. surface.DrawOutlinedRect( ScrW() - 8 - 256, ScrH() - 8 - 161, 256, 161 )
  177.  
  178.  
  179.  
  180. self:drawCompas()
  181. self:drawLocalPlayer()
  182. self:drawTraders()
  183. self:drawStatic()
  184. end
  185.  
  186.  
  187. do
  188. function meta:drawLocalPlayer()
  189. local vec = self:worldToMap(LocalPlayer():GetPos())
  190. render.SetMaterial(mat.arrow)
  191. local s = math.max(10, 32 * self.scale / 6)
  192. render.DrawQuadEasy(Vector(vec.x, vec.y), -vector_up, s, s, color_white, self:worldToMapAngles(LocalPlayer()))
  193. end
  194.  
  195.  
  196. local invisible = {}
  197. do
  198.  
  199. local Police = {
  200. TEAM_POLICE,TEAM_SWAT,TEAM_CPTSWAT,TEAM_SGT,TEAM_MAYOR,TEAM_ADVISOR
  201. }
  202.  
  203. function meta:drawTeamPolice()
  204. for p, teams in pairs(Police) do
  205. if LocalPlayer():Team() == teams then
  206. for _, pl in pairs(player.GetAll()) do
  207. if pl == LocalPlayer() or pl:GetNoDraw() then
  208. continue
  209. elseif pl:Team() == teams and pl:Health() > 0 then
  210. local pos = pl:GetNWVector("shoppos", false)
  211. vec = self:worldToMap(pos and pos or pl:GetPos())
  212. invisible[pl] = pos == false
  213.  
  214. draw.RoundedBox(5,vec.x - 4, vec.y - 4,8,8,team.GetColor(pl:Team()))
  215.  
  216. end
  217. end
  218. end
  219. end
  220. end
  221.  
  222. local traders = {
  223. [TEAM_CITIZEN or -1] = Material("icon16/cart.png"),
  224. [TEAM_COOK or -1] = Material("icon16/cup.png"),
  225. [TEAM_MAYOR or -1] = Material("icon16/user_gray.png"),
  226. [TEAM_DOCTOR or -1] = Material("icon16/pill.png"),
  227. }
  228.  
  229. function meta:drawTraders()
  230. table.Empty(invisible)
  231. surface.SetDrawColor(color_white)
  232. for _, pl in pairs(player.GetAll()) do
  233. if pl == LocalPlayer() or pl:GetNoDraw() then
  234. continue
  235. elseif traders[pl:Team()] and pl:Health() > 0 then
  236. local pos = pl:GetNWVector("shoppos", false)
  237. vec = self:worldToMap(pos and pos or pl:GetPos())
  238. invisible[pl] = pos == false
  239. render.SetMaterial(traders[pl:Team()])
  240. local s = math.max(16, 32 * self.scale*self.iconScale/5)
  241. render.DrawQuadEasy(Vector(vec.x, vec.y), -vector_up, 16, 16, Color(255,255,255,255), -90)
  242. end
  243. end
  244. end
  245. end
  246.  
  247.  
  248. end
  249.  
  250.  
  251.  
  252.  
  253. local static1 = {
  254. {Vector(-4322.2275390625, -649.9296875, 0.03125), Material("icon16/car.png")}, // car
  255.  
  256. }
  257.  
  258. function meta:drawMarker(v)
  259. local vec = self:worldToMap(v[1])
  260. render.SetMaterial(v[2])
  261. local s = math.max(16, 32 * self.scale*self.iconScale/7)
  262. render.DrawQuadEasy(Vector(vec.x, vec.y), -vector_up, s, s, color_white, -90)
  263. end
  264.  
  265. function meta:drawMarkerA(pos, icon, scale, size)
  266. scale = scale or 1
  267. local vec = self:worldToMap(pos, true)
  268. if !vec then return end
  269. render.SetMaterial(icon)
  270. render.DrawQuadEasy(Vector(vec.x, vec.y), -vector_up, size, size, color_white, -90)
  271. end
  272.  
  273. function meta:drawStatic()
  274. for k, v in pairs(static1) do
  275.  
  276. -- self:drawMarker(v)
  277.  
  278. end
  279. end
  280.  
  281.  
  282. local icon = Material('icon16/box.png')
  283. function meta:drawDumbsters()
  284. for k, v in pairs(ents.GetAll()) do
  285. if v:GetClass() == "storage" then
  286. if v:GetPos():Distance(LocalPlayer():GetPos()) < 300 then
  287. self:drawMarkerA(v:GetPos(), icon, 0.1, 5)
  288. end
  289. end
  290. end
  291. end
  292.  
  293.  
  294. do
  295. surface.CreateFont("minimap_sides", {
  296. size = 12,
  297. weight = 0,
  298. antialias = true,
  299. font = "Roboto"
  300. })
  301.  
  302. local named = {
  303. [0] = "N",
  304. [3] = "E",
  305. [6] = "S",
  306. [9] = "W",
  307. }
  308. local col_compas_outline = Color(0,0,0,255)
  309. local col_compas_outline_mid = Color(0,0,0,128)
  310. local col_compas_exact = Color(255,255,255,255)
  311. local col_compas_mid = Color(128,128,128,255)
  312.  
  313. local mat_circle = Material"gui/minimap/icon_circle"
  314.  
  315. function meta:drawCompas()
  316. for i = 0, 11 do
  317. if i%3==0 then
  318. local rad = -math.rad(360/12*i)
  319. local vec = self:worldToMapDirection(Vector(math.cos(rad), math.sin(rad), 0))
  320. local text = named[i] or i
  321.  
  322. surface.SetFont("minimap_sides")
  323. local w, h = surface.GetTextSize( text )
  324. surface.SetMaterial(mat_circle)
  325. if i%3==0 then
  326. surface.SetDrawColor( col_compas_outline )
  327. surface.SetTextColor( col_compas_exact )
  328. else
  329. surface.SetTextColor( col_compas_mid )
  330. surface.SetDrawColor( col_compas_outline_mid )
  331. end
  332. surface.DrawTexturedRect(vec.x - h, vec.y - h, h*2,h*2)
  333. surface.SetTextPos(vec.x - w/2, vec.y - h/2)
  334. surface.DrawText( text )
  335. end
  336. end
  337. end
  338. end
  339.  
  340. function meta:drawDebugAxis()
  341. surface.SetDrawColor(Color(255, 0, 0))
  342. surface.DrawLine(self.x, self.top, self.x + self.w, self.top)
  343. surface.DrawLine(self.x, self.bottom, self.x + self.w, self.bottom)
  344.  
  345. surface.SetDrawColor(Color(0, 255, 0))
  346. surface.DrawLine(self.x, self.y, self.x, self.y + self.h)
  347. surface.DrawLine(self.x + self.w, self.y, self.x + self.w, self.y + self.h)
  348.  
  349. surface.SetDrawColor(Color(0, 255, 0))
  350. surface.DrawLine(self.x + self.w/2, self.y, self.x + self.w/2, self.y + self.h)
  351. surface.SetDrawColor(Color(255, 0, 0))
  352. end
  353.  
  354.  
  355. minimap = nmap.new()
  356. minimap:applySize(0, ScrH(), 256, 256, 10/16)
  357. minimap:applySize(ScrW() - minimap.w - 8, ScrH() - (minimap.bottom - ScrH()) - 8, 256, 256, 10/16)
  358.  
  359. bigmap = nmap.new()
  360. bigmap:applySize(0, 0, ScrH(), ScrH(), 1)
  361.  
  362. timer.Simple(0, function()
  363. notification.yoff = ScrH() - minimap.top + 64
  364. notification.xoff = 20
  365. end)
  366.  
  367. local mdl = ClientsideModel("error.mdl")
  368. mdl:SetNoDraw(true)
  369.  
  370. local noDraw = true
  371. local lastPos = Vector(0,0,0)
  372.  
  373. hook.Add("HUDPaint","Minimap",function()
  374. render.SetBlend(0)
  375. mdl:DrawModel()
  376. render.SetBlend(1)
  377.  
  378. local pos = LocalPlayer():EyePos()
  379. local dt = lastPos - pos
  380. lastPos:Set(pos)
  381. dt = dt:Length()/FrameTime()
  382.  
  383. minimap.scale = Lerp(FrameTime(), minimap.scale, dt > 0 and 2 or 3)
  384. minimap.yaw = RenderAngles().y
  385. minimap.pos = pos
  386. minimap:draw()
  387.  
  388. bigmap.pos = Vector()
  389. bigmap.yaw = 90
  390. bigmap.scale = 0.65
  391. bigmap.iconScale = 3
  392. bigmap.bigmap = true
  393. if input.IsKeyDown(KEY_L) && !vgui.CursorVisible() then
  394. bigmap:draw()
  395. end
  396.  
  397. surface.CreateFont("BigMap_18", {
  398. size = 18,
  399. weight = 0,
  400. antialias = true,
  401. font = "Roboto"
  402. })
  403.  
  404. surface.SetFont("BigMap_18")
  405. surface.SetTextColor( Color(255,255,255) )
  406. surface.SetTextPos(ScrW() - 85, ScrH() - 30)
  407. surface.DrawText( "M - Map" )
  408. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement