w9s66v09c8x5o1fl3p0

Rifbot Items Stack

Jan 11th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.87 KB | None | 0 0
  1. --[[
  2.     Script Name:        Stack Items
  3.     Description:        Stacks items in container
  4.     Author:             Ascer - example
  5. ]]
  6.  
  7. local ITEMS = {3031, 3492, 3035}        -- items to stack
  8. local MAIN_DELAY = {300, 700}           -- delay moving items
  9.  
  10. -- DON'T EDIT BELOW THIS LINE
  11.  
  12. ----------------------------------------------------------------------------------------------------------------------------------------------------------
  13. --> Function:       stackItems()
  14. --> Description:    Stack items in container. Will break after action.
  15. --> Class:          None
  16. --> Params:         None
  17. -->                
  18. --> Return:         boolean true or false    
  19. ----------------------------------------------------------------------------------------------------------------------------------------------------------
  20. function stackItems()
  21.     local conts = Container.getItems()
  22.     for j = 1, table.count(conts) do
  23.         local stacks = {}
  24.         local cont = conts[j]
  25.         local items = cont.items
  26.         local index = 0
  27.         for i = 1, table.count(items) do
  28.             index = index + 1
  29.             local item = items[i]
  30.             if table.find(ITEMS, item.id) then
  31.                 if item.count < 100 then
  32.                     if not table.find(stacks, item.id) then
  33.                         table.insert(stacks, item.id)
  34.                         table.insert(stacks, {index - 1, item.id, item.count})
  35.                     else
  36.                         local remove_index = - 1
  37.                         for k = 1, table.count(stacks) do
  38.                             local stack = stacks[k]
  39.                             if type(stack) == "table" then
  40.                                 if stack[2] == item.id then
  41.                                     local space = 100 - stack[3]
  42.                                     if item.count > space then
  43.                                         return Container.MoveItemToContainer(cont.index, index - 1, cont.index, stack[1], item.id, space, 200)
  44.                                     else    
  45.                                         index = index - 1
  46.                                         return Container.MoveItemToContainer(cont.index, index, cont.index, stack[1], item.id, item.count, 200)
  47.                                     end
  48.                                 end
  49.                             end                                      
  50.                         end
  51.                         if remove_index ~= -1 then
  52.                             table.remove(stacks, remove_index)
  53.                             table.remove(stacks, remove_index)
  54.                         end
  55.                     end
  56.                 end
  57.             end                
  58.         end    
  59.     end
  60.     return false
  61. end
  62.  
  63. -- Module to run our function stackItems
  64. Module.New("Stack Items", function (mod)
  65.     stackItems()
  66.     mod:Delay(MAIN_DELAY[1], MAIN_DELAY[2]) -- delay
  67. end)
Add Comment
Please, Sign In to add comment