Jump to content

dxDrawImageSection Problem


Karuzo

Recommended Posts

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^^):

6r9cSl9.png

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

So i think i got it, but the problem is the localPlayer's icon is not at the right location.

idk why,

The Screenshot:

48zs.png

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

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

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

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