# [Help] How to convert coords to pixels, correctly?

## Recommended Posts

Is there any universal way, to convert GTA SA coordinates to pixels?

I tried with this:

```local x, y = getElementPosition(localPlayer)
x = (256 * x) / 6000 --(Player's coords times myMinimapWidth) devided by GTASAMaxCoords
y = (256 * y) / 6000 --Same as upper's```

But it's not giving me positive results. Anyone knows the way?

Edited by VaporZ
• Moderators

Looks good.

I think you spoil it elsewhere.

Edited by stPatrick
10 minutes ago, stPatrick said:

Looks good.

I think you spoil it elsewhere.

Look at this, perhaps ur right:

```pliki = {
mapa = "files/colormap.png",
gracz = "files/playerblip.png"
}

hud = {
szer = 320,
przez = 200
}

end)

end)

local w, h = guiGetScreenSize()

local x, y, z = getElementPosition(localPlayer)

local mult = 320 / 6000

local sX = x * mult
local sY = y * mult

local r = getScreenRotationFromWorldPosition(x, y, z)

dxDrawImageSection(9, 24, hud.szer, hud.szer, sX, sY, hud.szer, hud.szer, pliki.mapa, r--[[ - 72]], 0, 0, tocolor(255, 255, 255, hud.przez))
end)```

Results are negative, for my expectations.

At line 24, you already divide image size by 6000 and then in 26/27 you multiply it with player position but you need to multiply image size with player position first before dividing it by 6000.

Edited by -ffs-PLASMA
1 minute ago, -ffs-PLASMA said:

At line 24, you already divide image size by 6000 and then in 26/27 you multiply it with player position but you need to multiply image size with player position first before dividing it by 6000.

Ok, but look at this at logic side:

```local x, y, z = getElementPosition(localPlayer)

local mult = 320 / 6000

local sx = x * mult --Example: 16 (x) * 0.05 (320 / 6000) = 0.8
local sy = y * mult

--Isn't that same as:

local sx = (x * 320) / 6000 --Example: 16 (x) * 0.05 (320 / 6000) = 0.8
local sy = (y * 320) / 6000```

If you still not see the similarity, look:

(16 * 320) / 6000 is pretty the same as 16 * (320 / 6000)

2 hours ago, stPatrick said:

Looks good.

I think you spoil it elsewhere.

Well, I have another question, skipping previous, why this don't rendering target?

```pliki = {
mapa = "files/colormap.png"
}

hud = {
szer = 320,
przez = 200
}

image = dxCreateRenderTarget(hud.szer, hud.szer, true)
end)

destroyElement(image)
end)

local x, y, z = getElementPosition(localPlayer)
local r = getScreenRotationFromWorldPosition(x, y, z)

dxSetRenderTarget(image)
-dxSetBlendMode("blend")
dxDrawImageSection(9, 24, 3000, 3000, x, y, 3000, 3000, pliki.mapa)
end)```

• Scripting Moderators
20 minutes ago, VaporZ said:

Well, I have another question, skipping previous, why this don't rendering target?

```
pliki = {
mapa = "files/colormap.png"
}

hud = {
szer = 320,
przez = 200
}

image = dxCreateRenderTarget(hud.szer, hud.szer, true)
end)

destroyElement(image)
end)

local x, y, z = getElementPosition(localPlayer)
local r = getScreenRotationFromWorldPosition(x, y, z)

dxSetRenderTarget(image)
-dxSetBlendMode("blend")
dxDrawImageSection(9, 24, 3000, 3000, x, y, 3000, 3000, pliki.mapa)
end)
```

Not finished comment i guess?

`-dxSetBlendMode("blend")`

Perhaps do you use /debugscript 3 because it doesn't seems to?

48 minutes ago, majqq said:

Not finished comment i guess?

Nah, miss click. But why it doesn't render dxDrawImageSection()

• Scripting Moderators

Hope you can find the solution in my dxlib: https://wiki.multitheftauto.com/wiki/Dgs

5 hours ago, thisdp said:

Hope you can find the solution in my dxlib: https://wiki.multitheftauto.com/wiki/Dgs

Nope  I've already managed it to work successfully, but thank you for recommendation!

## Create an account

Register a new account