Advertisement
GravityCube

CLKeysAPI

Jan 1st, 2019
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.41 KB | None | 0 0
  1. --------------------------------------------------------
  2. -->                    Variables                     <--
  3. --------------------------------------------------------
  4. local me = peripheral.find("appeng_me_tilecable") or peripheral.find("appeng_me_tilecolorlesscable")
  5. local pim = peripheral.find("pim")
  6. local chest = peripheral.find("crystal")
  7.  
  8. local chestDirection = "north"
  9. --------------------------------------------------------
  10. -->                    Key Names                     <--
  11. --------------------------------------------------------
  12. key_name = nil
  13. l_key_name = nil
  14. if fs.exists("/keyNames") then
  15.     local list = gcapi.getListFromFile("/keyNames")
  16.     key_name = list["key_name"]
  17.     l_key_name = list["l_key_name"]
  18. else
  19.     error("You need to create the keyNames file with the names of the keys ({key_name and l_key_name})")
  20. end
  21.  
  22. --------------------------------------------------------
  23. -->                     ME STUFF                     <--
  24. --------------------------------------------------------
  25. function emptyChest()
  26.     me.insertItem(1,64,"up")
  27. end
  28. --------------------------------------------------------
  29. -->                     PIM STUFF                    <--
  30. --------------------------------------------------------
  31. function checkPlayer(player)
  32.     if getCurrentPlayer() == player then
  33.         return true
  34.     end
  35.     return false
  36. end
  37.  
  38. function getCurrentPlayer()
  39.     return pim.getInventoryName()
  40. end
  41.  
  42. function getKeysInInventory()
  43.     --CONFIG
  44.     local id = 131
  45.     local name = key_name
  46.    
  47.     qty = 0
  48.    
  49.     for i,item in pairs(pim.getAllStacks()) do
  50.         if item["id"] == id then
  51.             if item["name"] == name then
  52.                 if item["ench"] ~= nil then
  53.                     if item["ench"][1] ~= nil and item["ench"][1] == "Unbreaking I" then
  54.                         qty = qty + item["qty"]
  55.                     end
  56.                 end
  57.             end
  58.         end
  59.     end
  60.    
  61.     return qty
  62. end
  63.  
  64. function moveKeysToSystem(amount)
  65.    
  66.     --CONFIG
  67.     local id = 131
  68.     local name = key_name
  69.    
  70.     if amount > getKeysInInventory() then
  71.         return false, "Not enough keys"
  72.     end
  73.    
  74.     local qty = 0
  75.    
  76.     for i,item in pairs(pim.getAllStacks()) do
  77.         if item["id"] == id then
  78.             if item["name"] == name then
  79.                 if item["ench"] ~= nil then
  80.                     if item["ench"][1] ~= nil and item["ench"][1] == "Unbreaking I" then
  81.                         local keysMoved = pim.pushItemIntoSlot(chestDirection, i, amount, 1)
  82.                         qty = qty + keysMoved
  83.                         amount = amount - keysMoved
  84.                     end
  85.                 end
  86.             end
  87.         end
  88.     end
  89.     emptyChest()
  90.     return qty
  91. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement