Jump to content

black map problem


Burak5312

Recommended Posts

 

hello, sometimes when I go to another server and then enter my own local server, the map goes black like this and does not fix until I restart the mta.

what could this be due to?

mta-screen-2021-12-28-17-46-57.png

 

this is how it is normally

unknown.png

client:

local screenW,screenH = guiGetScreenSize()
local myW, myH = 1920, 1080
local relX, relY = (screenW/myW), (screenH/myH)
local middleX,middleY = screenW/2, screenH/2

local thisResource = getThisResource()

local isMapVisible = false
local isInfoTextVisible = true
local zoom = 1
local zoomRate = 0.1
local movementSpeed = 5
local minZoomLimit = 1
local maxZoomLimit = 5
local xOffset = 0
local yOffset = 0
local x,y = 0,0
local hSize = 0
local vSize = 0
local mapR, mapG, mapB, mapA = 255, 255, 255, 220 -- map opacity is mapA
local mapDrawColor = tocolor(mapR, mapG, mapB, mapA)
local normalColor = tocolor(255, 255, 255, 255)
local mapFile = "images/radar8192.jpg"
local topLeftWorldX, topLeftWorldY = -3000,3000
local lowerRightWorldX, lowerRightWorldY = 3000,-3000
local mapWidth, mapHeight = 6000,6000
local pixelsPerMeter = screenH/6000

local imageOwnerResource = getThisResource()

local radarStates = {
	["radar_zoom_in"] = false,
	["radar_zoom_out"] = false,
	["radar_move_north"] = false,
	["radar_move_south"] = false,
	["radar_move_east"] = false,
	["radar_move_west"] = false
}

local CustomgetControlState = getPedControlState

addEventHandler("onClientResourceStart", resourceRoot,
    function()
       toggleControl("radar", false)
       calculateFirstCoordinates()

       for control,state in pairs(radarStates) do
	      for key,states in pairs(getBoundKeys(control)) do
		     bindKey(key, "both", handleStateChange, control)
	      end
       end

    end
)

addEventHandler("onClientResourceStop", root,
    function(resource)
       if (resource == imageOwnerResource) and (resource ~= thisResource) then
		    setPlayerZRMapImage()
	    end
    end
)

addEvent("onClientPlayerMapHide")
addEvent("onClientPlayerMapShow")

function getPedControlState(control)
	local radarState = radarStates[control]
	if (radarState == nil) then
		return CustomgetControlState(control)
	else
		return radarState
	end
end

function handleStateChange(key, state, control)
	radarStates[control] = (state == "down")
end

function calculateFirstCoordinates()
	hSize = pixelsPerMeter*mapWidth*zoom
	vSize = pixelsPerMeter*mapHeight*zoom

	x = middleX-hSize/2+xOffset*zoom
	y = middleY-vSize/2+yOffset*zoom
end

function drawRadarMap()
   if (isMapVisible == false) then
      dxDrawImage(0, 0, 0, 0, mapFile, 0, 0, 0, 0, false)
   else
   	  checkMovement()
   	  hSize = pixelsPerMeter*mapWidth*zoom
	  vSize = pixelsPerMeter*mapHeight*zoom
		
	  x = middleX-hSize/2+xOffset*zoom
	  y = middleY-vSize/2+yOffset*zoom
	  
	  -- priority draws here
	  dxDrawImage(x, y, hSize, vSize, mapFile, 0, 0, 0, mapDrawColor, false)
	  drawRadarAreas()
	  drawBlips()
	  drawLocalPlayerArrow()
	  drawInfoMessage()
   end
end
addEventHandler("onClientPreRender", root, drawRadarMap)

function drawMapInfoText(text, posX, posY)
   local mapMin, mapMax
   local position = Vector2(posX, posY)
   do
        local mx, my, Mx, My = getPlayerZRMapBoundingBox()
        if (mx) then
            mapMin = Vector2(mx, my)
            mapMax = Vector2(Mx, My)
        else
            return
        end
    end
    local fMx, fMy = (position.x + 3000) / 6000, -(position.y - 3000) / 6000
    local fmx, fmy = 1 - fMx, 1 - fMy
    local screenMapPos = Vector2((fmx * mapMin.x) + (fMx * mapMax.x), (fmy * mapMin.y) + (fMy * mapMax.y))
    if (screenMapPos.x >= 0 and screenMapPos.y >= 0 and screenMapPos.x <= screenW and screenMapPos.y <= screenH) then
       dxDrawText(text, screenMapPos.x, screenMapPos.y, screenMapPos.x, screenMapPos.y, tocolor(255, 255, 255, 255), 1 * relX, "default", "center", "center")
    end
