XJMLN Posted August 5, 2017 Posted August 5, 2017 Hi, I wanna create a gui with minimap (like this), but i don't know how to calculate world position to screen position and show it on that map. I tried this: x2 =((x2 + 3000)/ 6000 *sw) y2 =((3000 - y2)/ 6000 *sh) But this show the wrong position for waypoint. Code: local sw,sh = guiGetScreenSize() local mw, mh = sw/1920, sh/1080 local t = {point=nil,pos=nil,map=false} t.gridlist = guiCreateGridList(mw*382, mh*281, mw*329, mh*530, false) t.gridlist_places = guiGridListAddColumn(t.gridlist, "Places", 0.9) guiSetVisible(t.gridlist,false) function travel_render() if not t.rendered then return end dxDrawImage((sw - sw*1200/1920)/2,(sh - sh*600/1080)/2,1200,600, "img/background.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) if t.map then dxDrawImage(t.pos[1],t.pos[2],32,32,"img/waypoint.png", 0,0,0, tocolor(255,255,255,255), false) end end function travel_fill(d) for i,v in ipairs(d) do local row = guiGridListAddRow(t.gridlist) guiGridListSetItemText(t.gridlist, row, t.gridlist_places, v.name, false, false) guiGridListSetItemData(t.gridlist, row, t.gridlist_places,v.tpPos) end end function travel_init() if (t.rendered) then removeEventHandler("onClientRender", root, travel_render) t.point = nil t.rendered = false guiSetVisible(t.gridlist,false) showCursor(false) guiGridListClear(t.gridlist) else guiGridListClear(t.gridlist) triggerServerEvent("travel_requestPlaces", localPlayer) t.rendered = true addEventHandler("onClientRender", root, travel_render) guiSetVisible(t.gridlist, true) showCursor(true) end end function interaction_fastTravel(args) if (not args.ped) then return end args.player = localPlayer local x,y,z = getElementPosition(args.player) local x2,y2,z2 = getElementPosition(args.ped) if (getDistanceBetweenPoints3D(x,y,z,x2,y2,z2)>2) then outputChatBox("You need to go closer.",255,0,0) return end t.point = args.ped travel_init() end function travel_updateBlip() local selRow = guiGridListGetSelectedItem(t.gridlist) if (selRow<0) then return end local pos = guiGridListGetItemData(t.gridlist, selRow, t.gridlist_places) local x2, y2, z2 = unpack(pos) x2 =((x2 + 3000)/ 6000 *sw) y2 =((3000 - y2)/ 6000 *sh) t.pos = {x2,y2} t.map = true end function travel_doTeleport() local selRow = guiGridListGetSelectedItem(t.gridlist) if (selRow<0) then return end local pos = guiGridListGetItemData(t.gridlist, selRow, t.gridlist_places) local x2, y2, z2 = unpack(pos) fadeCamera(false) travel_init() setElementFrozen(localPlayer,true) setTimer(function() setElementPosition(localPlayer,x2,y2,z2+1) setElementFrozen(localPlayer,false) fadeCamera(true) end,1500,1) end addEvent("travels_fillList", true) addEventHandler("travels_fillList", root,travel_fill) addEventHandler("onClientGUIClick", t.gridlist, travel_updateBlip) addEventHandler("onClientGUIDoubleClick", t.gridlist, travel_doTeleport) Anyone can help with this?
XJMLN Posted August 5, 2017 Author Posted August 5, 2017 But in this post you show how, from screen pos get world pos. I have the world pos and wanna get it to screen pos.
NeXuS™ Posted August 5, 2017 Posted August 5, 2017 Ahh, lol. I misunderstood the post. For more understanding I'd create a new variable which would indicate how many pixels one unit in GTA is. And then just use that to calculate everything. 1
XJMLN Posted August 5, 2017 Author Posted August 5, 2017 (edited) How i can calculate this units, just like this? local sw,sh = guiGetScreenSize() x2,y2,z2 -- coords x2 =x2/sw y2 = y2/sh Edited August 5, 2017 by jackpszmta
NeXuS™ Posted August 5, 2017 Posted August 5, 2017 (edited) local sX, sY = guiGetScreenSize() local mapW, mapH = 500, 500 local mapX, mapY = (sX-mapW)/2, (sY-mapH)/2 local pixelW = mapW/6000 local pixelH = mapH/6000 local testX, testY = 0, 0 function calculateScreen(inX, inY) return (inX+3000)*pixelW, math.abs((inY-3000))*pixelH end wX, wY = calculateScreen(testX, testY) outputChatBox(wX .. " " .. wY) Try this. Edited August 5, 2017 by NeXuS™ 1
Discord Moderators Pirulax Posted August 5, 2017 Discord Moderators Posted August 5, 2017 I dont think that i undestand you correctly, but try getScreenFromWorldPosition.
NeXuS™ Posted August 5, 2017 Posted August 5, 2017 (edited) You don't understand it correctly @Pirulax. Edited August 5, 2017 by NeXuS™
XJMLN Posted August 5, 2017 Author Posted August 5, 2017 Your code work good, but blip is showing on top left corner. How i can move that there: http://i.imgur.com/ipXmU1h.jpg?1 I tried this, but no reaction of change these values: local mapX,mapY = (sw - sw*1200/1920)/2,(sh - sh*600/1080)/2
NeXuS™ Posted August 5, 2017 Posted August 5, 2017 So, you'll have to use the returned variables. You have to add the 2 numbers to the position where you draw the image of the map. 1
</Mr.Tn6eL> Posted August 6, 2017 Posted August 6, 2017 you can use function map(value, low1, high1, low2, high2) return low2 + (high2 - low2) * (value - low1) / (high1 - low1) end local x, y = map(player_x, 0, world_w, 0, map_w), map(player_y, 0, world_h, 0, map_h) replace world_w and world_h with gta 3d world size and replace map_w and map_h with your 2d map x and player_x and player_y is player position
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