Vipont Posted May 15, 2024 Share Posted May 15, 2024 I have this client script in my customblips resource: ---------------BUGS------------------- --* 1) There's a period in between entering and exiting a vehicle whereby the camera switches its "lock on" from the ped to the vehicle or vice versa -- During this period, It is not possible to rotate the camera, but getCameraMatrix returns the lookAt point as if it had rotated. -- This means the customblip rotates like crazy but the radar doesnt -- --* 2) showPlayerHUDComponent has the ability to hide the radar, but custom blips is not aware of this. -- All scripts would also need to hook into customblips to notify it whenever hiding the radar -- -- Bug #2 is most easily fixed if we get a isRadarVisible/isPlayerHUDComponentVisible function or something to that effect local g_screenX,g_screenY = guiGetScreenSize() local localPlayer = getLocalPlayer() --Radar position/size local rel = { pos_x = 0.0625, pos_y = 0.76333333333333333333333333333333, size_x = 0.15, size_y = 0.175, radar_blip_y = 0.03333333333333333333333333333333, } local abs = { pos_x = math.floor(rel.pos_x * g_screenX), pos_y = math.floor(rel.pos_y * g_screenY), size_x = math.floor(rel.size_x * g_screenX), size_y = math.floor(rel.size_y * g_screenY), radar_blip_y = math.floor(rel.radar_blip_y * g_screenY) } abs.half_size_x = abs.size_x/2 abs.half_size_y = abs.size_y/2 abs.center_x = abs.pos_x + abs.half_size_x abs.center_y = abs.pos_y +abs.half_size_y local minBound = 0.1*g_screenY function getRadarScreenRadius ( angle ) --Since the radar is not a perfect ciricle, we work out the screen size of the radius at a certain angle return math.max(math.abs((math.sin(angle)*(abs.half_size_x - abs.half_size_y))) + abs.half_size_y,minBound) end count = 0 function renderBlip ( blip, toF11Map, radarWorldX, radarWorldY, camRot, radarRadius, F11minX, F11minY, F11maxX, F11maxY, F11sizeX, F11sizeY ) local blipX,blipY = streamedBlips[blip].x,streamedBlips[blip].y local width,height = streamedBlips[blip].width,streamedBlips[blip].height local radarScale = streamedBlips[blip].radarScale if not toF11Map then local toBlipRot = getVectorRotation(radarWorldX,radarWorldY,blipX,blipY ) local blipRot = toBlipRot - camRot --Get the screen radius at that rotation local radius = getRadarScreenRadius ( blipRot ) count = count + 1 local distance = getDistanceBetweenPoints2D ( radarWorldX,radarWorldY,blipX,blipY ) if (distance <= radarRadius) then setWidgetIsInRadar(blip, true) radius = (distance/radarRadius)*radius else setWidgetIsInRadar(blip, false) end local tx = radius * math.sin(blipRot) + abs.center_x local ty = -radius * math.cos(blipRot) + abs.center_y -- local sx,sy = width,height if radarScale then sx,sy = width*radarScale, height*radarScale setWidgetSize (blip,sx,sy) else --If the user hasnt forced a radar blip scale, we use GTA's default sizing local ratio = abs.radar_blip_y/height sx = ratio*width sy = abs.radar_blip_y setWidgetSize (blip,sx,sy) end setWidgetPosition(blip,tx-sx/2,ty-sy/2) else --Render to f11 map local minX, minY, maxX, maxY, sizeX, sizeY = F11minX, F11minY, F11maxX, F11maxY, F11sizeX, F11sizeY -- local mapX = blipX + 3000 local mapY = blipY + 3000 mapX = mapX*sizeX + minX mapY = maxY - mapY*sizeY --We set the original size in the F11 map local sx,sy = width,height setWidgetSize (blip,width,height) setWidgetPosition(blip,mapX-sx/2,mapY-sy/2) end end And I'm wondering how I can solve the Bug #2 with my radar client script in my radar resource. local screenSize = Vector2(guiGetScreenSize()) local settingsFileName = "configs.json" local radar = { x = 25, y = (screenSize.y - 240), w = 200, h = 200, mapImg = dxCreateTexture("images/map.png"); mapSize = 3072, playerSize = 24, blipSize = 12, shape = "round", } local bold = exports.fonts:getFont("roboto",12) local rt = dxCreateRenderTarget(radar.w, radar.h, true) local roundShaderMask = dxCreateShader("files/hud_mask.fx") local roundShaderImage = dxCreateTexture("images/circle_mask.png") local mapIcon = dxCreateTexture("images/map_icon.png"); addEventHandler("onClientResourceStart", resourceRoot, function() if not rt then rt = dxCreateRenderTarget(radar.w, radar.h, true) end if not roundShaderMask then roundShaderMask = dxCreateShader("files/hud_mask.fx") end if not roundShaderImage then roundShaderImage = dxCreateTexture("images/circle_mask.png") end dxSetShaderValue(roundShaderMask, "sPicTexture", rt) dxSetShaderValue(roundShaderMask, "sMaskTexture", roundShaderImage) setPlayerHudComponentVisible('radar', false) --dxSetShaderTransform(roundShaderMask, 0, 110, 0) local confile = fileOpen(settingsFileName) if confile then local count = fileGetSize(confile) local data = fileRead(confile, count) fileClose(confile) data = fromJSON(data) radar.x = data.x radar.y = data.y radar.w = data.w radar.h = data.h radar.shape = data.shape else confile = fileCreate(settingsFileName) fileClose(confile) end end) function getPlayerPosOnMap() local playerPos = Vector3(getElementPosition(localPlayer)) local mapX = radar.w/2 -(playerPos.x/(6000/radar.mapSize)) local mapY = radar.h/2 + (playerPos.y/(6000/radar.mapSize)) return Vector2(mapX, mapY) end addEventHandler("onClientRender", root, function() if not bold then bold = dxCreateFont(":hud/roboto.ttf", 12) end if getElementData(localPlayer, "loggedin") ~= 1 then return false end if not exports.hud:isActive() then return false end if getElementInterior(localPlayer) ~= 0 then return false end local camX,camY,camZ = getElementRotation(getCamera()) local playerPos = getPlayerPosOnMap() local pos = Vector2(getElementPosition(localPlayer)) if rt then dxSetRenderTarget(rt, true) dxDrawImage(playerPos.x - radar.mapSize/2, playerPos.y - radar.mapSize/2, radar.mapSize, radar.mapSize, radar.mapImg, camZ, (pos.x/(6000/radar.mapSize)), -(pos.y/(6000/radar.mapSize))) dxSetRenderTarget() end if radar.shape == "rect" or radar.shape == "square" then dxDrawRectangle(radar.x - 5, radar.y - 5, radar.w + 10, radar.h + 10, tocolor(17, 17, 17, 255)) dxDrawImage(radar.x, radar.y, radar.w, radar.h, rt) dxDrawRectangle(radar.x, radar.y, radar.w, 23, tocolor(17, 17, 17, 200)) dxDrawImage(radar.x + 2, radar.y, 20, 20, mapIcon, 0, 0, 0, tocolor(217, 70, 70)) dxDrawText(getZoneName(getElementPosition(localPlayer)), radar.x + 25, radar.y, 0, radar.y + 20, tocolor(255, 255, 255), 1, bold, "left", "center") dxDrawText("© Los Santos Roleplay", radar.x + 3, radar.y + radar.h - 15, 0, 0, tocolor(217, 70, 70, 150), 1) elseif radar.shape == "round" then dxDrawImage(radar.x - 8, radar.y - 6, radar.w + 16, radar.h + 16, roundShaderImage, 0, 0, 0, tocolor(217, 70, 70)) dxDrawImage(radar.x - 8, radar.y - 8, radar.w + 16, radar.h + 16, roundShaderImage, 0, 0, 0, tocolor(17, 17, 17)) dxDrawImage(radar.x, radar.y, radar.w, radar.h, roundShaderMask) end local rB, lB, tB, bB = radar.x + radar.w, radar.x, radar.y, radar.y + radar.h local cX, cY = (rB+lB)/2, (tB+bB)/2 local toLeft, toTop, toRight, toBottom = cX-lB, cY-tB, rB-cX, bB-cY if radar.shape == "square" or radar.shape == "rect" then tB = radar.y + 25 end for _, blip in ipairs(getElementsByType("blip")) do local blipPos = Vector2(getElementPosition(blip)) local distance = getDistanceBetweenPoints2D(blipPos.x, blipPos.y, pos.x, pos.y) local maxDistance = getBlipVisibleDistance(blip) if distance <= maxDistance and getElementDimension(blip) == getElementDimension(localPlayer) and getElementInterior(localPlayer) == getElementInterior(blip) then local trueDistance = distance/(6000/radar.mapSize) local rot = findRotation(blipPos.x, blipPos.y, pos.x, pos.y) - camZ local goodBlipPos = Vector2(getPointFromDistanceRotation(cX, cY, math.min(trueDistance, math.sqrt(toTop^2 + toRight^2)), rot)) if radar.shape ~= "rect" and radar.shape ~= "square" then goodBlipPos = Vector2(getPointFromDistanceRotation(cX, cY, math.min(trueDistance, radar.w/2), rot)) end goodBlipPos.x = math.max(lB, math.min(rB, goodBlipPos.x)) goodBlipPos.y = math.max(tB, math.min(bB, goodBlipPos.y)) local r, g, b, a = getBlipColor(blip) dxDrawImage(goodBlipPos.x - (radar.blipSize * getBlipSize(blip))/2, goodBlipPos.y - (radar.blipSize * getBlipSize(blip))/2, radar.blipSize * getBlipSize(blip), radar.blipSize * getBlipSize(blip), "images/blips/" .. getBlipIcon(blip) .. ".png", 0, 0, 0, tocolor(r or 255, g or 255, b or 255, a or 255)) end end --[[local ux, uy = nil, nil local alapBeallitasok = exports['ace_rendszer']:getAlapBeallitasok() for i,utvonal in ipairs(gpsPontok) do local hsl = exports['ace_rendszer']:tabla_masolas(alapBeallitasok["szerverSzin"]["hsl"]) hsl[2] = -0.5 local szin = {exports['ace_rendszer']:hsl2rgb(hsl[1], hsl[2], hsl[3])} local x,y = utvonal.x, utvonal.y local n_x = (((((3000)+x)/(6000)*(radar.mapSize))-((radar.w/2)))+((radar.w/2))) local n_y = ((((3000-y)/(6000)*radar.mapSize)-((radar.h/2)))+((radar.h/2))) if(ux and uy) then dxDrawLine ( ux, uy, n_x, n_y, tocolor(144, 0, 254, 255), 8 ) ux, uy = n_x, n_y else ux, uy = n_x,n_y end end]] dxDrawImage((radar.x + radar.w/2) - radar.playerSize/2, (radar.y + radar.h/2) - radar.playerSize/2, radar.playerSize, radar.playerSize, "images/player.png", camZ-getPedRotation(localPlayer)) end) north = createBlip( 0, 10000, 0, 4, 2, 255, 255, 255 ) function findRotation( x1, y1, x2, y2 ) local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) ) return t < 0 and t + 360 or t end function getPointFromDistanceRotation(x, y, dist, angle) --Author: robhol local a = math.rad(90 - angle); local dx = math.cos(a) * dist; local dy = math.sin(a) * dist; return x+dx, y+dy; end addEvent("radar:changeShape", true) addEventHandler("radar:changeShape", root, function(shape) if shape == "round" then radar.w = 200 radar.h = 200 radar.y = (screenSize.y - 240) elseif shape == "square" then radar.w = 200 radar.h = 200 radar.y = (screenSize.y - 240) elseif shape == "rect" then radar.y = (screenSize.y - 190) radar.w = 200 radar.h = 150 end radar.shape = shape saveRadarConf() end) function saveRadarConf() local confile = fileOpen(settingsFileName) if not confile then confile = fileCreate(settingsFileName) end local conTable = { x = radar.x, y = radar.y, w = radar.w, h = radar.h, shape = radar.shape } fileWrite(confile, toJSON(conTable)) fileClose(confile) end --BLIPS CNN = createBlip(1419.16796875, -1607.21875, 13.546875, 19, 2, 255, 255, 255) PD = createBlip(1554.8681640625, -1675.5947265625, 16.1953125, 30, 2, 255, 255, 255) GOV = createBlip(1481.0302734375, -1772.3134765625, 18.795755386353, 41, 2, 255, 255, 255) SMURD = createBlip(1172.0771484375, -1323.3505859375, 15.403001785278, 22, 2, 255, 255, 255) TUNNING = createBlip(946.90625, -1655.5498046875, 13.543536186218, 27, 2, 255, 255, 255) Can somebody help me ? Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now