WASSIm. Posted February 24, 2014 Share Posted February 24, 2014 hi guys i make radar like gta v but i don't know how make blips like this if them away Link to comment
Moderators Citizen Posted February 24, 2014 Moderators Share Posted February 24, 2014 (edited) You just have to calculate the pos like every others blip but before you render em, just verify if the position is out of the rectangle. If it is then replace the pos by the max. And do the reverse for the min pos they can have on the screen. local blipX = --some maths here to calculate the absolute X position of the blip local blipY = --some maths here to get the calculate Y position of the blip --for the X axe if blipX < radarX then blipX = radarX end --left side if blipX > radarX + radarWidth then blipX = radarX + radarWidth end --right side --for the Y axe if blipY < radarY then blipY = radarY end --top side if blipY > radarY + radarWidth then blipY = radarY + radarWidth end --bottom side --render everything For better performance, you can use elseif instead of two if in a row as I did (was a bit lazy ) We also can replace the if statements I did by using math.min (I'm writing it so check my post later, I just let you with the if version atm). EDIT: Here is the version with math.min and math.max: local blipX = --some maths here to calculate the absolute X position of the blip local blipY = --some maths here to get the calculate Y position of the blip blipX = math.max(radarX, math.min(radarX + radarWidth, blipX) blipY = math.max(radarY, math.min(radarY + radarHeight, blipY) I didn't tested it but I hope I didn't made mistakes in this version Edited February 24, 2014 by Guest Link to comment
WASSIm. Posted February 24, 2014 Author Share Posted February 24, 2014 (edited) the problem idk how make some maths to calculate the absolute X and Y position of the blip EDIT: thanks its working but i have some bugs. this code you can test it i removed health and armor bar and background code removed Edited February 25, 2014 by Guest Link to comment
Moderators Citizen Posted February 24, 2014 Moderators Share Posted February 24, 2014 Well it wasn't what you asked us for. I thought you already did the math part. Well I would say you need to find the ratio of you map file (probably by watching the difference between what returns getElementPosition, your position on the default map get the position (pixels) to be at the same place of your map file) Note: the pos: 0, 0 is the middle of the map. The part above has to be done outside of the radar script. To get the ratioX and ratioY (should be equal if the map is a square, and it should be). Once you got them (and I suppose your map file is 3000x3000 pixels): local mapImgWidth, mapImgHeight = 3000, 3000 local ratioX, ratioY = --[[value here]], --[[value here]] local x, y = getElementPosition(localPlayer) local tempMapX, tempMapY = x*ratioX, y*ratioY --the position in pixels on your map file ( with the middle of this file as origin (0, 0) ) local mapX, mapY = tempMapX + mapImgWidth/2, tempMapY + mapImgHeight/2 --the position in pixels on your map file ( with the upper left corner of this image as origin (0, 0) ) --so now we have the real position in pixels, we draw the the map: dxDrawImageSection(radarX, radarY, radarWidth, radarHeight, mapX - mapWidth/2, mapY - mapWidth/2, mapX + mapWidth/2, mapY + mapWidth/2, "images/map.png") Please read and try to understand that code (also tell me if it works ^^). This code will only draw the right part of the map according to the player position (btw, ratioX and ratioY have to be correct). And the player is always in the center of the radar. Once you got that, you can easily calculate the blips positions aswell. But I won't give you the code because it's currently taking me too much time. EDIT: Damn it ! You stole code while I was writing. Which is making my big post almost useless ... np. I can't test it (I mean I don't have enough time for that). What's the problem ?? (details explaination + screens if needed) Link to comment
Moderators Citizen Posted February 24, 2014 Moderators Share Posted February 24, 2014 thanks its working but i have some bugs Well idk which bug it is but I already can see one: local blipX = (posX+(width/2))+cblipx-(blipsize/2) local blipY = (posY+(height/2))+cblipy-(blipsize/2) local blipX = math.max(posX, math.min(posX + width, blipX)) local blipY = math.max(posY, math.min(posY + height, blipY)) You are creating these local variables twice, which is forbidden. local blipX = (posX+(width/2))+cblipx-(blipsize/2) local blipY = (posY+(height/2))+cblipy-(blipsize/2) blipX = math.max(posX, math.min(posX + width, blipX)) blipY = math.max(posY, math.min(posY + height, blipY)) (I removed the local keywords on line 4 and 5). This bug is now fixed and the two variable will still be locals variables. Link to comment
WASSIm. Posted February 24, 2014 Author Share Posted February 24, 2014 same. its not on his position on i closed it and look at blip then on bar health Link to comment
Moderators Citizen Posted February 24, 2014 Moderators Share Posted February 24, 2014 its not on his position on i closed it Can you please rewrite this in english please ? Then what shows the red arrow ? and look at blip then on bar health Not my fault, you were supposed to give the radar height to my math.min for the Y axe and by that I mean only the height of the image being rendered: blipX = math.max(posX, math.min(posX + width/scale, blipX)) --pretty sure u need to do that too for the X blipY = math.max(posY, math.min(posY + height/scale, blipY)) Link to comment
WASSIm. Posted February 25, 2014 Author Share Posted February 25, 2014 (edited) images removed Edited February 26, 2014 by Guest Link to comment
Moderators Citizen Posted February 25, 2014 Moderators Share Posted February 25, 2014 Yeah ok, it's just because the code you stole was designed for a circular radar. And in this code, the author used this lines of code to prevent blip icons going outside the radar: local dist = getDistanceBetweenPoints2D(px, py, bx, by) if dist > range then dist = tonumber(range) end (range is defined on top of the script to 100) so just remove that lines to let our code (math.min and math.max on the blip position) prevents them (the blips) to go outside the radar. Link to comment
WASSIm. Posted February 25, 2014 Author Share Posted February 25, 2014 finally i fixed it thank you you're helpful me Link to comment
WASSIm. Posted February 26, 2014 Author Share Posted February 26, 2014 (edited) i want make radararea on my radar but i get problem code removed Edited March 4, 2014 by Guest Link to comment
Moderators Citizen Posted February 26, 2014 Moderators Share Posted February 26, 2014 I really don't understand the position and size calculation in this code, it's kinda different from the blip one but it should looks like the same. Specially this: dxDrawRectangle(radarX, radarY, rw/2, -rh/2, tocolor(rr, rg, rb, ra), false) why -rh/2 ? is it like a random fix you tried ? If yes, then remove it in my code too (replace - by a + on line : local radarX = ((rmapX+(rmapW/2))+cradarx) local radarY = ((rmapY+(rmapH/2))+cradary) -- keep the position inside radarX = math.max(rmapX, math.min(rmapX + rmapW, radarX)) radarY = math.max(rmapY , math.min(rmapY + rmapH, radarY)) -- keep the size inside local radarW = math.max(rmapX, math.min(rmapX + rmapW, rmapX + rw/2)) local radarH = math.max(rmapY , math.min(rmapY + rmapH, rmapX - rh/2)) if (isRadarAreaFlashing(radar)) then ra = ra*math.abs(getTickCount()%1000-500)/500 end dxDrawRectangle(radarX, radarY, radarW, radarH, tocolor(rr, rg, rb, ra), false) Link to comment
WASSIm. Posted February 26, 2014 Author Share Posted February 26, 2014 now it worst. i don't want make radararea on range of radar Link to comment
Moderators Citizen Posted February 27, 2014 Moderators Share Posted February 27, 2014 Ok, can you please paste your code for the blips please ? Link to comment
WASSIm. Posted February 27, 2014 Author Share Posted February 27, 2014 (edited) code removed Edited March 4, 2014 by Guest Link to comment
Moderators Citizen Posted February 27, 2014 Moderators Share Posted February 27, 2014 (edited) Ok I think I did it, the only way to be sure is to test it. I checked the code 3 times line per line and in my head it does work Add this right under the loop for the blips (or right over if you want the blips to be rendered over the radar areas). for k, radararea in ipairs(getElementsByType("radararea")) do local rint = getElementInterior(radararea) local rdim = getElementDimension(radararea) if pi == rint and pd == rdim then local rx, ry = getElementPosition(radararea) local rw, rh = getRadarAreaSize(radararea) local rx2, ry2 = rx + rw, ry + rh local dist = getDistanceBetweenPoints2D(px, py, rx, ry) local dist2 = getDistanceBetweenPoints2D(px, py, rx2, ry2) --- As I already said, I don't understand this part, but if you are sure it's working nice for blips then it should work --- --top left corner local angle = 180 + findRotation(px, py, rx, ry) local crx, cry = getDistanceRotation(0, 0, range*(dist/range)/2, angle) local rX = math.max(rmapX, math.min(rmapX + rmapW, (rmapX+(rmapW/2))+crx)) local rY = math.max(rmapY, math.min(rmapY + rmapH, (rmapY+(rmapH/2))+cry)) -- bottom right corner local angle2 = 180 + findRotation(px, py, rx2, ry2) local crx2, cry2 = getDistanceRotation(0, 0, range*(dist2/range)/2, angle2) local rX2 = math.max(rmapX, math.min(rmapX + rmapW, (rmapX+(rmapW/2))+crx2)) local rY2 = math.max(rmapY, math.min(rmapY + rmapH, (rmapY+(rmapH/2))+cry2)) ---------------------------------------------------------------------------------------------------------------------------- if rX ~= rX2 and rY ~= rY2 then --means it's out of the radar local rr, rg, rb, ra = getRadarAreaColor(radararea) local rW, rH = rX2 - rX, rY2 - rY --- I dunno if that part really does what it should. I assume it does. --- if (isRadarAreaFlashing(radararea)) then ra = ra*math.abs(getTickCount()%1000-500)/500 end -------------------------------------------------------------------------- dxDrawRectangle(rX, rY, rW, rh, tocolor(rr, rg, rb, ra)) end end end Note: Do not create the radar area with a too high alpha if you want to see the map under the rectangles. I really hope it will work EDIT: Fixed typo at line 32 (cf. next post) Edited February 27, 2014 by Guest Link to comment
Castillo Posted February 27, 2014 Share Posted February 27, 2014 Small typo at isRadarAreaFlashing, you put "radar" but should of been "radararea". Link to comment
Moderators Citizen Posted February 27, 2014 Moderators Share Posted February 27, 2014 Small typo at isRadarAreaFlashing, you put "radar" but should of been "radararea". Oh wups ! You're right, I forgot to replace the name after I copied pasted that piece of code. Thanks. Link to comment
Moderators Citizen Posted March 3, 2014 Moderators Share Posted March 3, 2014 working fine thank you Link to comment
myonlake Posted March 4, 2014 Share Posted March 4, 2014 @OP: The MTA forums aren't here for personal advantage. If you want to get support, then don't remove your code. There are other people having same issues and you're just not making it any better here for anyone. That's just a disgrace. Link to comment
WASSIm. Posted March 4, 2014 Author Share Posted March 4, 2014 @OP: The MTA forums aren't here for personal advantage. If you want to get support, then don't remove your code. There are other people having same issues and you're just not making it any better here for anyone. That's just a disgrace. why ? for other stolen it ? just them can get exmple how make blip or how make radar area on radar Link to comment
myonlake Posted March 4, 2014 Share Posted March 4, 2014 No. If you don't want it to be used by others, then don't ask for our help at all in the first place. Link to comment
WASSIm. Posted March 4, 2014 Author Share Posted March 4, 2014 No. If you don't want it to be used by others, then don't ask for our help at all in the first place. realy ? everyone if solved his problem need share his code ? why after i make radar some people want copy my idea radar gta v? Link to comment
myonlake Posted March 4, 2014 Share Posted March 4, 2014 That's not what I meant. The thing I meant was that you removed all your code from this thread, which is kind of considered as a bad habit. You don't need to release your code, just don't remove the code in the thread you post. That's just ridiculous. I've had many of my help threads out there too with all kinds of code; doesn't mean I have to delete it all. It's very unlikely for them to be able to make something work by copy-pasting the code from forums anyways; the code is considered as material for further questions related to the same issues, this way we don't always have to give the same answers again when people can use the search tool and search for that issue. Just keep this in your mind next time you come around asking for help. Link to comment
WASSIm. Posted March 4, 2014 Author Share Posted March 4, 2014 them my full code anyone can stolen and use it or uploaded it on community and me & Citizen make it Link to comment
Recommended Posts