Jump to content

Cross roads visible on Radar


h4x7o0r

Recommended Posts

Posted

Hello, I've seen an useful radar resource on a cross server. The particularity of this radar is that u can see the cross roads (vgsh...).

Here is a picture to see exactly why am i looking for :

o0w2tt.png

Posted

@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 
  

Posted

Thank you for your reply, good is correct but how can i continue ? for example on the radar to have the road visible on the radar ?

All the best.

Posted

yes i'm having .img of the road that needs to be replaced on the map and also the id for each one of road, but i don't know how can i modify the dxDrawLine to fit my requirements.

Posted
yes i'm having .img of the road that needs to be replaced on the map and also the id for each one of road, but i don't know how can i modify the dxDrawLine to fit my requirements.

you can get X,Y,Z from object, and draw line

Posted

Thank you very much for your reply, sincerly i don't know how to calculate or what should i do :(

LE : I wanna have all roads visible on the radar not only one.

Posted

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 

Posted

I've read about what u've suggested but couldn't do it by myself that's why i've posted my *fail*script to see what should i need to change. I still don't know how to make visible on the radar my image.

Posted
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"

Posted

Thank you so much for your effort, u made my day.

There are some errors :

LINE 37: Bad argument @ "dxDrawImage" [Expected number at argument 1, got nil]

Posted

I've used some values, like : 200 20 160 32. (didn't let that unmodified)

Should I need another function to retrieve this ?

Thank you for all and still sorry for bothering.

All the best.

Posted

Those are values that i can find somewhere .. or do i need another function to get them all ? This is kinda ambiguous. Feel sorry for bothering you with my misunderstood and also thanks for your help.

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