abc123mewot

PIM Inventory clearer - Computercraft

Dec 14th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.57 KB | None | 0 0
  1. --PIM struct: Holds data about a PIM
  2. --Key: General direction of which side the PIM is located
  3. --Value: Must be the following: north, south, east, west, up or down
  4. local pimStructs = {
  5.   pim0 = {
  6.     loc = "left",
  7.     depot = "down"
  8.   },
  9.   pim1 = {
  10.     loc = "back",
  11.     depot = "down"
  12.   }
  13. }
  14. local pims = {}
  15. local ignoreWhitelist = false --Disables the whitelist entirely when true
  16. local whitelist = { --People who won't get pwned
  17.   "abc123mewot",
  18.   "person", "person",
  19.   "person",
  20.   "person", "person"}
  21.  
  22. for k, v in pairs(pimStructs) do
  23.   v.pim = peripheral.wrap(v.loc)
  24.   if v.pim == nil then
  25.     v.enabled = false
  26.     print("Pim id: " .. k .. " is not connected!")
  27.   else v.enabled = true end
  28. end
  29.  
  30. --Returns true if the inventory on the PIM is of an enemy origin (Not "pim" or not on the whitelist)
  31. function isNameEnemy(name)
  32.   if name == "pim" then return false end --Meaning nobody is on the PIM
  33.   if ignoreWhitelist then return true end
  34.   for k, v in pairs(whitelist) do
  35.     if name == v then return false end
  36.   end
  37.   return true
  38. end
  39. --Clears the inventory of the person on the PIM
  40. function clearInventory(pimStruct)
  41.   local c = pimStruct.pim.getInventorySize()
  42.   for i=1, c do pimStruct.pim.pushItem(pimStruct.depot, i) end
  43. end
  44.  
  45. while true do
  46.   for k, v in pairs(pimStructs) do
  47.     if v.enabled then
  48.       local pim = v.pim
  49.       local invName = pim.getInventoryName()
  50.       if isNameEnemy(invName) then
  51.         print("Clearing inventory of " .. invName)
  52.         clearInventory(v)
  53.         os.exit()
  54.       end
  55.     end
  56.   end
  57.   sleep(0.1)
  58. end
Add Comment
Please, Sign In to add comment