Advertisement
Axow01

phone_computer_craft

Aug 16th, 2023 (edited)
1,272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.72 KB | None | 0 0
  1. rednet.open("back")
  2. -- // test
  3. local args = {...}
  4.  
  5. -- local os = args[1]
  6. -- local shell = args[2]
  7. -- local multishell = args[3]
  8. local updateFiles = args[1]
  9.  
  10. local base_pos = {x = 40, y = 0, z = 594}
  11. local base_bigger_pos = {x = 220, y = 0, z = 774}
  12. local dispacher_id = 24
  13. local pastebin_code = "ELZBcwXG"
  14. local path = shell.getRunningProgram()
  15. local version = "3.3"
  16.  
  17. function update()
  18.     term.clear()
  19.     term.setTextColor(colors.green)
  20.     term.setCursorPos(2, 2)
  21.     term.write("Update Required.. PLS wait")
  22.     os.sleep(2)
  23.     term.clear()
  24.     os.run({shell = shell, exit = os.exit, multishell = multishell}, "rom/programs/http/pastebin.lua", "get", pastebin_code, "ctech_os_tmp.lua")
  25.     multishell.launch({shell = shell, exit = os.exit, multishell = multishell}, "ctech_os_tmp.lua", true)
  26.     exit()
  27. end
  28.  
  29. function get_dispacher_order()
  30.     local sender_id, message, distance_protocol = rednet.receive("ctech_phones_440", 1)
  31.     if (sender_id == dispacher_id) then
  32.         local cmd = {cmd = message[1], active = message[2]}
  33.         if (cmd.cmd == "continue") then return end
  34.         if (cmd.cmd == "shutdown" and cmd.active) then os.shutdown() end
  35.         if (cmd.cmd == "update" and cmd.active) then update() end
  36.     end
  37. end
  38.  
  39. if (updateFiles == true) then
  40.     print("updating files...")
  41.     shell.run("rm", "ctech_os.lua")
  42.     shell.run("rename", "ctech_os_tmp.lua", "ctech_os.lua")
  43.     os.reboot()
  44. end
  45.  
  46. while (true) do
  47.     local pos = {gps.locate()}
  48.     if (pos[1] ~= nil and pos[2] ~= nil and pos[3] ~= nil) then
  49.         if (pos[1] >= base_pos.x and pos[1] <= base_bigger_pos.x and pos[3] >= base_pos.z and pos[3] <= base_bigger_pos.z) then
  50.             rednet.send(dispacher_id, {pos, version}, "lights_dispacher_440")
  51.             get_dispacher_order()
  52.         else os.sleep(2) end
  53.     end
  54.     os.sleep(0.1)
  55. end
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement