SHOW:
|
|
- or go back to the newest paste.
| 1 | local sensor = peripheral.wrap "back" | |
| 2 | ||
| 3 | - | local ws, err = http.websocket("wss://osmarks.tk/wsthing/lasers/admin", {
|
| 3 | + | |
| 4 | - | authorization = "Key " .. key |
| 4 | + | |
| 5 | - | }) |
| 5 | + | local ws, err = http.websocket("wss://osmarks.tk/wsthing/lasers/admin", { authorization = "Key " .. key })
|
| 6 | ||
| 7 | if err then | |
| 8 | error(err) | |
| 9 | else | |
| 10 | - | print "Connected" |
| 10 | + | print "Connected to THOR satellite backend." |
| 11 | end | |
| 12 | ||
| 13 | - | function readWS() |
| 13 | + | local hist = {}
|
| 14 | - | while true do |
| 14 | + | while true do |
| 15 | - | local txt = ws.receive() |
| 15 | + | write "Target: " |
| 16 | - | print(txt) |
| 16 | + | local target = read(nil, hist) |
| 17 | table.insert(hist, target) | |
| 18 | print "Scanning..." | |
| 19 | local es = sensor.sense() | |
| 20 | - | function send(msg) |
| 20 | + | for _, e in pairs(es) do |
| 21 | - | local ok = ws.send(msg) |
| 21 | + | if e.name:match(target) or e.displayName:match(target) then |
| 22 | local x, y, z = gps.locate() | |
| 23 | local tx, ty, tz = e.x + x, e.y + y - 1, e.z + z | |
| 24 | - | function writeWS() |
| 24 | + | ws.send(("fire_position %f %f %f 5"):format(tx, ty, tz))
|
| 25 | - | local hist = {}
|
| 25 | + | print(e.name, e.displayName, tx, ty, tz) |
| 26 | - | while true do |
| 26 | + | end |
| 27 | - | write "|> " |
| 27 | + | |
| 28 | - | local input = read(nil, hist) |
| 28 | + | end |