Advertisement
Cavitt

Untitled

Mar 14th, 2012
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.53 KB | None | 0 0
  1. local config = {
  2.     method = 'all', -- single, all, near
  3.     loot = {
  4.         [3031] = 1 -- backpack index, slot type, ground, use
  5.     }
  6. }
  7.  
  8. local lastTarget = 0
  9. local targets = {}
  10. local que = {}
  11.  
  12. local function checkForNewTarget()
  13.     local target = Self.TargetID()
  14.     if (target > 0) then
  15.         local creature = Creature.GetByID(target)
  16.         if (creature:isValid()) and creature:ID() ~= Self.ID() then
  17.             if (creature:isOnScreen() and creature:isVisible() and creature:isAlive() and not creature:isPlayer()) then
  18.                 targets[creature:ID()] = creature:Position()
  19.                 lastTarget = target
  20.             end
  21.         end
  22.     end
  23. end
  24.  
  25. local function checkForDeadTargets()
  26.     for cid, pos in pairs(targets)do
  27.         local creature = Creature.GetByID(cid)
  28.         if (not creature:isValid()) then -- target is gone?
  29.             targets[cid] = nil
  30.         elseif (not creature:isAlive()) and (Self.DistanceFromPosition(pos.x, pos.y, pos.z) <= 7) then -- target died?
  31.             que[cid] = pos -- add to loot que
  32.             targets[cid] = nil -- delete from target list
  33.         end
  34.     end
  35. end
  36.  
  37. local function lootTargets()
  38.     wait(700, 900) -- incase one just died
  39.     for cid, pos in pairs(que)do
  40.         local tries = 5
  41.         local corpse = 0
  42.         repeat
  43.             corpse = Self.UseItemFromGround(pos.x, pos.y, pos.z)
  44.             wait(1500)
  45.             tries = tries - 1
  46.             print("attempts left: " .. tries)
  47.         until (corpse > 0) or (tries <= 0)
  48.         que[cid] = nil
  49.         print(corpse)
  50.     end
  51. end
  52.  
  53. while(true)do
  54.     checkForNewTarget()
  55.     checkForDeadTargets()
  56.     if (#targets == 0) or (config.method ~= 'all') then
  57.         print(#targets)
  58.         lootTargets()
  59.     end
  60.     wait(100)
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement