Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local NPC_type = 2 -- type 1 = regular NPC | type 2 = hireling NPC
- local delay = 500
- local thousand_supplies = true
- local ignore_capacity = false
- local items = {
- knight = {
- {name = "Supreme Health Potion", id = 23375, Amount = 200, category = "trade", categoryHouse = "potions"},
- {name = "Ultimate Health Potion", id = 7643, Amount = 0, category = "trade", categoryHouse = "potions"},
- {name = "Great Health Potion", id = 239, Amount = 0, category = "trade", categoryHouse = "potions"},
- {name = "Strong Mana Potion", id = 237, Amount = 400, category = "trade", categoryHouse = "potions"},
- },
- paladin = {
- {name = "Diamond Arrows", id = 35901, Amount = 5800, category = "trade", categoryHouse = "distance"},
- {name = "Spectral Bolt", id = 35902, Amount = 1800, category = "trade", categoryHouse = "distance"},
- {name = "Great Mana Potion", id = 238, Amount = 0, category = "trade", categoryHouse = "potions"},
- {name = "Ultimate Spirit Potion", id = 23374, Amount = 1200, category = "trade", categoryHouse = "potions"},
- {name = "Great Spirit Potion", id = 7642, Amount = 0, category = "trade", categoryHouse = "potions"},
- {name = "Great Fireball Rune", id = 3191, Amount = 0, category = "trade", categoryHouse = "runes"},
- {name = "Avalanche Rune", id = 3161, Amount = 0, category = "trade", categoryHouse = "runes"},
- {name = "Thunderstorm Rune", id = 3202, Amount = 5600, category = "trade", categoryHouse = "runes"},
- {name = "Stone Shower Rune", id = 3175, Amount = 0, category = "trade", categoryHouse = "runes"},
- {name = "Sudden Death Rune", id = 3155, Amount = 0, category = "trade", categoryHouse = "runes"},
- },
- monk = {
- {name = "Great Mana Potion", id = 238, Amount = 0, category = "trade", categoryHouse = "potions"},
- {name = "Ultimate Spirit Potion", id = 23374, Amount = 0, category = "trade", categoryHouse = "potions"},
- {name = "Great Spirit Potion", id = 7642, Amount = 0, category = "trade", categoryHouse = "potions"},
- {name = "Great Fireball Rune", id = 3191, Amount = 0, category = "trade", categoryHouse = "runes"},
- {name = "Avalanche Rune", id = 3161, Amount = 0, category = "trade", categoryHouse = "runes"},
- {name = "Thunderstorm Rune", id = 3202, Amount = 0, category = "trade", categoryHouse = "runes"},
- {name = "Stone Shower Rune", id = 3175, Amount = 0, category = "trade", categoryHouse = "runes"},
- {name = "Sudden Death Rune", id = 3155, Amount = 0, category = "trade", categoryHouse = "runes"},
- },
- mage = {
- {name = "Ultimate Mana Potion", id = 23373, Amount = 0, category = "trade", categoryHouse = "potions"},
- {name = "Great Mana Potion", id = 238, Amount = 0, category = "trade", categoryHouse = "potions"},
- {name = "Great Fireball Rune", id = 3191, Amount = 0, category = "trade", categoryHouse = "runes"},
- {name = "Avalanche Rune", id = 3161, Amount = 0, category = "trade", categoryHouse = "runes"},
- {name = "Thunderstorm Rune", id = 3202, Amount = 0, category = "trade", categoryHouse = "runes"},
- {name = "Stone Shower Rune", id = 3175, Amount = 0, category = "trade", categoryHouse = "runes"},
- {name = "Sudden Death Rune", id = 3155, Amount = 0, category = "trade", categoryHouse = "runes"},
- }
- }
- function getItemsByVocation()
- local vocation = verifyPlayerVocation()
- if not vocation then return nil end
- if vocation == 1 then
- return items.knight
- elseif vocation == 2 then
- return items.paladin
- elseif vocation == 3 or vocation == 4 then
- return items.mage
- elseif vocation == 5 then
- return items.monk
- else
- return nil
- end
- end
- function verifyPlayerVocation()
- local playerId = Player:getId()
- if not playerId then return nil end
- local playerCreature = Creature(playerId)
- if not playerCreature then return nil end
- return playerCreature:getVocation()
- end
- function refillSupplies()
- local itemsToRefill = getItemsByVocation()
- if not itemsToRefill then
- isRefilling = false
- return
- end
- isRefilling = true
- for _, item in ipairs(itemsToRefill) do
- refillItemsAndOpenTrade(item)
- end
- isRefilling = false
- end
- function refillItemsAndOpenTrade(item)
- if item.Amount <= 0 then
- return
- end
- if NPC_type == 1 then
- Game.talk("Hi", 12)
- wait(delay)
- Game.talk(item.category, 12)
- wait(delay)
- elseif NPC_type == 2 then
- Game.talk("Hi", 12)
- wait(delay)
- Game.talk("Goods", 12)
- wait(delay)
- Game.talk(item.categoryHouse, 12)
- wait(delay)
- end
- local currentCount = Game.getItemCount(item.id)
- local toBuy = item.Amount - currentCount
- if toBuy > 0 then
- if thousand_supplies and toBuy > 1000 then
- local remaining = toBuy
- while remaining > 0 do
- local buyAmount = math.min(1000, remaining)
- local bought = Npc.buy(item.id, buyAmount, ignore_capacity, false)
- wait(delay)
- local newCount = Game.getItemCount(item.id)
- local diff = newCount - currentCount
- if diff > 0 then
- currentCount = newCount
- remaining = remaining - diff
- print("[Refiller] Bought " .. item.name .. " " .. diff)
- else
- print("[Refiller] Couldn't purchase " .. item.name .. "!")
- break
- end
- end
- else
- local boughtAmount = 0
- local lastCount = Game.getItemCount(item.id)
- while boughtAmount < toBuy do
- local buySuccess = Npc.buy(item.id, toBuy - boughtAmount, ignore_capacity, false)
- wait(delay)
- local newCount = Game.getItemCount(item.id)
- local diff = newCount - lastCount
- if diff > 0 then
- boughtAmount = boughtAmount + diff
- lastCount = newCount
- else
- break
- end
- end
- if boughtAmount > 0 then
- print("[Refiller] Bought x" .. boughtAmount .. " " .. item.name)
- else
- print("[Refiller] Couldn't purchase " .. item.name .. "!")
- end
- end
- else
- print("[Refiller] Enough " .. item.name)
- end
- end
- refillSupplies()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement