phone-app-mine.lua
46 lines · 1000 B
PHONE APP MINE--
Copy & run
wget https://perlytiara.github.io/turtles.tips/raw/programs/perlytiara/BigBaemingGamers/phone/phone-app-mine.lua
| 1 | --PHONE APP MINE-- |
| 2 | |
| 3 | local SERVER_PORT = 420 |
| 4 | local PHONE_PORT = 69 |
| 5 | |
| 6 | local modem = peripheral.wrap("back") |
| 7 | ---@class Vec3 |
| 8 | ---@field x number |
| 9 | ---@field y number |
| 10 | ---@field z number |
| 11 | local size = { x = 0, y = 0, z = 0 } |
| 12 | |
| 13 | if (#arg == 3) then |
| 14 | local ax = tonumber(arg[1]) |
| 15 | local ay = tonumber(arg[2]) |
| 16 | local az = tonumber(arg[3]) |
| 17 | if not (ax and ay and az) then |
| 18 | print("Invalid size numbers") |
| 19 | os.exit() |
| 20 | end |
| 21 | ---@cast ax number |
| 22 | ---@cast ay number |
| 23 | ---@cast az number |
| 24 | size.x = ax |
| 25 | size.y = ay |
| 26 | size.z = az |
| 27 | else |
| 28 | print("NO SIZE GIVEN") |
| 29 | os.exit(1) |
| 30 | end |
| 31 | |
| 32 | local gx, gy, gz = gps.locate() |
| 33 | if not gx then |
| 34 | print("GPS not available") |
| 35 | os.exit(1) |
| 36 | end |
| 37 | local target = vector.new(gx, gy, gz) |
| 38 | local payloadMessage = string.format("%d %d %d %d %d %d %d", |
| 39 | target.x, target.y - 1, target.z, |
| 40 | size.x, size.y, size.z, |
| 41 | 1 |
| 42 | ) |
| 43 | |
| 44 | print(string.format("Targetting %d %d %d", target.x, target.y, target.z)) |
| 45 | modem.transmit(SERVER_PORT, PHONE_PORT, payloadMessage) |
| 46 |