Jump to content

Cross roads visible on Radar


h4x7o0r

Recommended Posts

@jaysds1 : Yeah I've checked community resources and haven't found any to display the roads and so on.

@TwiX! : Thank you for your reply, I've seen the docs of

getElementsByType 

but haven't got the right answer .

local objects = getElementsByType ( "object" )  

But i don't know how to retrieve a specific id. For example. The cross road has 8558 id. Should i use getElementModel ?

function radar ( targetElem ) 
    if ( getElementType ( targetElem ) == "object" ) and ( getElementModel ( targetElem ) == 8558) then 
        ... 
    end 
  

Link to comment

Thank you for reply, I've just read about those 2 functions but i think it's not what I am looking for because i want that every road (every object) that has the desire id to be positioned on the radar. I can't use x,y,z for each road by itself.

LE: I've tried to figure it out how can i create the script but i think all it's a mess :(

I've even found a resource for "custom blips" https://community.multitheftauto.com/index.php?p= ... ils&id=960 that has some exported functions.

Here's what i've tried :

addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), 
 function () 
  if ( getElementType ( targetElem ) == "object" ) and ( getElementModel ( targetElem ) == 8558) then 
    local x, y, z = getElementPosition(targetElem) 
    local sx, sy = getScreenFromWorldPosition(x, y, z+3) 
    exports.customblips:createCustomBlip ( x,y, 160, 32, "road.png" ) 
     
    else  
    exports.customblips:destroyCustomBlip ( x,y, 160, 32, "road.png" ) 
    end 

Link to comment
local rObjects = { [3458] = true,[8558] = true }; -- Radar objects 
  
function getObjectsInMyDistance() 
    rObjectsTabele = {}; 
    local pX,pY,pZ = getElementPosition(localPlayer); 
    if not pX or not pY or not pZ then return end 
    for _,object in ipairs(getElementsByType("object")) do 
        local id = getElementModel(object); 
        if rObjects[id] then 
            local eX,eY,eZ = getElementPosition(object); 
            if not eX or not eY or not eZ then return end 
            local distance = getDistanceBetweenPoints2D(pX,pY,eX,eY); 
            if distance < 180 then  
                table.insert(rObjectsTabele,object); 
            end 
        end 
    end 
    return rObjectsTabele; 
end 
  
addEventHandler("onClientRender",getRootElement(),  
function() 
    local pX,pY,pZ = getElementPosition(localPlayer); 
    local cX,cY,_,tX,tY = getCameraMatrix(); 
    local n = findRotation(cX,cY,tX,tY); 
    for _,object in ipairs(getObjectsInMyDistance()) do 
        local oX,oY,oZ = getElementRotation(object); 
        local id = getElementModel(object); 
        local eX,eY,eZ = getElementPosition(object); 
        if id == 3458 then 
            img = "yourImage.png"; 
            --Here you can set rotation for object 
        elseif id == 8558 then 
            img = "YouImageForThisID.png"; 
            --Here you can set rotation for object 
        end 
        dxDrawImage(yourX,yourY,yourWidth,yourHeight,img,n-oZ,0,0,tocolor(255,255,255,255)); 
        --Or dxDrawLine 
    end 
end 
); 
  
function findRotation(x1,y1,x2,y2) 
    local t = -math.deg(math.atan2(x2-x1,y2-y1)); 
    if t < 0 then t = t + 360; end 
    return t 
end 

something like this

don't forget to change "yourX","yourY","yourWidth","yourHeight"

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...