Advertisement
Sanwi

RailCalculator

Aug 3rd, 2014
1,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. $${
  2.  
  3. // This script calculates the best possible rail layout between two coordinates.
  4. // When you execute the script, it will prompt for an input. Enter the destination coordinates in this format: x y z
  5. // Your current coordinates will be used as the starting coordinates. It will tell you in your chat log how far to go straight, and
  6. // how far to go angled. Place the first rail next to you (not under you) in the target direction.
  7.  
  8. PROMPT(&inputcoords,"$$?","Enter end coordinates as: x y z",true,"%&inputcoords%")
  9.  
  10. replace(&inputcoords,"\"","");
  11.  
  12. #endcoords[] = split(" ","%&inputcoords%");
  13.  
  14. // Get xdif
  15. if(%#endcoords[0]% >= %XPOS%);
  16. #xdif = (%#endcoords[0]%) - (%XPOS%)
  17. &xaxis = "east"
  18. elseif(%#endcoords[0]% < %XPOS%);
  19. #xdif = (%XPOS%) - (%#endcoords[0]%)
  20. &xaxis = "west"
  21. endif;
  22.  
  23. // Get ydif
  24. if(%#endcoords[1]% >= %YPOS%);
  25. #ydif = (%#endcoords[1]%) - (%YPOS%)
  26. elseif(%#endcoords[1]% < %YPOS%);
  27. #ydif = (%YPOS%) - (%#endcoords[1]%)
  28. endif;
  29.  
  30. // Get zdif
  31. if(%#endcoords[2]% >= %ZPOS%);
  32. #zdif = (%#endcoords[2]%) - (%ZPOS%)
  33. &zaxis = "south"
  34. elseif(%#endcoords[2]% < %ZPOS%);
  35. #zdif = (%ZPOS%) - (%#endcoords[2]%)
  36. &zaxis = "north"
  37. endif;
  38.  
  39. // Calculate angle/straight
  40. if(%#xdif% > %#zdif%);
  41. #straight = (%#xdif%) - (%#zdif%)
  42.  
  43. // Calculate start of angled
  44. if(%&xaxis% = "west");
  45. #xstop = (%XPOS%) - (%#straight%)
  46. elseif(%&xaxis% = "east");
  47. #xstop = (%XPOS%) + (%#straight%)
  48. endif;
  49.  
  50. log("%#straight% %&xaxis%, %#zdif% %&zaxis%%&xaxis%. Turn at %#xstop%");
  51. elseif(%#zdif% > %#xdif%);
  52. #straight = (%#zdif%) - (%#xdif%)
  53.  
  54. // Calculate start of angled
  55. if(%&zaxis% = "south");
  56. #zstop = (%ZPOS%) + (%#straight%)
  57. elseif(%&zaxis% = "north");
  58. #zstop = (%ZPOS%) - (%#straight%)
  59. endif;
  60.  
  61. log("%#straight% %&zaxis%, %#xdif% %&zaxis%%&xaxis%. Turn at %#zstop%");
  62. endif;
  63.  
  64. stop();
  65. }$$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement