Jump to content

[HELP] Radar Simulator acl group


Recommended Posts

radar script is really cool.
I want to use it on my server but I want it to work with acl.
So the clan's radar will not show the people in that clan,
it will only be visible if someone else enters it.
Can you help me do this please?


local screenX, screenY = guiGetScreenSize()
local angle = 0
local visible = false
local lineVisible = false
local tick = getTickCount()
local radares = {}
local elementsDetected = {}
--
local radius = 20 -- radius
local centerPos = {-1344.0895996094, -42.202056884766, 10, 10} -- Edit position of radar: x, y, z, height
local radarColshape = createColCircle(centerPos[1], centerPos[2], radius)
--

function attachRadarToElement(element)
	if isElement(element) then
		centerPos = element
	end
end

function createRadar(posX, posY, size)
	table.insert(radares, {x = posX, y = posY, s = size, r = (size - (size*40/300))/2})
end
createRadar(screenX - 366, screenY - 318, 300)

local function linear(t, b, c, d)
  return c * t / d + b
end

function radar()
	local now = getTickCount()
	if now-tick >= 50 then
		tick = getTickCount()
		angle = angle < 360 and angle + 2 or 0
	end
	
	if visible then
		for _, v in ipairs(radares) do
			dxDrawImage(v.x, v.y, v.s, v.s, "images/radar.png")
			local centerX, centerY = v.x+v.s/2, v.y+v.s/2
			
			for i = -30, 1 do
				local alpha = 8.5*i
				local endX = math.cos( math.rad( angle + i*2 ) ) * v.r
				local endY = -math.sin( math.rad( angle + i*2 ) ) * v.r
				
				local lineX, lineY = centerX, centerY
				dxDrawLine(lineX, lineY, endX + lineX, endY + lineY, tocolor(0, 255, 0, alpha), 7)
			end
			for element, b in pairs(elementsDetected) do
				local elapsedTime = now - b[1]
				if elapsedTime < 3000 then
					local alpha = linear(elapsedTime, 255, -255, 3000)
					
					local hip = (v.r*b[3])/radius
					local x, y = math.cos(b[2]) * hip, math.sin(b[2]) * hip
					
					dxDrawImage(centerX-8+x, centerY-8-y, 16, 16, "images/56.png", _, _, _, tocolor(255, 255, 255, alpha))
				else
					elementsDetected[element] = nil
				end
			end
		end
	end
end
addEventHandler("onClientRender", root, radar)
--

addEventHandler("onClientPreRender", root,
	function()
		local centerX, centerY, centerZ, height
		if not isElement(centerPos) then
			centerX, centerY, centerZ, height = unpack( centerPos )
		else
			centerX, centerY, centerZ = getElementPosition(centerPos)
			height = 10
		end

		if lineVisible then
			
			for i = 1, 360, 45 do
				local endX = math.cos( math.rad( i ) ) * radius
				local endY = math.sin( math.rad( i ) ) * radius
				
				dxDrawLine3D(centerX, centerY, centerZ + height, endX + centerX, endY + centerY, centerZ + height, tocolor(255, 255, 0, 150), 7)
				dxDrawLine3D(endX + centerX, endY + centerY, centerZ, endX + centerX, endY + centerY, centerZ+height, tocolor(255, 255, 0, 150), 7)
			end
			
			local endX, endY = math.cos( math.rad( angle ) ) * radius, math.sin( math.rad( angle ) ) * radius
			local endX2, endY2 = math.cos( math.rad( angle - 10 ) ) * radius, math.sin( math.rad( angle - 10 ) ) * radius
			
			local middleZ = (centerZ + height)
			dxDrawLine3D(centerX, centerY, middleZ, endX + centerX, endY + centerY, middleZ, tocolor(255, 0, 0, 150), 3)
			dxDrawLine3D(centerX, centerY, middleZ, endX2 + centerX, endY2 + centerY, middleZ, tocolor(255, 0, 0, 150), 3)
			dxDrawLine3D( endX + centerX, endY + centerY, middleZ, endX2 + centerX, endY2 + centerY, middleZ, tocolor(255, 0, 0, 150), 3)
		end
		
		local elements = getElementsWithinColShape(radarColshape)
		for e = 1, #elements do
			local x, y, z = getElementPosition(elements[e])
			local hipotenusa = ( (x-centerX)^2 + (y-centerY)^2 ) ^ .5
			local eAngle = math.acos( (x-centerX) / hipotenusa )
			eAngle = (y-centerY) < 0 and math.pi*2 - eAngle or eAngle
			
			--local xFrom, yFrom = math.cos(eAngle)*hipotenusa, math.sin(eAngle)*hipotenusa
			--dxDrawLine3D(centerX, centerY, 7, xFrom + centerX, yFrom + centerY, z, tocolor(0, 255, 0, 150), 3) -- To see where the element is supposed to be
			
			if eAngle >= math.rad( angle - 10 ) and eAngle <= math.rad ( angle ) then
				if visible and not elementsDetected[elements[e]] then
					playSoundFrontEnd(5)
				end
				elementsDetected[elements[e]] = {getTickCount(), eAngle, hipotenusa}
			end
		end
		
	end
)

addCommandHandler("radar2", 
	function()
		visible = not visible
	end
)

addCommandHandler("radarline",
	function()
		lineVisible = not lineVisible
	end
)

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...