AVTMC

MC Mining computer

Sep 20th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.05 KB | None | 0 0
  1. local nbPuit = 0
  2. local nbPuitsTotal = 0
  3. local profondeur = 0
  4. local message = "attente"
  5.  
  6. function split(str,pat)
  7.  
  8.         local t = {}
  9.         local fpat = "(.-)" .. pat
  10.         local last_end = 1
  11.         local s, e, cap = str:find(fpat, 1)
  12.         while s do
  13.                 if s ~= 1 or cap ~= "" then
  14.                         table.insert(t,cap)
  15.                 end
  16.                 last_end = e+1
  17.                 s, e, cap = str:find(fpat, last_end)
  18.         end
  19.         if last_end <= #str then
  20.                 cap = str:sub(last_end)
  21.                 table.insert(t, cap)
  22.         end
  23.         return t
  24. end
  25.  
  26.  
  27. function affiche_etat()
  28.  
  29.         term.clear()
  30.         term.setCursorPos(4,4)
  31.         if message == "attente" then
  32.                 print("En attente de la tortue...")
  33.         elseif message == "encours" then
  34.                 print("Avancement du minage : "..nbPuit.."/"..nbPuitsTotal)
  35.                 term.setCursorPos(4,6)
  36.                
  37.                 if profondeur == 0 then
  38.                         print("Profondeur : "..profondeur)
  39.                 else
  40.                         print("Profondeur : -"..profondeur)
  41.                 end
  42.         elseif message == "retour" then
  43.                 print("Minage fini, retour au point de depart...")
  44.         elseif message == "fin" then
  45.                 print("Minage fini !")
  46.         end
  47.        
  48. end
  49.  
  50.  
  51.  
  52. rednet.open("right")
  53. affiche_etat()
  54.  
  55. while true do
  56.         event, id, text = os.pullEvent()
  57.         if event == "rednet_message" then
  58.                 local tab = split(text,":")                                         -- utilisation de la fonction "split" qui va prendre le texte reçu et va le decoupé en fonction du ":"
  59.                 if tab[1] == "etat" then message = tab[2] end                       -- cela s'appelle "mettre en série les informations"
  60.                 if tab[1] == "nbPuitsTotal" then nbPuitsTotal = tab[2] end     
  61.                 if tab[1] == "nbPuits" then nbPuit = tab[2] end
  62.                 if tab[1] == "profondeur" then profondeur = tab[2] end
  63.                 affiche_etat()
  64.         end
  65. end
Add Comment
Please, Sign In to add comment