end

function drawInfoMessage()
   if(isInfoTextVisible) then
      drawMapInfoText("(+) Zoom In Map. / (-) Zoom Out Map.", 0, 2890)
      drawMapInfoText("(NUM 4) Move Left. / (NUM 6) Move Right.", 0, 2770)
      drawMapInfoText("(NUM 8) Move Forward. / (NUM 2) Move Backward.", 0, 2650)
      drawMapInfoText("(NUM 0) Hide / Show This Info.", 0, 2530)
   end
end

function drawRadarAreas()
	local radarAreas = getElementsByType("radararea")
	if (#radarAreas > 0) then
		local tick = math.abs(getTickCount()%1000-500)
		local aFactor = tick/500
		
		for _,radararea in ipairs(radarAreas) do
			local x,y = getElementPosition(radararea)
			local sx,sy = getRadarAreaSize(radararea)
			local r,g,b,a = getRadarAreaColor(radararea)
			local isFlashing = isRadarAreaFlashing(radararea)
			
			if (isFlashing) then
				a=a*aFactor
			end
			
			local hx1,hy1 = getZRMapFromWorldPosition(x, y+sy)
			local hx2,hy2 = getZRMapFromWorldPosition(x+sx, y)
			local width = hx2-hx1
			local height = hy2-hy1
			
			dxDrawRectangle(hx1, hy1, width, height, tocolor(r, g, b, a), false)
		end
	end
end

function drawBlips()
	local blips = getElementsByType("blip")
	for _,blip in ipairs(blips) do
		local icon = getBlipIcon(blip) or 0
		local size = (getBlipSize(blip) or 2)*4
		local r,g,b,a = getBlipColor(blip)
			
		if (icon ~= 0) then
			r,g,b = 255, 255, 255
			size = 16
		end
			
		local x,y,z = getElementPosition(blip)
		x,y = getZRMapFromWorldPosition(x, y)
			
		local halfsize = size/2
			
		dxDrawImage(x-halfsize, y-halfsize, size, size, "images/blips/"..icon..".png", 0, 0, 0, tocolor(r, g, b, a), false)
	end
end

function drawLocalPlayerArrow()
	local x,y,z = getElementPosition(localPlayer)
	local _, _, rz = getElementRotation(localPlayer)
	
	local mapX, mapY = getZRMapFromWorldPosition(x, y)
	
	dxDrawImage(mapX-8, mapY-8, 16, 16, "images/blips/2.png", (-rz)%360, 0, 0, normalColor, false)
end

function zoomOutRecalculate()
	local newVSize = pixelsPerMeter*mapHeight*zoom
	if (newVSize > screenH) then
		local newY = middleY-newVSize/2+yOffset*zoom
		
		if (newY > 0) then
			yOffset = -(middleY-newVSize/2)/zoom
		elseif (newY <= (-newVSize+screenH)) then
			yOffset = (middleY-newVSize/2)/zoom
		end
	else
		yOffset = 0
	end
	
	local newHSize = pixelsPerMeter*mapWidth*zoom
	if (newHSize > screenW) then
		local newX = middleX-newHSize/2+xOffset*zoom
		
		if (newX >= 0) then
			xOffset = -(middleX-newHSize/2)/zoom
		elseif (newX <= (-newHSize+screenW)) then
			xOffset = (middleX-newHSize/2)/zoom
		end
	else
		xOffset = 0
	end
end

function checkMovement()
	-- Zoom
	if (getPedControlState("radar_zoom_in") and zoom < maxZoomLimit) then
		zoom = zoom+zoomRate
		if (zoom > maxZoomLimit) then zoom = maxZoomLimit end
	elseif (getPedControlState("radar_zoom_out") and zoom > minZoomLimit) then
		zoom = zoom-zoomRate
		if (zoom < minZoomLimit) then zoom = minZoomLimit end
		zoomOutRecalculate()
	end
	
	-- Move
	if (getPedControlState("radar_move_north")) then
		local newY = y-yOffset*zoom+(yOffset+movementSpeed)*zoom
		if (newY < 0) then
			yOffset = yOffset+movementSpeed
		end
	end

	if (getPedControlState("radar_move_south")) then
		local newY = y-yOffset*zoom+(yOffset-movementSpeed)*zoom
		if (newY > (-vSize+screenH)) then
			yOffset = yOffset-movementSpeed
		end
	end

	if (getPedControlState("radar_move_west")) then
		local newXOff = (xOffset+movementSpeed)
		local newX = x-xOffset*zoom+newXOff*zoom
		
		if (newX < 0) then
			xOffset = xOffset+movementSpeed
		end
	end

	if (getPedControlState("radar_move_east")) then
		local newX = x-xOffset*zoom+(xOffset-movementSpeed)*zoom
		if (newX > (-hSize+screenW)) then
			xOffset = xOffset-movementSpeed
		end
	end
end

function toggleZRMap()
   if(isMapVisible) then
      local onMapHide = triggerEvent("onClientPlayerMapHide", root, false)
      if(onMapHide) then isMapVisible = false end
   else
      local onMapShow = triggerEvent("onClientPlayerMapShow", root, false)
      if(onMapShow) then isMapVisible = true end
   end
end
bindKey("F11", "down", toggleZRMap)

function toggleInfoText()
   if(isMapVisible == false) then return end
      
   if(isInfoTextVisible == false) then
      isInfoTextVisible = true
   else
      isInfoTextVisible = false
   end
end
bindKey("num_0", "down", toggleInfoText)

-- EXPORT FUNCTIONS

function getPlayerZRMapBoundingBox()
	return x,y,x+hSize,y+vSize
end

function isPlayerZRMapVisible()
	return isMapVisible
end

function setPlayerZRMapVisible(value)
   isMapVisible = value
   if(isMapVisible) then
      triggerEvent("onClientPlayerMapShow", root, true)
   else
   	triggerEvent("onClientPlayerMapHide", root, true)
   end
end

function getZRMapFromWorldPosition(worldX, worldY)
	local mapX = x+pixelsPerMeter*(worldX-topLeftWorldX)*zoom
	local mapY = y+pixelsPerMeter*(topLeftWorldY-worldY)*zoom
	return mapX, mapY
end

function getWorldFromZRMapPosition(mapX, mapY)
	local worldX = topLeftWorldX+mapWidth/hSize*(mapX-x)
	local worldY = topLeftWorldY-mapHeight/vSize*(mapY-y)
	return worldX, worldY
end

function setPlayerZRMapImage(image, tLX, tLY, lRX, lRY)
	if (image and type(image) == "string") and (type(tLX) == "number") and (type(tLY) == "number") and (type(lRX) == "number") and (type(lRY) == "number") then
		sourceResource = sourceResource or thisResource
		
		if (string.find(image,":") ~= 1) then
			sourceResourceName = getResourceName(sourceResource)
			image = ":"..sourceResourceName.."/"..image
		end
		
		if (dxDrawImage(0, 0, 0, 0, image, 0, 0, 0, 0, false)) then
			imageOwnerResource = sourceResource
			
			mapFile = image
			topLeftWorldX,topLeftWorldY = tLX,tLY
			lowerRightWorldX,lowerRightWorldY = lRX,lRY
			mapWidth,mapHeight = lRX-tLX,tLY-lRY
			pixelsPerMeter = math.min(screenW/(mapWidth),screenH/mapHeight)
			
			zoom = 1
			xOffset = 0
			yOffset = 0
			return true
		end
	elseif not (image) then
		imageOwnerResource = thisResource
		
		mapFile = "images/radar8192.jpg"
		topLeftWorldX,topLeftWorldY = -3000,3000
		lowerRightWorldX,lowerRightWorldY = 3000,-3000
		mapWidth,mapHeight = 6000,6000
		pixelsPerMeter = screenH/6000
		
		zoom  = 1
		xOffset = 0
		yOffset = 0

		return true
	end
	return false
end

function getPlayerZRMapImage()
	return mapFile
end

function setPlayerZRMapColor(colorR, colorG, colorB, colorA)
	mapDrawColor = tocolor(colorR, colorG, colorB, colorA)
	mapR, mapG, mapB, mapA = colorR, colorG, colorB, colorA
end

function setPlayerZRMapMovementSpeed(value)
	movementSpeed = value
end

function getPlayerZRMapMovementSpeed()
	return movementSpeed
end

function getPlayerZRMapZoomFactor()
	return zoom
end

function getPlayerZRMapZoomRate()
	return zoomRate
end

function setPlayerZRMapZoomFactor(value)
	if (value >= minZoomLimit) and (value <= maxZoomLimit) then
		local prevZoom = zoom
		zoom = value	
	    if (value < prevZoom) then
		   zoomOutRecalculate()
		end		
	end
end

function setPlayerZRMapMinZoomLimit(value)
	minZoomLimit = value
end

function setPlayerZRMapMaxZoomLimit(value)
	maxZoomLimit = value
end

function getPlayerZRMapMinZoomLimit()
	return minZoomLimit
end

function getPlayerZRMapMaxZoomLimit()
	return maxZoomLimit
end

function getPlayerZRMapColor()
	return mapR, mapG, mapB, mapA
end
Edited by Burak5312
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...