Advertisement
AdslHouba

Enclume et listing

May 3rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.12 KB | None | 0 0
  1. local liste=ahb.fichier.charge("tete/liste")
  2.  
  3. if liste==nil then liste={}
  4. else liste=textutils.unserialize(liste)
  5. end
  6.  
  7. local ecran=ahb.addPeripheral("monitor_6")
  8. local enclume=ahb.addPeripheral("enclumeCPO_0")
  9. local coffre=ahb.addPeripheral("chest_0")
  10. local w,h=ecran.pp.getSize()
  11. local curs=1
  12. local filtre=""
  13. local filtreCopie=""
  14. local affichage=true
  15. local deCompt=0
  16.  
  17. function viewer(args,player)
  18.     affichage=false
  19.     filtre=args[2]
  20.     filtreCopie=args[2]
  21.     local total=0
  22.     ecran.pp.clear()
  23.     curs=0
  24.     while not(curs==-1) do
  25.         recherche(false)
  26.         if not(curs==-1) then
  27.             total=total+1
  28.             afficheLigne()
  29.         end
  30.     end
  31.     deCompt=3+(total*1.5)
  32.     curs=0
  33.     if total>h then
  34.     --if total>1 then
  35.         affichage=true
  36.     end
  37. end
  38. function viewerAdd(args,player)
  39.     -- Envoyer une etiquette dans le coffre
  40.     coffre.pp.condenseItems()
  41.     coffre.pp.pushItem("WEST",1,1)
  42.    
  43.     -- Rename l ettiquette
  44.     enclume.pp.rename(filtreCopie)
  45.    
  46.     table.insert(liste,filtreCopie)
  47.     ahb.fichier.sauvegarde("tete/liste",textutils.serialize(liste))
  48. end
  49. function recherche(boucle)
  50.     local r=true
  51.     while r do
  52.         cursPP(boucle)
  53.         if curs==-1 then
  54.             r=false
  55.         else
  56.             if string.match(liste[curs],filtre) then
  57.                 r=false
  58.             end
  59.         end
  60.     end
  61. end
  62. function cursPP(boucle)
  63.     curs=curs+1
  64.     if liste[curs]==nil then
  65.         if boucle then
  66.             curs=1
  67.         else
  68.             curs=-1
  69.         end
  70.     end
  71. end
  72. function afficheLigne()
  73.     ecran.pp.scroll(1)
  74.     ecran.pp.setCursorPos(1,h)
  75.     ecran.pp.write(liste[curs])
  76. end
  77. function afficheLignes()
  78.     curs=1
  79.     while not(curs==-1) and curs<h do
  80.         afficheLigne()
  81.         cursPP(false)
  82.     end
  83.     if curs==-1 then
  84.         curs=0
  85.     end
  86. end
  87.  
  88. chatbox.add("viewer",viewer,"//viewer PSEUDO chercher si le pseudo existe")
  89. chatbox.add("add",viewerAdd,"//viewerAdd Creer la tete et ajoute a la liste le dernier PSEUDO chercher")
  90.  
  91. function init()
  92.     afficheLignes()
  93.     while true do
  94.         if affichage then
  95.             if filtre=="" then
  96.                 cursPP(true)
  97.             else
  98.                 recherche(true)
  99.             end
  100.             afficheLigne()
  101.         end
  102.         if deCompt>0 then
  103.             deCompt=deCompt-1
  104.             if deCompt<=0 then
  105.                 afficheLignes()
  106.                 affichage=true
  107.                 filtre=""              
  108.             end
  109.         end
  110.         os.sleep(1)
  111.     end
  112. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement