Castillo Posted July 8, 2012 Share Posted July 8, 2012 Hi everyone. I'm having issues with calculations for a radar area, for some reason is not creating it where it should: My code: local width, height = math.abs ( x2 - x ), math.abs ( y2 - y ) if ( x2 < x ) then local tempx = x2 x2 = x x = tempx end if ( y2 < y ) then local tempy = y2 y2 = y y = tempy end And the screenshot of the problem: http://i.imgur.com/pNEwh.jpg The RED rectangle is the radar area created by script, and the GREEN is where the radar area should be. I hope someone can help me with this issue. Thanks in advance. Link to comment
Jaysds1 Posted July 8, 2012 Share Posted July 8, 2012 hmmm, well, after the width and height has been released, the script checks if x2/y2 < x/y now, I'm not sure, but try putting the width and height part after the that little check. if ( x2 < x ) then local tempx = x2 x2 = x x = tempx end if ( y2 < y ) then local tempy = y2 y2 = y y = tempy end local width, height = math.abs ( x2 - x ), math.abs ( y2 - y ) Link to comment
Castillo Posted July 8, 2012 Author Share Posted July 8, 2012 Same problem. Edit: Check the screenshot again, I had uploaded wrong one. Link to comment
FabienWang Posted July 8, 2012 Share Posted July 8, 2012 Easy: compare x and x2 values with abs (so you won't have problem whereever you are) if math.abs(x2) > math.abs(x) then local tempx = x2 x2 = x x = tempx end if math.abs(y2) > math.abs(y) then local tempy = y2 y2 = y y = tempy end local width, height = math.abs ( x2 - x ), math.abs ( y2 - y ) Link to comment
50p Posted July 8, 2012 Share Posted July 8, 2012 What about after you get x coord take away the width of the area to get correct x? x = x - width; -- or whichever x you use as the first argument in createRadarArea TIP: You can swap values in Lua as following: x, x2 = x2, x; Link to comment
Castillo Posted July 8, 2012 Author Share Posted July 8, 2012 Easy: compare x and x2 values with abs (so you won't have problem whereever you are) if math.abs(x2) > math.abs(x) then local tempx = x2 x2 = x x = tempx end if math.abs(y2) > math.abs(y) then local tempy = y2 y2 = y y = tempy end local width, height = math.abs ( x2 - x ), math.abs ( y2 - y ) With this the result is the following: http://i.imgur.com/rmH12.jpg Edit: With this: if math.abs(x2) > math.abs(x) then local tempx = x2 x2 = x x = tempx end if math.abs(y2) > math.abs(y) then local tempy = y2 y2 = y y = tempy end local width, height = math.abs ( x2 - x ), math.abs ( y2 - y ) x = x - width In Los Santos it works fine, but then in other places like Las Venturas it bugs like this: http://i.imgur.com/Gfc0x.jpg Link to comment
50p Posted July 8, 2012 Share Posted July 8, 2012 Why use math.abs to compare values? Doesn't matter where you are, if you get bottomX and bottomY values, they will always be smaller then topX and topY (since topX and topY are equal to bottomX + width and bottomY + height). Use math.abs only to calculate width and height only. Lets say you are in the x < 0 and y < 0 quadrant (which is quadrant III -> http://en.wikipedia.org/wiki/Quadrant_(plane_geometry)) x = -1245 y = -130 topX = -1200 topY = -10 x < topX and y < topY -- this is true if you do math.abs for these, it will be false because then: x > topX and y > bottomY Your last screenshot shows that you need to add height or radar area to bottomY coord. Link to comment
Castillo Posted July 8, 2012 Author Share Posted July 8, 2012 I don't understand what do you mean. Link to comment
50p Posted July 8, 2012 Share Posted July 8, 2012 Give an example of 2 areas you use: x, x2, y, y2 (from different quadrants, follow the link from previous post if you don't know what I mean by quadrants). I'm not sure if the coords you use are what I think they are. It's simple maths but if you get the coords wrong the result will be wrong. Link to comment
Castillo Posted July 8, 2012 Author Share Posted July 8, 2012 Area 1: x = 2257.3439941406 x2 = 2257.3439941406 y = 1347.7255859375 y2 = 1219.62890625 Area 2: x = 1434.8157958984 x2 = 1434.8157958984 y = -1724.2453613281 y2 = -1601.0743408203 The second area is bugged. Link to comment
50p Posted July 8, 2012 Share Posted July 8, 2012 Why both of your X values (x and x2) are the same? (Probably your mistake copy'n'pasting). If you use these coords to calculate width: x2 - x = 0; same if you do x - x2 = 0; Link to comment
Castillo Posted July 8, 2012 Author Share Posted July 8, 2012 I copied it exactly like the script output, this makes it the same: local x = ( x - width ) Area 1: x = 1524.0031738281 x2 = 1440.0651855469 y = -1725.3817138672 y2 = -1600.7269287109 Area 2: x = 2389.6433105469 x2 = 2256.5837402344 y = 1347.0687255859 y2 = 1219.8205566406 Link to comment
50p Posted July 8, 2012 Share Posted July 8, 2012 Your coords are wrong. They should be as swapped. Area 1: x = 1440.0651855469; y = -1725.3817138672; x2 = 1524.0031738281; y2 = -1600.7269287109; Area 2: x = 2256.5837402344; y = 1219.8205566406; x2 = 2389.6433105469; y2 = 1347.0687255859; Width and height: width = math.abs( x2 - x ); height = math.abs( y2 - y ); createRadarArea( x, y, width, height ); You should get coords in the following manner: Link to comment
Castillo Posted July 8, 2012 Author Share Posted July 8, 2012 I'm creating it like you say, but still bugged. Current code: if ( x2 > x ) then local tempx = x2 x2 = x x = tempx end if ( y2 > y ) then local tempy = y2 y2 = y y = tempy end width = math.abs( x2 - x ) height = math.abs( y2 - y ) local x = ( x - width ) Screenshot: http://i.imgur.com/Fc2Ec.jpg Link to comment
50p Posted July 8, 2012 Share Posted July 8, 2012 This is all you need: width = math.abs( x2 - x ) height = math.abs( y2 - y ) You don't need to swap coords. Try this (just copy'n'pase in onResourceStart): x = 1440.0651855469; y = -1725.3817138672; x2 = 1524.0031738281; y2 = -1600.7269287109; width = math.abs( x2 - x ); -- width = 1524 - 1440 = 84 height = math.abs( y2 - y ); -- height = -1600 - (-1725) = -1600 + 1725 = 125 createRadarArea( x, y, width, height ); Link to comment
Castillo Posted July 8, 2012 Author Share Posted July 8, 2012 http://i.imgur.com/berRt.jpg The created manually by your code works, but I can also create on that place without problems. Link to comment
50p Posted July 8, 2012 Share Posted July 8, 2012 That's all you need. Just replace the x, y, x2 and y2 with coords of other areas but remember to follow the rules I showed you on the picture previously and it should always create the area correctly. I think your coords are little messed up and that's the reason it fails or you have some more calculations which are not necessary. Link to comment
Castillo Posted July 8, 2012 Author Share Posted July 8, 2012 x = 1440.0651855469; y = -1725.3817138672; x2 = 1524.0031738281; y2 = -1600.7269287109; width = math.abs( x2 - x ); -- width = 1524 - 1440 = 84 height = math.abs( y2 - y ); -- height = -1600 - (-1725) = -1600 + 1725 = 125 createRadarArea( x, y, width, height ); I replaced these coordinates with ones from the Pyramid at Las Venturas and now it doesn't even appear. My coords: x = 2255.3669433594; y = 1344.3487548828; x2 = 2255.3669433594; y2 = 1219.9694824219; width = math.abs( x2 - x ); height = math.abs( y2 - y ); createRadarArea( x, y, width, height ); Link to comment
50p Posted July 8, 2012 Share Posted July 8, 2012 Your x and x2 are the same (so width = x2 - x = 0) Link to comment
Castillo Posted July 8, 2012 Author Share Posted July 8, 2012 I tried using the coords given, instead of what the script gives and it doesn't work either, is not on the right place. Link to comment
50p Posted July 9, 2012 Share Posted July 9, 2012 I'm pretty sure your coords are all wrong. I tested the 2 sets of coords and they both work just fine (pyramid in LV and by LSPD). No problems whatsoever. Link to comment
Castillo Posted July 9, 2012 Author Share Posted July 9, 2012 The problem is resolved, thank you 50p. 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