Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
- Version 2, December 2004
- Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
- Everyone is permitted to copy and distribute verbatim or modified
- copies of this license document, and changing it is allowed as long
- as the name is changed.
- DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
- 0. You just DO WHAT THE FUCK YOU WANT TO.
- ]]
- local clip = {}
- do
- local render = render
- local STENCILOPERATION_REPLACE = STENCILOPERATION_REPLACE
- local STENCILOPERATION_ZERO = STENCILOPERATION_ZERO
- local STENCILCOMPARISONFUNCTION_EQUAL = STENCILCOMPARISONFUNCTION_EQUAL
- local STENCILCOMPARISONFUNCTION_NEVER = STENCILCOMPARISONFUNCTION_NEVER
- local STENCILCOMPARISONFUNCTION_NOTEQUAL = STENCILCOMPARISONFUNCTION_NOTEQUAL
- function clip.Start()
- render.SetStencilEnable(true)
- render.SetStencilWriteMask(1)
- render.SetStencilTestMask(1)
- render.SetStencilReferenceValue(1)
- end
- function clip.End()
- render.ClearStencil()
- render.SetStencilEnable(false)
- end
- function clip.Render(call1, call2, clipOuter)
- render.ClearStencil()
- render.SetStencilFailOperation(STENCILOPERATION_REPLACE)
- render.SetStencilPassOperation(STENCILOPERATION_ZERO)
- render.SetStencilZFailOperation(STENCILOPERATION_ZERO)
- render.SetStencilCompareFunction(STENCILCOMPARISONFUNCTION_NEVER)
- call1()
- render.SetStencilFailOperation(STENCILOPERATION_ZERO)
- render.SetStencilPassOperation(STENCILOPERATION_REPLACE)
- render.SetStencilZFailOperation(STENCILOPERATION_ZERO)
- if clipOuter then
- render.SetStencilCompareFunction(STENCILCOMPARISONFUNCTION_EQUAL)
- else
- render.SetStencilCompareFunction(STENCILCOMPARISONFUNCTION_NOTEQUAL)
- end
- call2()
- end
- end
- local GenerateCircleVertices = nil
- do
- local cos, rad, sin = math.cos, math.rad, math.sin
- function GenerateCircleVertices(centreX, centreY, radius, angStart, angSize)
- local vertices = {}
- local passes = 64 -- Seems to look pretty enough
- vertices[1] = { -- Ensure vertices resemble sector and not a chord
- x = centreX,
- y = centreY
- }
- for i = 0, passes do
- local sectorVertexAng = rad(-90 + angStart + angSize * (i / passes))
- vertices[i + 2] = {
- x = centreX + cos(sectorVertexAng) * radius,
- y = centreY + sin(sectorVertexAng) * radius
- }
- end
- return vertices
- end
- end
- local miniMapMat = Material("roleplay/minimap.png")
- local miniMapRT = GetRenderTarget("MiniMapRT", 512, 512, true)
- local miniMapRTMat = CreateMaterial("MiniMapRTMat", "UnlitGeneric", {["$basetexture"] = "MiniMapRT"})
- local radius = math.Clamp(math.floor(ScrH() / 8.5), 80, 256)
- local x, y = 32 + radius, 32 + radius
- local barSize = radius / 9
- local outlineSize = 3
- local innerBarVertices = GenerateCircleVertices(x, y, radius - barSize, 0, 360)
- local healthBarVertices = GenerateCircleVertices(x, y, radius, 0, 0)
- local armorBarVertices = GenerateCircleVertices(x, y, radius, 0, 0)
- local innerBackgroundVertices = innerBarVertices
- local backgroundVertices = GenerateCircleVertices(x, y, radius, 0, 360)
- local innerOutlineVertices = backgroundVertices
- local innerInlineVertices = GenerateCircleVertices(x, y, radius - barSize - outlineSize, 0, 360)
- local outlineVertices = GenerateCircleVertices(x, y, radius + outlineSize, 0, 360)
- local inlineVertices = GenerateCircleVertices(x, y, radius - barSize, 0, 360)
- local lastHealth = nil
- local lastArmor = nil
- hook.Add("Think", "rp_radar", function()
- if not IsValid(LocalPlayer()) then return end
- local ply = LocalPlayer()
- if ply:Health() ~= lastHealth or ply:Armor() ~= lastArmor then
- local hp = Lerp(0.25, lastHealth or 100, ply:Health())
- local armor = Lerp(0.25, lastArmor or 100, ply:Armor())
- local healthFrac = hp / 100
- local armorFrac = armor / 100
- local healthAngSize = 180 * healthFrac
- local armorAngSize = 180 * armorFrac
- local healthAngStart = 180 + (180 - healthAngSize)
- local armorAngStart = healthAngStart - armorAngSize
- healthBarVertices = GenerateCircleVertices(x, y, radius, healthAngStart, healthAngSize)
- armorBarVertices = GenerateCircleVertices(x, y, radius, armorAngStart, armorAngSize)
- lastHealth = hp
- lastArmor = armor
- end
- end)
- local color_white = color_white
- local color_black = color_black
- local color_health = Color(92, 131, 86)
- local color_lowhealth = Color(148, 76, 67)
- local color_armor = Color(74, 148, 160)
- local color_innerbackground = Color(0, 0, 0, 210)
- local texWhite = surface.GetTextureID("vgui/white")
- local rendering_minimap = false
- hook.Add("PreDrawViewModel", "Radar", function()
- if rendering_minimap then
- return true
- end
- end)
- hook.Add("ShouldDrawLocalPlayer", "Radar", function()
- if rendering_minimap then
- return true
- end
- end)
- hook.Add("HUDPaint", "Radar", function()
- if not IsValid(LocalPlayer()) then return end
- local ply = LocalPlayer()
- surface.SetDrawColor(color_white)
- surface.SetTexture(texWhite)
- do
- local oldRT = render.GetRenderTarget()
- local oldW, oldH = ScrW(), ScrH()
- render.SetRenderTarget(miniMapRT)
- render.SetViewPort(0, 0, 512, 512)
- render.Clear(40, 40, 40, 255)
- cam.Start2D()
- local ang = EyeAngles()
- local pos = EyePos()
- render.SuppressEngineLighting(true)
- rendering_minimap = true
- render.RenderView({
- angles = Angle(90, ang.y, 0),
- origin = Vector(pos.x, pos.y, 2400),
- x = 0,
- y = 0,
- w = 512,
- h = 512,
- fov = 40,
- dopostprocess = false
- })
- rendering_minimap = false
- render.SuppressEngineLighting(false)
- cam.End2D()
- render.SetViewPort(0, 0, oldW, oldH)
- render.SetRenderTarget(oldRT)
- end
- clip.Start()
- clip.Render(
- function()
- surface.DrawPoly(innerInlineVertices)
- end,
- function()
- surface.SetMaterial(miniMapRTMat)
- surface.DrawTexturedRect(x - 256, y - 256, 512, 512)
- surface.SetTexture(texWhite)
- end,
- true
- )
- clip.Render(
- function()
- surface.DrawPoly(innerOutlineVertices)
- end,
- function()
- surface.SetDrawColor(color_black)
- surface.DrawPoly(outlineVertices)
- end
- )
- clip.Render(
- function()
- surface.DrawPoly(innerInlineVertices)
- end,
- function()
- surface.SetDrawColor(color_black)
- surface.DrawPoly(inlineVertices)
- end
- )
- clip.Render(
- function()
- surface.DrawPoly(innerBackgroundVertices)
- end,
- function()
- surface.SetDrawColor(color_innerbackground)
- surface.DrawPoly(backgroundVertices)
- end
- )
- clip.Render(
- function()
- surface.DrawPoly(innerBarVertices)
- end,
- function()
- if ply:Health() > 10 or math.ceil(RealTime()) % 2 == 0 then
- surface.SetDrawColor(color_health)
- else
- surface.SetDrawColor(color_lowhealth)
- end
- surface.DrawPoly(healthBarVertices)
- end
- )
- clip.Render(
- function()
- surface.DrawPoly(innerBarVertices)
- end,
- function()
- surface.SetDrawColor(color_armor)
- surface.DrawPoly(armorBarVertices)
- end
- )
- clip.End()
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement