SHARE
TWEET

Untitled

a guest Apr 20th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. FollowThisPerson = "Ale Zadyma" -- Character name to follow.
  2.  
  3. FloorChangers = {
  4.     Ladders   = {Up   = {1948, 1968},
  5.                  Down = {432, 412, 469, 369, 7478, 7182, 482, 8658,}},
  6.    
  7.     Holes     = {Up   = {},
  8.                  Down = {293, 294, 595, 385, 594}},
  9.    
  10.     RopeSpots = {Up   = {386},
  11.                  Down = {}},
  12.    
  13.     Stairs    = {Up   = {1958, 7548, 7544, 1952, 1950, 1947, 7542, 1978, 8657, 1977, 1956, 1957, 1954},
  14.                  Down = {414, 413, 437, 7731, 469, 413, 434, 469, 438, 600, 4826, 8932, 6129}},
  15.     Sewers    = {Up   = {},
  16.                  Down = {435, }},
  17. }
  18.  
  19. ---------------------------------------------
  20. -------------- END OF CONFIG ----------------
  21. ---------------------------------------------
  22.  
  23. local target = FollowThisPerson
  24. local lastKnownPosition
  25.  
  26. local function goLastKnown()
  27.     while Self.DistanceFromPosition(lastKnownPosition.x, lastKnownPosition.y, lastKnownPosition.z) > 1 do
  28.         Self.UseItemFromGround(lastKnownPosition.x, lastKnownPosition.y, lastKnownPosition.z)
  29.         wait(200, 700)
  30.     end
  31. end
  32.  
  33. local function handleUse(pos)
  34.     goLastKnown()
  35.     local lastZ = Self.Position().z
  36.     while Self.Position().z == lastZ do
  37.         Self.UseItemFromGround(pos.x, pos.y, pos.z)
  38.         wait(400, 800)
  39.     end
  40. end
  41.  
  42. local function handleStep(pos)
  43.     goLastKnown()
  44.     local lastZ = Self.Position().z
  45.     while Self.Position().z == lastZ do
  46.         Self.Step(Map.GetDirectionTo(Self.Position(), pos))
  47.         wait(400, 800)
  48.     end
  49. end
  50.  
  51. local function getRope()
  52.     local ropes = {"rope", "elvenhair rope"}
  53.     for _, rope in ipairs(ropes) do
  54.         if Self.ItemCount(rope) > 0 then return Item.GetID(rope) end
  55.     end
  56. end
  57.  
  58. local function handleRope(pos)
  59.     goLastKnown()
  60.     local lastZ = Self.Position().z
  61.     while Self.Position().z == lastZ do
  62.         Self.UseItemWithGround(getRope(), pos.x, pos.y, pos.z)
  63.         wait(400, 800)
  64.     end
  65. end
  66.  
  67. local floorChangeSelector = {
  68.     Ladders = {Up=handleUse, Down=handleStep},
  69.     Holes = {Up=handleStep, Down=handleStep},
  70.     RopeSpots = {Up=handleRope, Down=handleRope},
  71.     Stairs = {Up=handleStep, Down=handleStep},
  72.     Sewers = {Up=handleUse, Down=handleUse},
  73. }
  74.  
  75.  
  76. Module("Follow-Renew", function(f)
  77.     local c = Creature(target)
  78.     if c and not c:isFollowed() then
  79.         c:Follow()
  80.     end
  81. end)
  82.  
  83. local function checkTargetPos()
  84.     local c = Creature(target)
  85.     if c:Position().z == Self.Position().z then
  86.         lastKnownPosition = c:Position()
  87.     end
  88. end
  89.  
  90. local function distance(pos1, pos2)
  91.     local pos2 = pos2 or lastKnownPosition or Self.Position()
  92.     return math.abs(pos1.x-pos2.x) + math.abs(pos1.y-pos2.y)
  93. end
  94.  
  95. local function executeClosest(possibilities)
  96.     local closest
  97.     local closestDistance = 99999
  98.     for _, data in ipairs(possibilities) do
  99.         local dist = distance(data.pos)
  100.         if dist < closestDistance then
  101.             closest = data
  102.             closestDistance = dist
  103.         end
  104.     end
  105.     if closest then closest.changer(closest.pos) end
  106. end
  107.  
  108. local function handleFloorChange()
  109.     local c = Creature(target)
  110.     local range = 2
  111.     local p = Self.Position()
  112.     local possibleChangers = {}
  113.     for _, dir in ipairs({"Down", "Up"}) do
  114.         for changer, data in pairs(FloorChangers) do
  115.             for x = -range, range do
  116.                 for y = -range, range do
  117.                     if table.find(data[dir], Map.GetTopUseItem(p.x+x, p.y+y, p.z).id) then
  118.                         table.insert(possibleChangers, {changer=floorChangeSelector[changer][dir], pos={x=p.x+x, y=p.y+y, z=p.z}})
  119.                     end
  120.                 end
  121.             end
  122.         end
  123.     end
  124.     executeClosest(possibleChangers)
  125. end
  126.  
  127. local function targetMissing()
  128.     for name, c in Creature.iPlayers() do
  129.         if name == target then
  130.             return c:Position().z ~= Self.Position().z
  131.         end
  132.     end
  133.     return true
  134. end
  135.  
  136. Module("Handle floor change", function(f)
  137.     checkTargetPos()
  138.     if targetMissing() and lastKnownPosition then
  139.         handleFloorChange()
  140.     end
  141. end)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top