Cobra Posted September 9, 2013 Share Posted September 9, 2013 I make a Navigational Script with a speaker and so on, but i have a problem, i dont know how to script the calculation of the shortest way of the parts. I asked in another forum (a german mta forum) they said make the calculation with this mathematically way : http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm But i dont have an idea how to do this in lua. If there is anyone who can help me i would be very happy That is what i Have, i did about 1600 Points so about 4800 cordinates. for example: Strassenkord[1] = -2271.3115234375,2351.767578125,4.48455905914311 Strassenkord[2] = -2328.15234375,2390.9033203125,5.7813405990601 Strassenkord[3] = -2360.2001953125,2348.5302734375,4.8359375 Strassenkord[4] = -2466.0283203125,2331.1083984375,4.8359375 Strassenkord[5] = -2466.01171875,2261.11328125,4.8351097106934 Strassenkord[6] = -2556.2861328125,2291.79296875,4.8359375 Strassenkord[7] = -2563.6083984375,2331.107421875,4.8359375 Strassenkord[8] = -2615.1513671875,2331.2001953125,8.203125 Strassenkord[9] = -2604.0947265625,2434.994140625,14.7265625 Strassenkord[10] = -2543.8857421875,2395.1240234375,14.697037696838 Strassenkord[11] = -2504.6064453125,2421.0869140625,16.598020553589 Strassenkord[12] = -2394.533203125,2432.2265625,10.309600830078 http://abload.de/img/baysidem5sed.png i hope anyone can help me, thanks for any helping and sorry for me school english ^^ Link to comment
Woovie Posted September 9, 2013 Share Posted September 9, 2013 https://code.google.com/p/mtasa-resourc ... ps/gps.lua Link to comment
bandi94 Posted September 9, 2013 Share Posted September 9, 2013 There is more way of doing this , most used way is "Graph" way , like on that wiki page. The base of this algorithm is , : 1. Store each point-point distance , like point 1 - point 2 distance is 1km . point 2 - point 3 distance is 0.7 km , and so on for each - each point 2. get the start / end point . like you wanna go from point 3 to point 8. 3. Now you go through all possibilities and get the distance. From your image the posibilities of go are : 3-4-7-8 3-4-5-6-7-8 3-4-11-10-7-8 3-4-11-10-9-8 3-2-12-11-10-7-8 3-2-12-11-10-9-8 Now with the data of point-point distance witch you save'd you calculate the distnace for every posibility , after that you get the shortes one , and you have it. Link to comment
Cobra Posted March 1, 2014 Author Share Posted March 1, 2014 There is more way of doing this , most used way is "Graph" way , like on that wiki page.The base of this algorithm is , : 1. Store each point-point distance , like point 1 - point 2 distance is 1km . point 2 - point 3 distance is 0.7 km , and so on for each - each point 2. get the start / end point . like you wanna go from point 3 to point 8. 3. Now you go through all possibilities and get the distance. From your image the posibilities of go are : 3-4-7-8 3-4-5-6-7-8 3-4-11-10-7-8 3-4-11-10-9-8 3-2-12-11-10-7-8 3-2-12-11-10-9-8 Now with the data of point-point distance witch you save'd you calculate the distnace for every posibility , after that you get the shortes one , and you have it. @bandi94: Ok thanks, but my problem is not to understand how it works, but my problem is to make a script with that knowledge. https://code.google.com/p/mtasa-resources/source/browse/trunk/%5Bgameplay%5D/gps/gps.lua @Woovie: Ok thanks, but they used OOP and i dont know how that works at all, i do not understand the logic about OOP. So i do not understand the Script and how to translate it for my script Link to comment
Cobra Posted March 4, 2014 Author Share Posted March 4, 2014 no one who can help me ? Link to comment
myonlake Posted March 5, 2014 Share Posted March 5, 2014 Not sure why you'd have to translate or do anything like so, you can just download and use that resource. It has some exported functions which you can use. Link to comment
Cobra Posted March 5, 2014 Author Share Posted March 5, 2014 @myonlake: because i do not understand OOP, and that script is scripted OOP. 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