Advertisement
martintokio

Hireling CaveBot Dialog

Mar 25th, 2025
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.18 KB | None | 0 0
  1. --Hireling Dialog
  2. local hireling_settings = {
  3.     dish_name = "Carrion Casserole",
  4.     dish_id = 29414,
  5.     dish_amount = 10,
  6.     hireling_name = "Otclient"
  7. }
  8.  
  9. function get_item_count(itemId)
  10.     local count = 0
  11.     for _, container in pairs(g_game.getContainers()) do
  12.         for _, item in ipairs(container:getItems()) do
  13.             if item:getId() == itemId then
  14.                 count = count + item:getCount()
  15.             end
  16.         end
  17.     end
  18.     for _, item in ipairs(player:getItems()) do
  19.         if item:getId() == itemId then
  20.             count = count + item:getCount()
  21.         end
  22.     end
  23.     return count
  24. end
  25.  
  26. function check_purse()
  27.     local purse = getContainerByName("Store inbox")
  28.     if not purse then
  29.         g_game.use(g_game.getLocalPlayer():getInventoryItem(InventorySlotPurse))
  30.     end
  31. end
  32.  
  33. function talk_hireling()
  34.     check_purse()
  35.     CaveBot.Conversation("hi")
  36.     schedule(200, function()
  37.         check_purse()
  38.         CaveBot.Conversation("food")
  39.     end)
  40.     schedule(400, function()
  41.         check_purse()
  42.         CaveBot.Conversation("specific")
  43.     end)
  44.     schedule(800, function()
  45.         check_purse()
  46.         CaveBot.Conversation(hireling_settings.dish_name)
  47.     end)
  48.     schedule(1200, function()
  49.         check_purse()
  50.         CaveBot.Conversation("yes")
  51.     end)
  52.    
  53.     schedule(1600, function()
  54.         if get_item_count(hireling_settings.dish_id) < hireling_settings.dish_amount then
  55.             check_and_buy()
  56.         end
  57.     end)
  58. end
  59.  
  60. function buy_hireling()
  61.     local hireling = getCreatureByName(hireling_settings.hireling_name)
  62.     if not hireling then
  63.         print("CaveBot[follow]: can't find hireling to follow")
  64.         return
  65.     end
  66.  
  67.     local hireling_pos = hireling:getPosition()
  68.     local pos = pos()
  69.  
  70.     if getDistanceBetween(hireling_pos, pos) > 2 then
  71.         follow(hireling)
  72.         schedule(1000, buy_hireling)
  73.         return
  74.     end
  75.  
  76.     g_game.cancelFollow()
  77.     talk_hireling()
  78. end
  79.  
  80. function check_and_buy()
  81.     check_purse()
  82.  
  83.     if get_item_count(hireling_settings.dish_id) < hireling_settings.dish_amount then
  84.         buy_hireling()
  85.     end
  86. end
  87.  
  88. check_and_buy()
  89. return true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement