Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. local status = 2
  2. local wait_time = 0
  3.  
  4. local get_available_chest = function()
  5.     local backend_items = Managers.backend:get_interface("items")
  6.     local all_items = backend_items:get_all_backend_items()
  7.    
  8.     for backend_id, item in pairs(all_items) do
  9.         local data = item.data
  10.         local RemainingUses = item.RemainingUses or 0
  11.         local item_type = data and data.item_type or ""
  12.        
  13.         if item_type == "loot_chest" and RemainingUses > 0 then
  14.             return backend_id, RemainingUses
  15.         end
  16.     end
  17.    
  18.     return nil
  19. end
  20.  
  21. local open_next_chest = function()
  22.     local backend_id, total = get_available_chest()
  23.    
  24.     if backend_id then
  25.         -- Open Chest
  26.         local backend_loot = Managers.backend:get_interface("loot")
  27.        
  28.         --backend_loot:open_loot_chest("witch_hunter", backend_id)
  29.         --backend_loot:open_loot_chest("bright_wizard", backend_id)
  30.         --backend_loot:open_loot_chest("dwarf_ranger", backend_id)
  31.         backend_loot:open_loot_chest("wood_elf", backend_id)
  32.         --backend_loot:open_loot_chest("empire_soldier", backend_id)
  33.        
  34.         -- Debug
  35.         EchoConsole("Open box " .. tostring(backend_id) .. " - " .. tostring(total))
  36.        
  37.         return true
  38.     else
  39.         Mods.exec("loadfile", "salvage_low")
  40.     end
  41.    
  42.     return false
  43. end
  44.  
  45. Mods.hook.set("", "BackendInterfaceLootPlayfab.loot_chest_rewards_request_cb", function(func, self, id, result)
  46.     func(self, id, result)
  47.    
  48.     status = 2
  49. end)
  50.  
  51. Mods.hook.set("", "MatchmakingManager.update", function(func, self, dt, t)
  52.     safe_pcall(function()
  53.         if status == 0 then
  54.             if open_next_chest() then
  55.                 status = 1
  56.             end
  57.         elseif status == 2 then
  58.             wait_time = t
  59.             status = 3
  60.         elseif status == 3 then
  61.             if wait_time + 1 < t then
  62.                 status = 0
  63.             end
  64.         end
  65.     end)
  66.    
  67.     return func(self, dt, t)
  68. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement