Advertisement
AdslHouba

Cleanner d'interface (ComputerCraft)

Nov 9th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.64 KB | None | 0 0
  1. -- Vider à distance les items de votre inventaire dans ae2 sauf ce configuré via le chat
  2. -- VIDEO
  3. -- Periphereal++ et Computercraft 1.7.10
  4.  
  5. -- Player Interface (peripheral++)
  6. local pi=peripheral.find("playerInterfacePPP")
  7. local chat=peripheral.find("chatBox")
  8. -- config coffre
  9. pi.setOutputSide("NORTH")
  10. local joueur='Adsl_Houba'
  11. local moi=pi.getPlayerInv(joueur)
  12.  
  13. -- creation du fichier items pour la premeir utilisation
  14. if not(fs.exists("items")) then
  15.   fl=fs.open("items","w")
  16.   fl.write("{}")
  17.   fl.close()
  18. end
  19.  
  20. local items={}
  21. -- Function chargement d'une variable sauvegarder
  22. function charge(nom)
  23.     file=fs.open(nom,"r")
  24.     tmp=file.readAll()
  25.     file.close()
  26.     return tmp
  27. end
  28. -- Function de sauvegarde d'une variable
  29. function memoW(nom,info)
  30.     file=fs.open(nom,"w")
  31.     file.write(info)
  32.     file.close()
  33. end
  34. items=textutils.unserialize(charge("items"))
  35.  
  36. -- attente reponse joueur
  37. function attente()
  38.     while true do
  39.         local event, player, arg = os.pullEvent("command") -- \
  40.         if player==joueur then
  41.             if arg[1]=='o' or  arg[1]=='n' or arg[1]=='q' then
  42.                 return arg[1]
  43.             end
  44.         end
  45.     end
  46. end
  47. function viderItem(iName)
  48.     for iv=0, 39 do
  49.         local info=moi.getStackInSlot(iv)
  50.         if type(info)=='table' then
  51.             if iName==info.name then
  52.                 moi.retrieveFromSlot(iv,info.amount)
  53.             end
  54.         end
  55.     end
  56. end
  57.  
  58.  
  59.  
  60. function vide()
  61.     local listeQuestion={}
  62.     local texteQuestion=''
  63.     for iv=0, 39 do
  64.         local info=moi.getStackInSlot(iv)
  65.         if type(info)=='table' then
  66.             if type(items[info.name])=='nil' then
  67.                 if type(listeQuestion[info.name])=='nil' then
  68.                     listeQuestion[info.name]=info.displayName
  69.                     if texteQuestion=='' then
  70.                         texteQuestion=info.displayName
  71.                     else
  72.                         texteQuestion=texteQuestion..', '..info.displayName
  73.                     end
  74.                 end
  75.             elseif items[info.name]==false then
  76.                 moi.retrieveFromSlot(iv,info.amount)
  77.             end
  78.         end
  79.     end
  80.     if texteQuestion~='' then
  81.         chat.tell(joueur,'Garder tous '..texteQuestion.. ' ? \o => OUI \n => NON \q => Question',9999,false,'Inventaire')
  82.         texte=attente()
  83.         if texte=='o' then
  84.             table.foreach(listeQuestion, function(iName,data)
  85.                 items[iName]=true              
  86.             end)               
  87.             memoW("items",textutils.serialize(items))
  88.         elseif texte=='n' then
  89.             table.foreach(listeQuestion, function(iName,data)
  90.                 items[iName]=false
  91.                 viderItem(iName)
  92.             end)               
  93.             memoW("items",textutils.serialize(items))
  94.         else
  95.             table.foreach(listeQuestion, function(iName,nomFr)
  96.                 chat.tell(joueur,'Garder '..nomFr.. ' ? \o => OUI \n => NON',9999,false,'Inventaire')
  97.                 texte=attente()    
  98.                 if texte=='o' then
  99.                     items[iName]=true
  100.                 else
  101.                     items[iName]=false
  102.                     viderItem(iName)
  103.                 end
  104.                 memoW("items",textutils.serialize(items))
  105.             end)
  106.         end
  107.        
  108.     end -- texteQuestion~=''
  109.     chat.tell(joueur,'Inventaire clean',9999,false,'Inventaire')
  110. end
  111.  
  112. while true do
  113.     local event, player, arg = os.pullEvent("command") -- \vide
  114.     if player==joueur then
  115.         if arg[1]=='vide' then
  116.             vide()
  117.         elseif arg[1]=='ckoi' then
  118.             local info=moi.getStackInSlot(arg[2]-1)
  119.             chat.tell(joueur,arg[2]..' c\'est '..info.displayName.. ' CODE : '..info.name..' CONFIG : '..tostring(items[info.name]),9999,false,'Inventaire')
  120.         elseif arg[1]=='garder' then
  121.             local info=moi.getStackInSlot(arg[2]-1)
  122.             chat.tell(joueur,'On garde '..info.displayName..' '..arg[2],9999,false,'Inventaire')
  123.             items[info.name]=true
  124.             memoW("items",textutils.serialize(items))
  125.         elseif arg[1]=='ranger' then
  126.             local info=moi.getStackInSlot(arg[2]-1)
  127.             chat.tell(joueur,'On raznge '..info.displayName..' '..arg[2],9999,false,'Inventaire')
  128.             items[info.name]=false
  129.             memoW("items",textutils.serialize(items))
  130.         end
  131.     end
  132. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement