kLeeNex24

jump

Apr 13th, 2013
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.19 KB | None | 0 0
  1. print("loading...")
  2.  
  3. CSide = "back"
  4.  
  5. Alarm = "left"
  6.  
  7. redInputSide = "bottom"
  8.  
  9. Title = "<Jump-S v1.2.2 \"Kopro^3ch\">"
  10.  
  11. Style = {
  12.  BGDeflt = colors.blue,
  13.  BGTitle = colors.cyan,
  14.  BGWarn = colors.red
  15. }
  16.  
  17. RealDistance = 0
  18. MinimumDistance = 1
  19.  
  20. os.unloadAPI("rednet")
  21. os.unloadAPI("disk")
  22. os.unloadAPI("help")
  23. os.unloadAPI("vector")
  24. os.unloadAPI("paintutils")
  25. os.unloadAPI("gps")
  26.  
  27. warp.setConnectionSide(CSide)
  28.  
  29. term.setBackgroundColor(Style.BGDeflt)
  30.  
  31. function Show(Text)
  32.  term.write(Text)
  33.  local xt,yt = term.getCursorPos()
  34.  term.setCursorPos(1, yt+1)
  35. end
  36.  
  37. function Clear()
  38.  term.clear()
  39.  term.setCursorPos(1,1)
  40. end
  41.  
  42. function SaveData()
  43.  local file = fs.open("shipdata.txt", "w")
  44.  file.writeLine(textutils.serialize(SData))
  45.  file.close()
  46. end
  47.  
  48. function ReadData()
  49.  local file = fs.open("shipdata.txt", "r")
  50.  SData = textutils.unserialize(file.readAll())
  51.  file.close()
  52. end
  53.  
  54. function ShowDirection()
  55.  if SData.Direction == warp.UP then
  56.   Show(" Direction  = Up")
  57.  elseif SData.Direction == warp.DOWN then
  58.   Show(" Direction  = Down")
  59.  elseif SData.Direction == warp.FRONT then
  60.   Show(" Direction  = Front")
  61.  elseif SData.Direction == warp.BACK then
  62.   Show(" Direction  = Back")
  63.  elseif SData.Direction == warp.LEFT then
  64.   Show(" Direction  = Left")
  65.  elseif SData.Direction == warp.RIGHT then
  66.   Show(" Direction  = Right")
  67.  end
  68. end
  69.  
  70. function CalcRealDistance()
  71.  if SData.Mode > 1 and SData.Distance > 0 then
  72.   RealDistance = SData.Distance * 100
  73.   MinimumDistance = 1
  74.  else
  75.   if SData.Direction == warp.UP or SData.Direction == warp.DOWN then
  76.    MinimumDistance = SData.Up + SData.Down
  77.    RealDistance = SData.Distance + MinimumDistance
  78.   elseif SData.Direction == warp.FRONT or SData.Direction == warp.BACK then
  79.    MinimumDistance = SData.Front + SData.Back
  80.    RealDistance = SData.Distance + MinimumDistance
  81.   elseif SData.Direction == warp.LEFT or SData.Direction == warp.RIGHT then
  82.    MinimumDistance = SData.Left + SData.Right
  83.    RealDistance = SData.Distance + MinimumDistance
  84.   end
  85.   MinimumDistance = MinimumDistance + 1
  86.  end
  87. end
  88.  
  89. function ShowInfo()
  90.  term.setBackgroundColor(Style.BGTitle)
  91.  Show(Title)
  92.  term.setBackgroundColor(Style.BGDeflt)
  93.  Show("Dimensions:")
  94.  Show(" Front      = "..SData.Front)
  95.  Show(" Right      = "..SData.Right)
  96.  Show(" Up         = "..SData.Up)
  97.  Show(" Back       = "..SData.Back)
  98.  Show(" Left       = "..SData.Left)
  99.  Show(" Down       = "..SData.Down)
  100.  Show("Warp data:")
  101.  Show(" Distance   = "..RealDistance)
  102.  ShowDirection()
  103.  if SData.Mode == 1 then
  104.   Show(" Mode       = Normal")
  105.  else
  106.   Show(" Mode       = Long")
  107.  end
  108. end
  109.  
  110. function Confirm()
  111.  term.setBackgroundColor(Style.BGWarn)
  112.  Show("    Are you sure? (y/n)    ")
  113.  term.setBackgroundColor(Style.BGDeflt)
  114.  local event, keycode = os.pullEvent("key")
  115.  if keycode == 21 then
  116.   return true
  117.  else
  118.   return false
  119.  end
  120. end
  121.  
  122. function Warp()
  123.  sleep(1)
  124.  Clear()
  125.  Show("Let's warp!...")
  126.  warp.setDirection(SData.Direction)
  127.  
  128.  warp.setMode(SData.Mode)
  129.  
  130.  warp.doJump()
  131.  sleep(2)
  132.  Show("Warp complete.")
  133.  term.write("(press any key)")
  134.  os.pullEvent("key")
  135. end
  136.  
  137. function SetDistance()
  138.  Clear()
  139.  sleep(0.2)
  140.  term.setBackgroundColor(colors.cyan)
  141.  Show("<====  Set distance  ====>")
  142.  term.setBackgroundColor(colors.blue)
  143.  SData.Distance = 0
  144.  CalcRealDistance()
  145.  term.write("Distance (min "..MinimumDistance.."): ")
  146.  SData.Distance = tonumber(read())
  147.  if SData.Distance < MinimumDistance then
  148.   SData.Distance = 1
  149.   term.setBackgroundColor(Style.BGWarn)
  150.   Show(" Wrong distance. Try again. ")
  151.   term.setBackgroundColor(Style.BGDeflt)
  152.   os.pullEvent("key")
  153.   CalcRealDistance()
  154.  else
  155.   if SData.Mode == 1 then
  156.    SData.Distance = SData.Distance - RealDistance
  157.   end
  158.   warp.setDistance(SData.Distance)
  159.   CalcRealDistance()
  160.  end
  161. end
  162.  
  163. function SetDirection()
  164.  local drun = true
  165.  while(drun) do
  166.   Clear()
  167.   term.setBackgroundColor(Style.BGTitle)
  168.   Show("<==== Set direction ====>")
  169.   term.setBackgroundColor(Style.BGDeflt)
  170.   ShowDirection()
  171.   term.setBackgroundColor(Style.BGTitle)
  172.   Show("Use directional keys")
  173.   Show("W/S keys for Up/Down")
  174.   Show("Enter - confirm")
  175.   term.setBackgroundColor(Style.BGDeflt)
  176.   local event, keycode = os.pullEvent("key")
  177.   if keycode == 200 then
  178.    SData.Direction = warp.FRONT
  179.   elseif keycode == 17 then
  180.    SData.Direction = warp.UP
  181.   elseif keycode == 203 then
  182.    SData.Direction = warp.LEFT
  183.   elseif keycode == 205 then
  184.    SData.Direction = warp.RIGHT
  185.   elseif keycode == 208 then
  186.    SData.Direction = warp.BACK
  187.   elseif keycode == 31 then
  188.    SData.Direction = warp.DOWN
  189.   elseif keycode == 28 then
  190.    drun = false
  191.   end
  192.  end
  193. end
  194.  
  195. function SetDimensions()
  196.  Clear()
  197.  term.setBackgroundColor(Style.BGTitle)
  198.  Show("<==== Set dimensions ====>")
  199.  term.setBackgroundColor(Style.BGDeflt)
  200.  term.write(" Front ("..SData.Front..") : ")
  201.  SData.Front = tonumber(read())
  202.  term.write(" Right ("..SData.Right..") : ")
  203.  SData.Right = tonumber(read())
  204.  term.write(" Up    ("..SData.Up..") : ")
  205.  SData.Up = tonumber(read())
  206.  term.write(" Back  ("..SData.Back..") : ")
  207.  SData.Back = tonumber(read())
  208.  term.write(" Left  ("..SData.Left..") : ")
  209.  SData.Left = tonumber(read())
  210.  term.write(" Down  ("..SData.Down..") : ")
  211.  SData.Down = tonumber(read())
  212.  term.write("Setting dimensions...")
  213.  warp.setGabaritsP(SData.Front, SData.Right, SData.Up)
  214.  warp.setGabaritsN(SData.Back, SData.Left, SData.Down)
  215. end
  216.  
  217. function PulseAndWarp()
  218.  while(true) do
  219.   Clear()
  220.   Show(" Waiting for red input")
  221.   for i = 0, 10 do
  222.    rs.setOutput(Alarm, true)
  223.    sleep(1)
  224.    rs.setOutput(Alarm, false)
  225.    sleep(1)
  226.   end
  227.   warp.summonAllPlayers()
  228.  end
  229. end
  230.  
  231. function WaitingForRInput()
  232.  mrun = true
  233.  while(mrun) do
  234.   state = rs.getInput(redInputSide)
  235.   os.pullEvent("redstone")
  236.   if rs.getInput(redInputSide) ~= state then
  237.    mrun = false
  238.   end
  239.  end
  240. end
  241.  
  242. if fs.exists("shipdata.txt") then
  243.  ReadData()
  244. else
  245.  SData = {
  246.   Mode = 1,
  247.   Distance = 1,
  248.   Direction = warp.FRONT,
  249.   Front = 1,
  250.   Right = 1,
  251.   Up = 1,
  252.   Back = 1,
  253.   Left = 1,
  254.   Down = 1
  255.  }
  256. end
  257.  
  258. parallel.waitForAny(PulseAndWarp, WaitingForRInput)
  259. rs.setOutput(Alarm, false)
  260. CalcRealDistance()
  261.  
  262. mrun = true
  263. while(mrun) do
  264.  Clear()
  265.  ShowInfo()
  266.  term.setBackgroundColor(Style.BGTitle)
  267.  Show("D - Set dimensions, M - Toggle warp mode")
  268.  Show("S - Set distance and direction, J - Jump")
  269.  Show("C - Summon crew, X - Exit               ")
  270.  term.setBackgroundColor(Style.BGDeflt)
  271.  local event, keycode = os.pullEvent("key")
  272.  if keycode == 31 then
  273.   SetDirection()
  274.   SetDistance()
  275.   SaveData()
  276.  elseif keycode == 50 then
  277.   SData.Mode = SData.Mode + 1
  278.   if SData.Mode > 2 then
  279.    SData.Mode = 1
  280.   end
  281.   SaveData()
  282.   CalcRealDistance()
  283.  elseif keycode == 32 then
  284.   SetDimensions()
  285.   SaveData()
  286.  elseif keycode == 36 then
  287.   Clear()
  288.   ShowInfo()
  289.   if Confirm() then
  290.    rs.setOutput(Alarm, true)
  291.    Warp()
  292.    parallel.waitForAny(PulseAndWarp, WaitingForRInput)
  293.    rs.setOutput(Alarm, false)
  294.   end
  295.  elseif keycode == 46 then
  296.   if Confirm() then
  297.    warp.summonAllPlayers()
  298.   end
  299.  elseif keycode == 45 then
  300.   mrun = false
  301.  end
  302. end
  303.  
  304. if SData.Mode == 3 then
  305.  SData.Mode = 2
  306.  SaveData()
  307. end
  308.  
  309. Clear()
  310. print("<==== wish you good ====>")
  311. sleep(1)
  312. os.shutdown()
Advertisement
Add Comment
Please, Sign In to add comment