Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if game.GetMap() != "rp_rockford_v1b" then return end
- nmap = {}
- function util.ProjectToAxis2D( level, x1, y1, x2 ,y2 )
- local fc = (y1-level)/(y1-y2)
- return x2*fc+x1*(1-fc)
- end
- local meta = {}
- meta.__index = meta
- local mat = {
- arrow = Material("gui/minimap/player_arrow.png", "smooth noclamp"),
- dot = Material("gui/minimap/icon_circle"),
- area = Material("gui/minimap/image.png"),
- nmarea = Material("gui/minimap/image.png"),
- solid = Material("gui/minimap/image.png"),
- nmsolid = Material("gui/minimap/image.png"),
- solidShadow = Material("gui/minimap/image.png"),
- nmsolidShadow = Material("gui/minimap/image.png"),
- radius = Material("gui/minimap/radar_radius"),
- }
- local color_shadow = Color(0,0,0,65)
- local color_solidmap = Color(255,255,255,200)
- function nmap.new()
- return setmetatable({
- x = 32,
- y = 32,
- w = 256,
- h = 256,
- pos = Vector(),
- ratio = 1,
- top = 0,
- bottom = 32 + 256,
- numsec = 32768 / 256,
- scale = 1,
- mx = Matrix(),
- yaw = 0,
- area = mat.area,
- solid = mat.solid,
- iconScale = 1,
- solidShadow = mat.solidShadow
- }, meta)
- end
- function meta:applySize(x, y, w, h, ratio)
- self.x = x
- self.y = y
- self.w = w
- self.h = h
- self.numsec = 32768 / w
- self.ratio = ratio
- self.top = y + h * 0.5 - w * ratio * 0.5
- self.bottom = y + h * 0.5 + w * ratio * 0.5
- end
- function meta:worldToMap(vec)
- local o = vec
- local vec = vec - self.pos
- local ang = (vec):Angle().y * -1
- vec.z = 0
- local dist = vec:Length() / (self.numsec / self.scale)
- local ang = ang + self.yaw - 90
- vec.x = self.x + self.w * 0.5 + math.cos(math.rad(ang)) * dist
- vec.y = self.y + self.h * 0.5 + math.sin(math.rad(ang)) * dist
- local newy, newx = vec.y, vec.x
- if vec.y <= self.top then
- newx = util.ProjectToAxis2D(self.top, self.x + self.w * 0.5, self.y + self.h * 0.5, vec.x, vec.y)
- elseif vec.y >= self.bottom then
- newx = util.ProjectToAxis2D(self.bottom, self.x + self.w * 0.5, self.y + self.h * 0.5, vec.x, vec.y)
- end
- if vec.x <= self.x then
- newy = util.ProjectToAxis2D(self.x, self.y + self.h * 0.5, self.x + self.w * 0.5, vec.y, vec.x)
- elseif vec.x >= self.x + self.w then
- newy = util.ProjectToAxis2D(self.x + self.w, self.y + self.h * 0.5, self.x + self.w * 0.5, vec.y, vec.x)
- end
- vec.y = math.Clamp(newy, self.top, self.bottom)
- vec.x = math.Clamp(newx, self.x, self.x + self.w)
- return vec
- end
- function meta:worldToMapDirection(vec)
- vec.x = -vec.x
- vec:Rotate( Angle(0,self.yaw+90,0))
- local H2 = self.h*0.5*self.ratio
- local W2 = self.w*0.5
- local newy, newx = vec.y, vec.x
- if vec.y < 0 then
- newy = -H2
- else
- newy = H2
- end
- newx = util.ProjectToAxis2D(newy, 0, 0, vec.x, vec.y)
- if newx > W2 then
- newx = W2
- elseif newx < -W2 then
- newx = -W2
- end
- newy = util.ProjectToAxis2D(newx,0,0, vec.y, vec.x)
- vec.x = self.x + self.w * 0.5 + newx
- vec.y = self.y + self.h * 0.5 + newy
- return vec
- end
- function meta:worldToMapAngles(angOrEnt)
- if IsEntity(angOrEnt) then
- local ent = angOrEnt
- return self:worldToMapAngles(ent:InVehicle() and ent:GetVehicle():GetAngles().y + 90 or ent:EyeAngles().y)
- elseif isangle(angOrEnt) then
- local ang = angOrEnt
- return self:worldToMapAngles(ang.y)
- elseif isnumber(angOrEnt) then
- local yaw = angOrEnt
- return -90 + yaw - self.yaw
- end
- end
- function meta:calculateMatrix()
- local pos = Vector()
- pos:Set(self.pos)
- pos.x = pos.x / 32768 + 1
- pos.y = 1 - pos.y / 32768
- pos.z = 0
- self.mx:Identity()
- self.mx:Translate(Vector(-0.5, -0.5, 0))
- self.mx:Translate(pos)
- self.mx:Scale(Vector(1/self.scale, 1/self.scale, 1))
- self.mx:Rotate(Angle(0, -self.yaw + 90, 0))
- self.mx:Translate(Vector(-0.5, -0.5, 0))
- end
- function meta:draw()
- self:calculateMatrix()
- self.area:SetMatrix("$basetexturetransform", self.mx)
- self.solid:SetMatrix("$basetexturetransform", self.mx)
- self.solidShadow:SetMatrix("$basetexturetransform", self.mx)
- surface.SetDrawColor(ColorAlpha(color_white, 200))
- surface.SetMaterial(self.area)
- surface.DrawTexturedRect(self.x, self.y, self.w, self.h)
- surface.SetDrawColor(color_shadow)
- surface.SetMaterial(self.solidShadow)
- surface.DrawTexturedRect(self.x, self.y + 3, self.w, self.h)
- surface.SetDrawColor(color_solidmap)
- surface.SetMaterial(self.solid)
- surface.DrawTexturedRect(self.x, self.y, self.w, self.h)
- surface.SetDrawColor( Color( 0, 0, 0, 165 ) )
- surface.DrawOutlinedRect( ScrW() - 8 - 256, ScrH() - 8 - 161, 256, 161 )
- self:drawCompas()
- self:drawLocalPlayer()
- self:drawTraders()
- self:drawStatic()
- end
- do
- function meta:drawLocalPlayer()
- local vec = self:worldToMap(LocalPlayer():GetPos())
- render.SetMaterial(mat.arrow)
- local s = math.max(10, 32 * self.scale / 6)
- render.DrawQuadEasy(Vector(vec.x, vec.y), -vector_up, s, s, color_white, self:worldToMapAngles(LocalPlayer()))
- end
- local invisible = {}
- do
- local Police = {
- TEAM_POLICE,TEAM_SWAT,TEAM_CPTSWAT,TEAM_SGT,TEAM_MAYOR,TEAM_ADVISOR
- }
- function meta:drawTeamPolice()
- for p, teams in pairs(Police) do
- if LocalPlayer():Team() == teams then
- for _, pl in pairs(player.GetAll()) do
- if pl == LocalPlayer() or pl:GetNoDraw() then
- continue
- elseif pl:Team() == teams and pl:Health() > 0 then
- local pos = pl:GetNWVector("shoppos", false)
- vec = self:worldToMap(pos and pos or pl:GetPos())
- invisible[pl] = pos == false
- draw.RoundedBox(5,vec.x - 4, vec.y - 4,8,8,team.GetColor(pl:Team()))
- end
- end
- end
- end
- end
- local traders = {
- [TEAM_CITIZEN or -1] = Material("icon16/cart.png"),
- [TEAM_COOK or -1] = Material("icon16/cup.png"),
- [TEAM_MAYOR or -1] = Material("icon16/user_gray.png"),
- [TEAM_DOCTOR or -1] = Material("icon16/pill.png"),
- }
- function meta:drawTraders()
- table.Empty(invisible)
- surface.SetDrawColor(color_white)
- for _, pl in pairs(player.GetAll()) do
- if pl == LocalPlayer() or pl:GetNoDraw() then
- continue
- elseif traders[pl:Team()] and pl:Health() > 0 then
- local pos = pl:GetNWVector("shoppos", false)
- vec = self:worldToMap(pos and pos or pl:GetPos())
- invisible[pl] = pos == false
- render.SetMaterial(traders[pl:Team()])
- local s = math.max(16, 32 * self.scale*self.iconScale/5)
- render.DrawQuadEasy(Vector(vec.x, vec.y), -vector_up, 16, 16, Color(255,255,255,255), -90)
- end
- end
- end
- end
- end
- local static1 = {
- {Vector(-4322.2275390625, -649.9296875, 0.03125), Material("icon16/car.png")}, // car
- }
- function meta:drawMarker(v)
- local vec = self:worldToMap(v[1])
- render.SetMaterial(v[2])
- local s = math.max(16, 32 * self.scale*self.iconScale/7)
- render.DrawQuadEasy(Vector(vec.x, vec.y), -vector_up, s, s, color_white, -90)
- end
- function meta:drawMarkerA(pos, icon, scale, size)
- scale = scale or 1
- local vec = self:worldToMap(pos, true)
- if !vec then return end
- render.SetMaterial(icon)
- render.DrawQuadEasy(Vector(vec.x, vec.y), -vector_up, size, size, color_white, -90)
- end
- function meta:drawStatic()
- for k, v in pairs(static1) do
- -- self:drawMarker(v)
- end
- end
- local icon = Material('icon16/box.png')
- function meta:drawDumbsters()
- for k, v in pairs(ents.GetAll()) do
- if v:GetClass() == "storage" then
- if v:GetPos():Distance(LocalPlayer():GetPos()) < 300 then
- self:drawMarkerA(v:GetPos(), icon, 0.1, 5)
- end
- end
- end
- end
- do
- surface.CreateFont("minimap_sides", {
- size = 12,
- weight = 0,
- antialias = true,
- font = "Roboto"
- })
- local named = {
- [0] = "N",
- [3] = "E",
- [6] = "S",
- [9] = "W",
- }
- local col_compas_outline = Color(0,0,0,255)
- local col_compas_outline_mid = Color(0,0,0,128)
- local col_compas_exact = Color(255,255,255,255)
- local col_compas_mid = Color(128,128,128,255)
- local mat_circle = Material"gui/minimap/icon_circle"
- function meta:drawCompas()
- for i = 0, 11 do
- if i%3==0 then
- local rad = -math.rad(360/12*i)
- local vec = self:worldToMapDirection(Vector(math.cos(rad), math.sin(rad), 0))
- local text = named[i] or i
- surface.SetFont("minimap_sides")
- local w, h = surface.GetTextSize( text )
- surface.SetMaterial(mat_circle)
- if i%3==0 then
- surface.SetDrawColor( col_compas_outline )
- surface.SetTextColor( col_compas_exact )
- else
- surface.SetTextColor( col_compas_mid )
- surface.SetDrawColor( col_compas_outline_mid )
- end
- surface.DrawTexturedRect(vec.x - h, vec.y - h, h*2,h*2)
- surface.SetTextPos(vec.x - w/2, vec.y - h/2)
- surface.DrawText( text )
- end
- end
- end
- end
- function meta:drawDebugAxis()
- surface.SetDrawColor(Color(255, 0, 0))
- surface.DrawLine(self.x, self.top, self.x + self.w, self.top)
- surface.DrawLine(self.x, self.bottom, self.x + self.w, self.bottom)
- surface.SetDrawColor(Color(0, 255, 0))
- surface.DrawLine(self.x, self.y, self.x, self.y + self.h)
- surface.DrawLine(self.x + self.w, self.y, self.x + self.w, self.y + self.h)
- surface.SetDrawColor(Color(0, 255, 0))
- surface.DrawLine(self.x + self.w/2, self.y, self.x + self.w/2, self.y + self.h)
- surface.SetDrawColor(Color(255, 0, 0))
- end
- minimap = nmap.new()
- minimap:applySize(0, ScrH(), 256, 256, 10/16)
- minimap:applySize(ScrW() - minimap.w - 8, ScrH() - (minimap.bottom - ScrH()) - 8, 256, 256, 10/16)
- bigmap = nmap.new()
- bigmap:applySize(0, 0, ScrH(), ScrH(), 1)
- timer.Simple(0, function()
- notification.yoff = ScrH() - minimap.top + 64
- notification.xoff = 20
- end)
- local mdl = ClientsideModel("error.mdl")
- mdl:SetNoDraw(true)
- local noDraw = true
- local lastPos = Vector(0,0,0)
- hook.Add("HUDPaint","Minimap",function()
- render.SetBlend(0)
- mdl:DrawModel()
- render.SetBlend(1)
- local pos = LocalPlayer():EyePos()
- local dt = lastPos - pos
- lastPos:Set(pos)
- dt = dt:Length()/FrameTime()
- minimap.scale = Lerp(FrameTime(), minimap.scale, dt > 0 and 2 or 3)
- minimap.yaw = RenderAngles().y
- minimap.pos = pos
- minimap:draw()
- bigmap.pos = Vector()
- bigmap.yaw = 90
- bigmap.scale = 0.65
- bigmap.iconScale = 3
- bigmap.bigmap = true
- if input.IsKeyDown(KEY_L) && !vgui.CursorVisible() then
- bigmap:draw()
- end
- surface.CreateFont("BigMap_18", {
- size = 18,
- weight = 0,
- antialias = true,
- font = "Roboto"
- })
- surface.SetFont("BigMap_18")
- surface.SetTextColor( Color(255,255,255) )
- surface.SetTextPos(ScrW() - 85, ScrH() - 30)
- surface.DrawText( "M - Map" )
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement