Advertisement
martintokio

Untitled

Jun 22nd, 2025
287
0
20 hours
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.17 KB | None | 0 0
  1. local NPC_type = 2 -- type 1 = regular NPC | type 2 = hireling NPC
  2. local delay = 500
  3. local thousand_supplies = true
  4. local ignore_capacity = false
  5.  
  6. local items = {
  7.     knight = {
  8.         {name = "Supreme Health Potion", id = 23375, Amount = 200, category = "trade", categoryHouse = "potions"},
  9.         {name = "Ultimate Health Potion", id = 7643, Amount = 0, category = "trade", categoryHouse = "potions"},
  10.         {name = "Great Health Potion", id = 239, Amount = 0, category = "trade", categoryHouse = "potions"},
  11.         {name = "Strong Mana Potion", id = 237, Amount = 400, category = "trade", categoryHouse = "potions"},
  12.     },
  13.     paladin = {
  14.         {name = "Diamond Arrows", id = 35901, Amount = 5800, category = "trade", categoryHouse = "distance"},
  15.         {name = "Spectral Bolt", id = 35902, Amount = 1800, category = "trade", categoryHouse = "distance"},
  16.         {name = "Great Mana Potion", id = 238, Amount = 0, category = "trade", categoryHouse = "potions"},
  17.         {name = "Ultimate Spirit Potion", id = 23374, Amount = 1200, category = "trade", categoryHouse = "potions"},
  18.         {name = "Great Spirit Potion", id = 7642, Amount = 0, category = "trade", categoryHouse = "potions"},
  19.         {name = "Great Fireball Rune", id = 3191, Amount = 0, category = "trade", categoryHouse = "runes"},
  20.         {name = "Avalanche Rune", id = 3161, Amount = 0, category = "trade", categoryHouse = "runes"},
  21.         {name = "Thunderstorm Rune", id = 3202, Amount = 5600, category = "trade", categoryHouse = "runes"},
  22.         {name = "Stone Shower Rune", id = 3175, Amount = 0, category = "trade", categoryHouse = "runes"},
  23.         {name = "Sudden Death Rune", id = 3155, Amount = 0, category = "trade", categoryHouse = "runes"},
  24.     },
  25.     monk = {
  26.         {name = "Great Mana Potion", id = 238, Amount = 0, category = "trade", categoryHouse = "potions"},
  27.         {name = "Ultimate Spirit Potion", id = 23374, Amount = 0, category = "trade", categoryHouse = "potions"},
  28.         {name = "Great Spirit Potion", id = 7642, Amount = 0, category = "trade", categoryHouse = "potions"},
  29.         {name = "Great Fireball Rune", id = 3191, Amount = 0, category = "trade", categoryHouse = "runes"},
  30.         {name = "Avalanche Rune", id = 3161, Amount = 0, category = "trade", categoryHouse = "runes"},
  31.         {name = "Thunderstorm Rune", id = 3202, Amount = 0, category = "trade", categoryHouse = "runes"},
  32.         {name = "Stone Shower Rune", id = 3175, Amount = 0, category = "trade", categoryHouse = "runes"},
  33.         {name = "Sudden Death Rune", id = 3155, Amount = 0, category = "trade", categoryHouse = "runes"},
  34.     },
  35.     mage = {
  36.         {name = "Ultimate Mana Potion", id = 23373, Amount = 0, category = "trade", categoryHouse = "potions"},
  37.         {name = "Great Mana Potion", id = 238, Amount = 0, category = "trade", categoryHouse = "potions"},
  38.         {name = "Great Fireball Rune", id = 3191, Amount = 0, category = "trade", categoryHouse = "runes"},
  39.         {name = "Avalanche Rune", id = 3161, Amount = 0, category = "trade", categoryHouse = "runes"},
  40.         {name = "Thunderstorm Rune", id = 3202, Amount = 0, category = "trade", categoryHouse = "runes"},
  41.         {name = "Stone Shower Rune", id = 3175, Amount = 0, category = "trade", categoryHouse = "runes"},
  42.         {name = "Sudden Death Rune", id = 3155, Amount = 0, category = "trade", categoryHouse = "runes"},
  43.     }
  44.   }
  45.  
  46. function getItemsByVocation()
  47.   local vocation = verifyPlayerVocation()
  48.   if not vocation then return nil end
  49.  
  50.   if vocation == 1 then
  51.     return items.knight
  52.   elseif vocation == 2 then
  53.     return items.paladin
  54.   elseif vocation == 3 or vocation == 4 then
  55.     return items.mage
  56.   elseif vocation == 5 then
  57.     return items.monk
  58.   else
  59.     return nil
  60.   end
  61. end
  62.  
  63. function verifyPlayerVocation()
  64.   local playerId = Player:getId()
  65.   if not playerId then return nil end
  66.   local playerCreature = Creature(playerId)
  67.   if not playerCreature then return nil end
  68.   return playerCreature:getVocation()
  69. end
  70.  
  71. function refillSupplies()
  72.   local itemsToRefill = getItemsByVocation()
  73.   if not itemsToRefill then
  74.     isRefilling = false
  75.     return
  76.   end
  77.  
  78.   isRefilling = true
  79.  
  80.   for _, item in ipairs(itemsToRefill) do
  81.     refillItemsAndOpenTrade(item)
  82.   end
  83.  
  84.   isRefilling = false
  85. end
  86.  
  87. function refillItemsAndOpenTrade(item)
  88.   if item.Amount <= 0 then
  89.     return
  90.   end
  91.  
  92.   if NPC_type == 1 then
  93.     Game.talk("Hi", 12)
  94.     wait(delay)
  95.     Game.talk(item.category, 12)
  96.     wait(delay)
  97.   elseif NPC_type == 2 then
  98.     Game.talk("Hi", 12)
  99.     wait(delay)
  100.     Game.talk("Goods", 12)
  101.     wait(delay)
  102.     Game.talk(item.categoryHouse, 12)
  103.     wait(delay)
  104.   end
  105.  
  106.   local currentCount = Game.getItemCount(item.id)
  107.   local toBuy = item.Amount - currentCount
  108.  
  109.   if toBuy > 0 then
  110.     if thousand_supplies and toBuy > 1000 then
  111.       local remaining = toBuy
  112.       while remaining > 0 do
  113.         local buyAmount = math.min(1000, remaining)
  114.         local bought = Npc.buy(item.id, buyAmount, ignore_capacity, false)
  115.         wait(delay)
  116.         local newCount = Game.getItemCount(item.id)
  117.         local diff = newCount - currentCount
  118.         if diff > 0 then
  119.           currentCount = newCount
  120.           remaining = remaining - diff
  121.           print("[Refiller] Bought " .. item.name .. " " .. diff)
  122.         else
  123.           print("[Refiller] Couldn't purchase " .. item.name .. "!")
  124.           break
  125.         end
  126.       end
  127.     else
  128.       local boughtAmount = 0
  129.       local lastCount = Game.getItemCount(item.id)
  130.       while boughtAmount < toBuy do
  131.         local buySuccess = Npc.buy(item.id, toBuy - boughtAmount, ignore_capacity, false)
  132.         wait(delay)
  133.         local newCount = Game.getItemCount(item.id)
  134.         local diff = newCount - lastCount
  135.         if diff > 0 then
  136.           boughtAmount = boughtAmount + diff
  137.           lastCount = newCount
  138.         else
  139.           break
  140.         end
  141.       end
  142.      
  143.       if boughtAmount > 0 then
  144.         print("[Refiller] Bought x" .. boughtAmount .. " " .. item.name)
  145.       else
  146.         print("[Refiller] Couldn't purchase " .. item.name .. "!")
  147.       end
  148.     end
  149.   else
  150.     print("[Refiller] Enough " .. item.name)
  151.   end
  152. end
  153.  
  154. refillSupplies()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement