Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("loading...")
- CSide = "back"
- Alarm = "left"
- redInputSide = "bottom"
- Title = "<Jump-S v1.2.2 \"Kopro^3ch\">"
- Style = {
- BGDeflt = colors.blue,
- BGTitle = colors.cyan,
- BGWarn = colors.red
- }
- RealDistance = 0
- MinimumDistance = 1
- os.unloadAPI("rednet")
- os.unloadAPI("disk")
- os.unloadAPI("help")
- os.unloadAPI("vector")
- os.unloadAPI("paintutils")
- os.unloadAPI("gps")
- warp.setConnectionSide(CSide)
- term.setBackgroundColor(Style.BGDeflt)
- function Show(Text)
- term.write(Text)
- local xt,yt = term.getCursorPos()
- term.setCursorPos(1, yt+1)
- end
- function Clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function SaveData()
- local file = fs.open("shipdata.txt", "w")
- file.writeLine(textutils.serialize(SData))
- file.close()
- end
- function ReadData()
- local file = fs.open("shipdata.txt", "r")
- SData = textutils.unserialize(file.readAll())
- file.close()
- end
- function ShowDirection()
- if SData.Direction == warp.UP then
- Show(" Direction = Up")
- elseif SData.Direction == warp.DOWN then
- Show(" Direction = Down")
- elseif SData.Direction == warp.FRONT then
- Show(" Direction = Front")
- elseif SData.Direction == warp.BACK then
- Show(" Direction = Back")
- elseif SData.Direction == warp.LEFT then
- Show(" Direction = Left")
- elseif SData.Direction == warp.RIGHT then
- Show(" Direction = Right")
- end
- end
- function CalcRealDistance()
- if SData.Mode > 1 and SData.Distance > 0 then
- RealDistance = SData.Distance * 100
- MinimumDistance = 1
- else
- if SData.Direction == warp.UP or SData.Direction == warp.DOWN then
- MinimumDistance = SData.Up + SData.Down
- RealDistance = SData.Distance + MinimumDistance
- elseif SData.Direction == warp.FRONT or SData.Direction == warp.BACK then
- MinimumDistance = SData.Front + SData.Back
- RealDistance = SData.Distance + MinimumDistance
- elseif SData.Direction == warp.LEFT or SData.Direction == warp.RIGHT then
- MinimumDistance = SData.Left + SData.Right
- RealDistance = SData.Distance + MinimumDistance
- end
- MinimumDistance = MinimumDistance + 1
- end
- end
- function ShowInfo()
- term.setBackgroundColor(Style.BGTitle)
- Show(Title)
- term.setBackgroundColor(Style.BGDeflt)
- Show("Dimensions:")
- Show(" Front = "..SData.Front)
- Show(" Right = "..SData.Right)
- Show(" Up = "..SData.Up)
- Show(" Back = "..SData.Back)
- Show(" Left = "..SData.Left)
- Show(" Down = "..SData.Down)
- Show("Warp data:")
- Show(" Distance = "..RealDistance)
- ShowDirection()
- if SData.Mode == 1 then
- Show(" Mode = Normal")
- else
- Show(" Mode = Long")
- end
- end
- function Confirm()
- term.setBackgroundColor(Style.BGWarn)
- Show(" Are you sure? (y/n) ")
- term.setBackgroundColor(Style.BGDeflt)
- local event, keycode = os.pullEvent("key")
- if keycode == 21 then
- return true
- else
- return false
- end
- end
- function Warp()
- sleep(1)
- Clear()
- Show("Let's warp!...")
- warp.setDirection(SData.Direction)
- warp.setMode(SData.Mode)
- warp.doJump()
- sleep(2)
- Show("Warp complete.")
- term.write("(press any key)")
- os.pullEvent("key")
- end
- function SetDistance()
- Clear()
- sleep(0.2)
- term.setBackgroundColor(colors.cyan)
- Show("<==== Set distance ====>")
- term.setBackgroundColor(colors.blue)
- SData.Distance = 0
- CalcRealDistance()
- term.write("Distance (min "..MinimumDistance.."): ")
- SData.Distance = tonumber(read())
- if SData.Distance < MinimumDistance then
- SData.Distance = 1
- term.setBackgroundColor(Style.BGWarn)
- Show(" Wrong distance. Try again. ")
- term.setBackgroundColor(Style.BGDeflt)
- os.pullEvent("key")
- CalcRealDistance()
- else
- if SData.Mode == 1 then
- SData.Distance = SData.Distance - RealDistance
- end
- warp.setDistance(SData.Distance)
- CalcRealDistance()
- end
- end
- function SetDirection()
- local drun = true
- while(drun) do
- Clear()
- term.setBackgroundColor(Style.BGTitle)
- Show("<==== Set direction ====>")
- term.setBackgroundColor(Style.BGDeflt)
- ShowDirection()
- term.setBackgroundColor(Style.BGTitle)
- Show("Use directional keys")
- Show("W/S keys for Up/Down")
- Show("Enter - confirm")
- term.setBackgroundColor(Style.BGDeflt)
- local event, keycode = os.pullEvent("key")
- if keycode == 200 then
- SData.Direction = warp.FRONT
- elseif keycode == 17 then
- SData.Direction = warp.UP
- elseif keycode == 203 then
- SData.Direction = warp.LEFT
- elseif keycode == 205 then
- SData.Direction = warp.RIGHT
- elseif keycode == 208 then
- SData.Direction = warp.BACK
- elseif keycode == 31 then
- SData.Direction = warp.DOWN
- elseif keycode == 28 then
- drun = false
- end
- end
- end
- function SetDimensions()
- Clear()
- term.setBackgroundColor(Style.BGTitle)
- Show("<==== Set dimensions ====>")
- term.setBackgroundColor(Style.BGDeflt)
- term.write(" Front ("..SData.Front..") : ")
- SData.Front = tonumber(read())
- term.write(" Right ("..SData.Right..") : ")
- SData.Right = tonumber(read())
- term.write(" Up ("..SData.Up..") : ")
- SData.Up = tonumber(read())
- term.write(" Back ("..SData.Back..") : ")
- SData.Back = tonumber(read())
- term.write(" Left ("..SData.Left..") : ")
- SData.Left = tonumber(read())
- term.write(" Down ("..SData.Down..") : ")
- SData.Down = tonumber(read())
- term.write("Setting dimensions...")
- warp.setGabaritsP(SData.Front, SData.Right, SData.Up)
- warp.setGabaritsN(SData.Back, SData.Left, SData.Down)
- end
- function PulseAndWarp()
- while(true) do
- Clear()
- Show(" Waiting for red input")
- for i = 0, 10 do
- rs.setOutput(Alarm, true)
- sleep(1)
- rs.setOutput(Alarm, false)
- sleep(1)
- end
- warp.summonAllPlayers()
- end
- end
- function WaitingForRInput()
- mrun = true
- while(mrun) do
- state = rs.getInput(redInputSide)
- os.pullEvent("redstone")
- if rs.getInput(redInputSide) ~= state then
- mrun = false
- end
- end
- end
- if fs.exists("shipdata.txt") then
- ReadData()
- else
- SData = {
- Mode = 1,
- Distance = 1,
- Direction = warp.FRONT,
- Front = 1,
- Right = 1,
- Up = 1,
- Back = 1,
- Left = 1,
- Down = 1
- }
- end
- parallel.waitForAny(PulseAndWarp, WaitingForRInput)
- rs.setOutput(Alarm, false)
- CalcRealDistance()
- mrun = true
- while(mrun) do
- Clear()
- ShowInfo()
- term.setBackgroundColor(Style.BGTitle)
- Show("D - Set dimensions, M - Toggle warp mode")
- Show("S - Set distance and direction, J - Jump")
- Show("C - Summon crew, X - Exit ")
- term.setBackgroundColor(Style.BGDeflt)
- local event, keycode = os.pullEvent("key")
- if keycode == 31 then
- SetDirection()
- SetDistance()
- SaveData()
- elseif keycode == 50 then
- SData.Mode = SData.Mode + 1
- if SData.Mode > 2 then
- SData.Mode = 1
- end
- SaveData()
- CalcRealDistance()
- elseif keycode == 32 then
- SetDimensions()
- SaveData()
- elseif keycode == 36 then
- Clear()
- ShowInfo()
- if Confirm() then
- rs.setOutput(Alarm, true)
- Warp()
- parallel.waitForAny(PulseAndWarp, WaitingForRInput)
- rs.setOutput(Alarm, false)
- end
- elseif keycode == 46 then
- if Confirm() then
- warp.summonAllPlayers()
- end
- elseif keycode == 45 then
- mrun = false
- end
- end
- if SData.Mode == 3 then
- SData.Mode = 2
- SaveData()
- end
- Clear()
- print("<==== wish you good ====>")
- sleep(1)
- os.shutdown()
Advertisement
Add Comment
Please, Sign In to add comment