Advertisement
meuced

minage turtle V1.8 - affichage rednet

May 4th, 2013
866
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.81 KB | None | 0 0
  1. local nbPuit = 0
  2. local nbPuitsTotal = 0
  3. local profondeur = 0
  4. local idChannel = 123
  5. local message = "attente"
  6.  
  7. function split(str,pat)
  8.  
  9.         local t = {}
  10.         local fpat = "(.-)" .. pat
  11.         local last_end = 1
  12.         local s, e, cap = str:find(fpat, 1)
  13.         while s do
  14.                 if s ~= 1 or cap ~= "" then
  15.                         table.insert(t,cap)
  16.                 end
  17.                 last_end = e+1
  18.                 s, e, cap = str:find(fpat, last_end)
  19.         end
  20.         if last_end <= #str then
  21.                 cap = str:sub(last_end)
  22.                 table.insert(t, cap)
  23.         end
  24.         return t
  25. end
  26.  
  27.  
  28. function affiche_etat()
  29.  
  30.         term.clear()
  31.         term.setCursorPos(4,4)
  32.         if message == "attente" then
  33.                 print("En attente de la tortue...")
  34.         elseif message == "encours" then
  35.                 print("Avancement du minage : "..nbPuit.."/"..nbPuitsTotal)
  36.                 term.setCursorPos(4,6)
  37.                
  38.                 if profondeur == 0 then
  39.                         print("Profondeur : "..profondeur)
  40.                 else
  41.                         print("Profondeur : -"..profondeur)
  42.                 end
  43.         elseif message == "vidage" then
  44.                 term.setCursorPos(4,8)
  45.                 print("La tortue revient vider son inventaire")
  46.         elseif message == "charbon" then
  47.                 term.setCursorPos(4,8)
  48.                 print("La tortue revient prendre du charbon")
  49.         elseif message == "retour" then
  50.                 print("Minage fini, retour au point de depart...")
  51.         elseif message == "fin" then
  52.                 print("Minage fini !")
  53.         end
  54.        
  55. end
  56.  
  57.  
  58.  
  59. --rednet.open("right")
  60. modem = peripheral.wrap("left")
  61. affiche_etat()
  62.  
  63. while true do
  64.         modem.open(idChannel)
  65.         event, modemSide, senderChannel, replyChannel, text, senderDistance = os.pullEvent("modem_message")
  66.         local tab = split(text,":")
  67.         if tab[1] == "etat" then message = tab[2] end
  68.         if tab[1] == "nbPuitsTotal" then nbPuitsTotal = tab[2] end
  69.         if tab[1] == "nbPuits" then nbPuit = tab[2] end
  70.         if tab[1] == "profondeur" then profondeur = tab[2] end
  71.         affiche_etat()
  72.         modem.close(idChannel)
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement