Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- variables
- local dColorB = colors.black
- local dColorF = colors.white
- local monitor
- local modem
- local targetMonitor
- local transporter
- local lasers = {}
- local laserCount = 0
- local mode = 0
- local x = 0
- local y = 0
- local z = 0
- local bL
- local bE
- local locked = false
- local energizeCountDown = -1
- -- setup check
- monitorIndex = 4000
- for _, name in pairs(peripheral.getNames()) do
- for n, i in string.gmatch(name, "(%w+)_(%w+)") do
- if (peripheral.getType(name) == "monitor") then
- if (tonumber(i) < monitorIndex) then
- monitorIndex = tonumber(i)
- monitor = peripheral.wrap(name)
- end
- end
- if (peripheral.getType(name) == "warpdriveTransporterCore") then
- transporter = peripheral.wrap(name)
- end
- if (peripheral.getType(name) == "warpdriveMonitor") then
- targetMonitor = peripheral.wrap(name)
- end
- if (peripheral.getType(name) == "warpdriveLaser") then
- lasers[laserCount] = peripheral.wrap(name)
- laserCount = laserCount + 1
- end
- end
- if (peripheral.getType(name) == "modem") then
- modem = peripheral.wrap(name)
- end
- end
- assert(not (targetMonitor == nil))
- assert(not (monitor == nil))
- assert(not (transporter == nil))
- assert(not (modem == nil))
- assert(laserCount > 0)
- print("Lasers detected: "..laserCount)
- monitor.setBackgroundColor(dColorB)
- monitor.setTextColor(dColorF)
- monitor.setTextScale(1)
- monitor.clear()
- targetMonitor.videoChannel(66)
- modem.open(3)
- transporter.enable(true)
- transporter.beamFrequency(60016)
- transporter.energyFactor(4)
- transporter.lock(false)
- for _, laser in pairs(lasers) do
- laser.beamFrequency(616)
- end
- -- buttons
- buttonsCount = 0
- buttons = {}
- Button =
- {
- x = 0,
- y = 0,
- h = 0,
- w = 0,
- text = "",
- colorB = colors.gray,
- colorF = colors.blue,
- onClick
- }
- function Button:new(o, x, y, h, w, text, colorB, colorF, onClick)
- o = o or {}
- o.x = x
- o.y = y
- o.h = h
- o.w = w
- o.text = text
- o.colorB = colorB
- o.colorF = colorF
- o.onClick = onClick
- buttons[buttonsCount] = o
- buttonsCount = buttonsCount + 1
- Button.draw(o)
- return o
- end
- function Button.draw(self)
- monitor.setBackgroundColor(self.colorB)
- for i = 0, self.h - 1 do
- monitor.setCursorPos(self.x, self.y +i)
- monitor.write(string.rep(" ", self.w))
- end
- monitor.setTextColor(self.colorF)
- monitor.setCursorPos(self.x + math.floor((self.w - string.len(self.text)) / 2), self.y + math.floor(self.h / 2))
- monitor.write(self.text)
- monitor.setBackgroundColor(dColorB)
- monitor.setTextColor(dColorF)
- end
- -- drawing
- monitor.setCursorPos(1, 1)
- monitor.write("Mode:")
- monitor.setCursorPos(1, 2)
- monitor.write("Target:")
- function wipe(x, y, n)
- monitor.setCursorPos(x, y)
- monitor.write(string.rep(" ", n))
- monitor.setCursorPos(x, y)
- end
- function drawInfo()
- wipe(7, 1, 25)
- if (mode == 0) then
- monitor.setTextColor(colors.green)
- monitor.write("Transportation")
- elseif (mode == 1) then
- monitor.setTextColor(colors.red)
- monitor.write("Combat")
- end
- wipe(9, 2, 25)
- monitor.setTextColor(dColorF)
- monitor.write(x.." "..y.." "..z)
- if (mode == 0) then
- acquisitionEnergy, energizeEnergy = transporter.getEnergyRequired()
- wipe(1, 4, 40)
- monitor.write("Lock Energy: "..acquisitionEnergy.."eu")
- wipe(1, 5, 40)
- monitor.write("Energizing Energy: "..energizeEnergy.."eu")
- strength = math.floor(transporter.getLockStrength() * 100)
- wipe(1, 6, 40)
- monitor.write("Lock strength: ")
- if (strength < 60) then
- monitor.setTextColor(colors.red)
- elseif (strength < 80) then
- monitor.setTextColor(colors.orange)
- else
- monitor.setTextColor(colors.green)
- end
- monitor.write(strength.."%")
- if (locked) then
- if (strength < 60) then
- bE.colorB = colors.orange
- else
- bE.colorB = colors.green
- end
- if (energizeCountDown < 0) then
- bE.text = "ENERGIZE"
- else
- bE.text = math.floor(energizeCountDown)
- end
- else
- bE.text = "ENERGIZE"
- bE.colorB = colors.red
- end
- Button.draw(bE)
- else
- i = 4
- for _, laser in pairs(lasers) do
- monitor.setTextColor(dColorF)
- wipe(1, i, 40)
- monitor.write("Laser - "..laser.laserMediumCount()..": ")
- monitor.setTextColor(colors.green)
- monitor.write(math.floor(laser.energy()).."eu")
- i = i + 1
- end
- end
- end
- function touchEvent(colum, row)
- for i = 0, buttonsCount - 1 do
- if (buttons[i].x <= colum and buttons[i].x + buttons[i].w >= colum and buttons[i].y <= row and buttons[i].y + buttons[i].h >= row) then
- buttons[i].onClick(buttons[i], true)
- end
- end
- end
- -- callBacks
- function callBack()
- if (redstone.getInput("left")) then
- if (mode == 0) then
- for i = 4, 15 do
- wipe(1, i, 40)
- end
- end
- mode = 1
- else
- if (mode == 1) then
- for i = 4, 15 do
- wipe(1, i, 40)
- end
- Button.draw(bL)
- end
- mode = 0
- end
- drawInfo()
- if (mode == 0) then
- if (energizeCountDown >= 0) then
- energizeCountDown = energizeCountDown - 1
- if (energizeCountDown == 0) then
- transporter.energize(true)
- end
- elseif (redstone.getInput("back")) then
- energizeCountDown = 5
- end
- end
- end
- function transporterCallback()
- transporter.remoteLocation(x, y, z)
- end
- function laserCallback()
- for _, laser in pairs(lasers) do
- myX, myY, myZ = laser.position()
- dx = x - myX
- dy = y - myY
- dz = z - myZ
- -- shoot (due to bug in older versions, you were required to use -dz here)
- laser.emitBeam(dx, dy, dz)
- end
- end
- function lockButton()
- locked = not locked
- if (locked) then
- bL.colorB = colors.red
- bL.text = "UNLOCK"
- else
- bL.colorB = colors.green
- bL.text = "LOCK"
- end
- transporter.lock(locked)
- Button.draw(bL)
- end
- function energizeButton()
- if (locked and energizeCountDown < 0) then
- energizeCountDown = 5
- end
- end
- -- buttons
- bL = Button:new(nil, 2, 9, 3, 10, "LOCK", colors.green, colors.white, lockButton)
- bE = Button:new(nil, 14, 9, 3, 14, "ENERGIZE", colors.green, colors.white, energizeButton)
- -- loop
- local loop = true
- local interval = 1
- local timer = os.startTimer(0)
- while loop do
- local event, arg1, arg2, arg3, arg4 = os.pullEvent()
- if (event == "timer") then
- callBack()
- os.startTimer(interval)
- end
- if (event == "key") then
- if (arg1 == keys.space) then
- break
- end
- end
- if (event == "monitor_touch") then
- touchEvent(arg2, arg3)
- end
- if (event == "modem_message") then
- target = textutils.unserialize(arg4)
- x = target.x
- y = target.y
- z = target.z
- if (mode == 0) then
- transporterCallback()
- else
- laserCallback()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement