Karuzo Posted February 22, 2014 Share Posted February 22, 2014 Hello everyone, I have a problem with my radar. I want to draw a part of the map.png , let's say just 150x150 of the map.png with a little zoom or smth like that. Example(i don't want that Zoom Level^^): I want to show a part of the radar , like in the picture. Here's my code what i've got atm. addEventHandler("onClientRender",root, function() showPlayerHudComponent("radar", false) local px,py,pz = getElementPosition(localPlayer) local screenx, screeny = guiGetScreenSize() local bx = 200 local by = 200 local ppx = 5 local ppy = 5 local box_screen_x = (screenx/100) local box_screen_y = (screeny/100 *98)- by local point_x = (3000+px)/6000*200 local point_y = (3000-py)/6000*200 dxDrawImage(box_screen_x, box_screen_y,bx,by,"files/map.png") dxDrawImage(box_screen_x+point_x, box_screen_y+point_y, ppx, ppy,"files/redicon.png") for i, v in ipairs( getElementsByType('player') ) do if v ~= localPlayer then local apx,apy,apz = getElementPosition(v) local point_xx = (3000+apx)/6000*200 local point_yy = (3000-apy)/6000*200 dxDrawImage(box_screen_x+point_xx, box_screen_y+point_yy, ppx, ppy,"files/blueicon.png") end end end) Hope you understood me Link to comment
Karuzo Posted February 22, 2014 Author Share Posted February 22, 2014 So i think i got it, but the problem is the localPlayer's icon is not at the right location. idk why, The Screenshot: My Code: addEventHandler("onClientRender",root, function() showPlayerHudComponent("radar", false) local px,py,pz = getElementPosition(localPlayer) local screenx, screeny = guiGetScreenSize() local bx = 256 local by = 200 local ppx = 5 local ppy = 5 local box_screen_x = (screenx/100) local box_screen_y = (screeny/100*90)- by local point_x = (3000+px)/6000*256 local point_y = (3000-py)/6000*(bx-by) dxDrawImageSection(box_screen_x, box_screen_y, 256, 200,bx+(px*256/6000),by-(py*200/6000), 256, 200, "files/map.png") --dxDrawImage(box_screen_x, box_screen_y,bx,by,"files/map.png") dxDrawImage(box_screen_x+point_x, box_screen_y+point_y, ppx, ppy,"files/me.png")--Localplayers Icon --[[for i, v in ipairs( getElementsByType('player') ) do --Don't care to this. if v ~= localPlayer then local scale = 256/(3000*2) local apx,apy,apz = getElementPosition(v) local point_xx = box_screen_x+apx*scale local point_yy = box_screen_y+apy*scale dxDrawImage(point_xx, point_yy, ppx, ppy,"files/them.png") end end--]] end) i know i know , the code is mess, but i'm just tryin' something new and didn't do that before. Link to comment
Bonsai Posted February 22, 2014 Share Posted February 22, 2014 I didn't really check the code, but I suggest you do use a rendertarget. Its easier to handle in my opinion. Link to comment
Karuzo Posted February 22, 2014 Author Share Posted February 22, 2014 Hmm, i think it's just an error which i can't see. Link to comment
Blaawee Posted February 22, 2014 Share Posted February 22, 2014 I'v been working on something like that before and i got it work. try this : local screenx, screeny = guiGetScreenSize( ); local posX = 2; local posY = 247; -- Make sure it's the right values local width = 150; local height = 150; -- local scale = 2.2; local texture = dxCreateTexture( 'files/map.png', 'dxt5', true, 'clamp' ); imageWidth, imageHeight = dxGetMaterialSize( texture ); showPlayerHudComponent( "radar", false ) addEventHandler("onClientRender",root, function( ) local px ,py, pz = getElementPosition( localPlayer ) local mapX = px / ( 6000 / imageWidth ) + ( imageWidth / 2 ) - ( width / scale / 2 ); local mapY = py / ( -6000 / imageHeight ) + ( imageHeight / 2 ) - ( height / scale / 2 ); dxDrawImageSection( posX, screeny - posY, width, height, mapX, mapY, width / scale, height / scale, texture, 0, 0, 0, tocolor( 255, 255, 255, 255 ), false ); -- You can use a rectangle --dxDrawRectangle( posX + width / 2, screeny - posY + height / 2, 5, 5, tocolor( 0, 0, 255, 255 ) ); -- Or dxDrawImage( posX + width / 2, screeny - posY + height / 2, 5, 5, "files/me.png" ); --[[for i, v in ipairs( getElementsByType('player') ) do --Don't care to this. if v ~= localPlayer then local scale = 256/(3000*2) local apx,apy,apz = getElementPosition(v) local point_xx = box_screen_x+apx*scale local point_yy = box_screen_y+apy*scale dxDrawImage(point_xx, point_yy, ppx, ppy,"files/them.png") end end]] end ) Link to comment
Karuzo Posted February 22, 2014 Author Share Posted February 22, 2014 Hey Blaawee! Thank you! it works perfect! But i've got one problem : The radar has a low-quality, i can't see the streets, and i want that the players could see the streets with let's say a scale 2.4. Hope you understand me Link to comment
Blaawee Posted February 22, 2014 Share Posted February 22, 2014 It's depend on your texture,try to find a good texture with a high dimensions. Link to comment
Karuzo Posted February 22, 2014 Author Share Posted February 22, 2014 Well i use the one which is in F11, i can't find another one. Link to comment
MTA Team 0xCiBeR Posted February 22, 2014 MTA Team Share Posted February 22, 2014 A 1.0 or 1.5 scale would solve the problem i think Link to comment
Karuzo Posted February 22, 2014 Author Share Posted February 22, 2014 Yeah, did that, but isn't there a better picture than the one i've found ? it has the resolutions 900x900, i think there could be more //Edit: Is there a way to rotate the radar ? Link to comment
Blaawee Posted February 22, 2014 Share Posted February 22, 2014 I'm not sure if this will work or not local screenx, screeny = guiGetScreenSize( ); local posX = 2; local posY = 247; -- Make sure it's the right values local width = 150; local height = 150; -- local scale = 2.2; local texture = dxCreateTexture( 'files/map.png', 'dxt5', true, 'clamp' ); imageWidth, imageHeight = dxGetMaterialSize( texture ); showPlayerHudComponent( "radar", false ) addEventHandler("onClientRender",root, function( ) local px ,py, pz = getElementPosition( localPlayer ) local mapX = px / ( 6000 / imageWidth ) + ( imageWidth / 2 ) - ( width / scale / 2 ); local mapY = py / ( -6000 / imageHeight ) + ( imageHeight / 2 ) - ( height / scale / 2 ); local cx,cy,cz,tx,ty,tz = getCameraMatrix( ); local rotation = findRotation( cx,cy,tx,ty ); dxDrawImageSection( posX, screeny - posY, width, height, mapX, mapY, width / scale, height / scale, texture, rotation, 0, 0, tocolor( 255, 255, 255, 255 ), false ); -- You can use a rectangle --dxDrawRectangle( posX + width / 2, screeny - posY + height / 2, 5, 5, tocolor( 0, 0, 255, 255 ) ); -- Or dxDrawImage( posX + width / 2, screeny - posY + height / 2, 5, 5, "files/me.png" ); --[[for i, v in ipairs( getElementsByType('player') ) do --Don't care to this. if v ~= localPlayer then local scale = 256/(3000*2) local apx,apy,apz = getElementPosition(v) local point_xx = box_screen_x+apx*scale local point_yy = box_screen_y+apy*scale dxDrawImage(point_xx, point_yy, ppx, ppy,"files/them.png") end 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 Link to comment
Karuzo Posted February 22, 2014 Author Share Posted February 22, 2014 Thank you for your reply, but as you can see that's not that nice :3 Link to comment
MTA Team 0xCiBeR Posted February 22, 2014 MTA Team Share Posted February 22, 2014 Try rotating the rectangle too. Link to comment
pa3ck Posted February 22, 2014 Share Posted February 22, 2014 Try this map: http://oi60.tinypic.com/2jez9kw.jpg Link to comment
Blaawee Posted February 22, 2014 Share Posted February 22, 2014 What about to add an image like a mask maybe this will be usefull. Link to comment
Karuzo Posted February 22, 2014 Author Share Posted February 22, 2014 Try rotating the rectangle too. How ? There is no rotation argument on dxDrawRectangle i think. @pa3ck: Thank you! @Blaawee: how do you mean that ? Link to comment
MTA Team 0xCiBeR Posted February 22, 2014 MTA Team Share Posted February 22, 2014 Try rotating the rectangle too. How ? There is no rotation argument on dxDrawRectangle i think. With some math it can be done.. Link to comment
Karuzo Posted February 22, 2014 Author Share Posted February 22, 2014 Math is not really my friend, could you please tell me what i need for that ? Link to comment
Blaawee Posted February 22, 2014 Share Posted February 22, 2014 Try rotating the rectangle too. How ? There is no rotation argument on dxDrawRectangle i think. With some math it can be done.. well, show to us what you can do. 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