Forgee_XenoBot

Forgee library v 1.0.1

Aug 3rd, 2012
2,340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.85 KB | None | 0 0
  1. --[[
  2. Forgee library v 1.0.1
  3. To use these functions paste: dofile("Forgee.lua")
  4. at the top of your script.
  5.  
  6. Forum thread: http://forums.xenobot.net/showthread.php?2392-Lua-functions-by-Forgee
  7. Facebook: http://facebook.com/forgee.xenobot
  8. ]]
  9.  
  10. ----------------------------------------------------------------------------
  11. ------------------------------ Self Class ----------------------------------
  12. ----------------------------------------------------------------------------
  13.  
  14. -- getMonstersAround(4, "Frost Dragon", "Frost Dragon Hatchling")
  15. function getMonstersAround(radius, ...)
  16.     local t = {...}
  17.     local monsters = {}
  18.     for i = CREATURES_LOW, CREATURES_HIGH do
  19.         local creature = Creature.GetFromIndex(i) -- Let's find us a creature //TODO: Find a way to read additional info correctly (hp, speed, outfit etc).
  20.         if (creature:isValid()) and creature:ID() ~= Self.ID() then -- Make sure it's valid and don't count ourselves.
  21.             if (creature:isOnScreen() and creature:isVisible() and creature:isAlive()) then -- We want to see the creature.
  22.                 if not creature:isPlayer() then -- And it must not be a player, aren't we picky?
  23.                     local name = creature:Name()
  24.                     if (creature:DistanceFromSelf() <= radius) then -- Is the creature close enough to be considered?
  25.                         if (#t > 0 and table.contains(t, name)) or (#t == 0) then -- If we have a monster list, we look for our creature there.
  26.                             table.insert(monsters, creature)
  27.                         end
  28.                     end
  29.                 end
  30.             end
  31.         end
  32.     end
  33.     return monsters
  34. end
  35. --[[
  36. Example use for exori: (Note: Added exori() function to library.)
  37.  
  38. dofile("Forgee.lua")
  39. local radius = 1 -- Radius to consider
  40. local min = 2 -- Minimum number of monsters to hit.
  41. local spell = "exori" -- Spell to cast.
  42. local mana = 120 -- Minimum mana to cast spell.
  43. local monsters = {"Frost Dragon", "Frost Dragon Hatchling"}
  44. function exori()
  45.     local m = getMonstersAround(radius, unpack(monsters))
  46.     if #m >= min then
  47.         Self.Cast(spell, mana)
  48.         wait(1100, 1800)
  49.     end
  50. end
  51.  
  52. while (true) do
  53.     exori()
  54. end
  55. ]]
  56.  
  57. -- getPlayersAround(7, "DarkstaR", "Syntax")
  58. function getPlayersAround(radius, ...)
  59.     local t = {...}
  60.     local players = {}
  61.     if (radius == 0) then
  62.         radius = 8
  63.     end
  64.     for i = CREATURES_LOW, CREATURES_HIGH do
  65.         local creature = Creature.GetFromIndex(i)
  66.         if (creature:isValid()) and creature:ID() ~= Self.ID() then
  67.             if (creature:isOnScreen() and creature:isVisible() and creature:isAlive()) then
  68.                 if creature:isPlayer() then
  69.                     local name = creature:Name()
  70.                     if (creature:DistanceFromSelf() <= radius) then
  71.                         if (not table.contains(t, name)) then -- If we have a white list, we look for the player there.
  72.                             table.insert(players, creature)
  73.                         end
  74.                     end
  75.                 end
  76.             end
  77.         end
  78.     end
  79.     return players
  80. end
  81. --[[
  82. Usage:
  83. We can find all info the bot can get about a creature.
  84. If you enter names after the radius it will work as a "whitelist".
  85.  
  86. players = getPlayersAround(8, "DarkstaR", "Syntax")
  87. if #players > 0 then
  88.     for i = #players do
  89.         creature = players[i]
  90.         if creature:HealthPercent() < 60 then
  91.             ~do something
  92.         end
  93.     end
  94. end
  95. ]]
  96.  
  97. -- Same as getPlayersAround, but gets players from other floors too.
  98. -- xrayPlayersAround(6)
  99. function xrayPlayersAround(radius, ...)
  100.     local t = {...}
  101.     local players = {}
  102.     if (radius == 0) then
  103.         radius = 8
  104.     end
  105.     for i = CREATURES_LOW, CREATURES_HIGH do
  106.         local creature = Creature.GetFromIndex(i)
  107.         if (creature:isValid()) and creature:ID() ~= Self.ID() then
  108.             if creature:isVisible() and creature:isAlive() then
  109.                 if creature:isPlayer() then
  110.                     local name = creature:Name()
  111.                     local selfpos = Self.Position()
  112.                     local creaturepos = creature:Position()
  113.                     local distance = math.max(math.abs(selfpos.x - creaturepos.x), math.abs(selfpos.y - creaturepos.y))
  114.                     if (distance <= radius) then
  115.                         if not table.contains(t, name) then
  116.                             table.insert(players, creature)
  117.                         end
  118.                     end
  119.                 end
  120.             end
  121.         end
  122.     end
  123.     return players
  124. end
  125.  
  126.  
  127. function monstersAround(radius, ...) -- Count monsters around. monstersAround(5, "Frost Dragon") will count only Frost Dragons within a 5 sqm radius.
  128.     if getMonstersAround(radius, ...) then
  129.         return #getMonstersAround(radius, ...)
  130.     else
  131.         return 0
  132.     end
  133. end
  134.  
  135. function playersAround(radius, ...) -- Count players around. Names are excluded from the count.
  136.     if getPlayersAround(radius, ...) then
  137.         return #getPlayersAround(radius, ...)
  138.     else
  139.         return 0
  140.     end
  141. end
  142.  
  143.  
  144. -- Can be used for any circular aoe spell such as UE, Divine Caldera, etc.
  145. -- exori(1, 3, "exori", 120, false, "Frost Dragon", "Frost Dragon Hatchling")
  146. function exori(radius, num, spell, mana, hitPlayers, ...)
  147.     local monsters = {...}
  148.     if monstersAround(radius, unpack(monsters)) >= num then
  149.         if not hitPlayers then
  150.             if playersAround(radius + 2) == 0 then
  151.                 Self.Cast(spell, mana)
  152.             end
  153.         else
  154.             Self.Cast(spell, mana)
  155.         end
  156.         wait(1100, 1800)
  157.     end
  158.     wait(200,500)
  159. end
  160. --[[Example Script ] --
  161. dofile("Forgee.lua")
  162. local radius = 1 -- Radius to consider
  163. local num = 2 -- Minimum number of monsters to hit.
  164. local spell = "exori" -- Spell to cast.
  165. local mana = 120 -- Minimum mana to cast spell.
  166. local monsters = {"Frost Dragon", "Frost Dragon Hatchling"}
  167. local hitPlayers = false -- false will not cast the spell if there are players in the affected nearby (radius+1). true will execute regardless of other players, only recommended for Optional pvp.
  168.  
  169. while (true) do
  170.     exori(radius, num, spell, mana, hitPlayers, monsters) -- All waiting is handled by the main function.
  171. end
  172. ]]
  173.  
  174. Self.GetMonstersAround = getMonstersAround
  175. Self.MonstersAround = monstersAround
  176. Self.GetPlayersAround = getPlayersAround
  177. Self.PlayersAround = playersAround
  178. Self.Exori = exori
  179.  
  180. --[[
  181. Backpacks inside one another should be the same kind.
  182. closeBackpacks() -- optional id of cascaded backapacks
  183. ]]
  184. function closeBackpacks()
  185.     local displayName = "CloseBackpacks"
  186.     local tmpBP = Container.GetFirst()
  187.     local cascaded = {}
  188.     while tmpBP:isOpen() do
  189.         for spot = 0, tmpBP:ItemCount() do
  190.             local item = tmpBP:GetItemData(spot)
  191.             if item.id == tmpBP:ID() then
  192.                 table.insert(cascaded, tmpBP:ID())
  193.                 tmpBP = tmpBP:GetNext()
  194.             end
  195.         end
  196.         tmpBP = Container.GetFirst()
  197.         if not table.contains(cascaded, tmpBP:ID()) or tmpBP:ItemCount() == 0 then -- Backpack is main or last cascaded. Closing...
  198.             Self.UseItem(tmpBP:ID())
  199.             wait(500, 900)
  200.         end
  201.         if #cascaded > 0 then -- Any cascaded backpacks?
  202.             for i = 1, #cascaded do
  203.                 if tmpBP:ID() == cascaded[i] then -- Found cascaded backpack.
  204.                     if tmpBP:ItemCount() > 0 then -- Backpack contains atleast one item, check for another bp.
  205.                         for spot = 0, tmpBP:ItemCount() do
  206.                             local item = tmpBP:GetItemData(spot)
  207.                             if item.id == tmpBP:ID() then -- Found anoter cascade bp, opening...
  208.                                 tmpBP:UseItem(spot, true)
  209.                                 break
  210.                             end
  211.                         end
  212.                     end
  213.                 end
  214.             end
  215.         end
  216.         wait(500, 900)
  217.         tmpBP = Container.GetFirst() -- Get a new bp to check.
  218.         if tmpBP:ID() == 0 then -- No more open backpacks.
  219.             print("All backpacks were successfully closed.")
  220.         end
  221.     end
  222.     return true
  223. end
  224.  
  225. -- openBackpacks(id[, {"Parent Name", id})
  226. -- openBackpacks() -- Will open the bp in your backpack slot.
  227. -- openBackpacks({"Backpack", 9602}) -- Will open an orange bp (9602) inside a Backpack.
  228. -- openBackpacks(9602, {"Orange Backpack", 8860}) -- Will first open an orage bp inside the first container/main bp. Then opens a Brocade Backpack inside the Orange Backpack.
  229. function openBackpacks(...)
  230.     local displayName = "OpenBackpacks"
  231.     local backpacks = {...}
  232.     Self.UseItem(Self.Backpack().id) -- Open main backpack.
  233.     print("Opening main backpack.")
  234.     wait(500, 900)
  235.     main = Container.GetFirst()
  236.     if #backpacks > 0 then
  237.         for i = 1, #backpacks do
  238.             if type(backpacks[i]) == 'table' then -- Is parent container specified?
  239.                 tmpBP = Container.GetByName(backpacks[i][1])
  240.                 for spot = 0, tmpBP:ItemCount() do
  241.                     item = tmpBP:GetItemData(spot)
  242.                     if item.id == backpacks[i][2] then
  243.                         tmpBP:UseItem(spot)
  244.                         print("Opening backpack from list. " .. backpacks[i][1] .. ", " .. backpacks[i][2])
  245.                         wait(500, 800)
  246.                     end
  247.                 end
  248.             else -- If there is no parent specified we will use the main bp.
  249.                 for spot = 0, main:ItemCount() do
  250.                     item = main:GetItemData(spot)
  251.                     if item.id == backpacks[i] then
  252.                         main:UseItem(spot)
  253.                         print("Opening backpack from list, " .. backpacks[i])
  254.                         wait(500, 800)
  255.                     end
  256.                 end
  257.             end
  258.         end
  259.         local indexes = Container.GetIndexes()
  260.         for i = 1, #indexes do
  261.             if type(backpacks[i]) == "table" then
  262.                 if Container.GetFromIndex(indexes[i]):ID() ~= backpacks[i][1] then
  263.                     return false
  264.                 end
  265.             else
  266.                 if Container.GetFromIndex(indexes[i]):ID() ~= backpacks[i] then
  267.                     return false
  268.                 end
  269.             end
  270.         end
  271.         return true
  272.     end
  273. end
  274.  
  275. --[[
  276. Returns a table containing the ids of opened backpacks in order.
  277. open = getOpenBackpacks()
  278. open[1] -> first backpack
  279. open[2] -> second backpack, etc.
  280. ]]
  281. function getOpenBackpacks()
  282.     local indexes = Container.GetIndexes() -- Find index for all open backpacks
  283.     local open = {} -- Create a place to store our open backpacks
  284.     for i = 1, #indexes do -- Search all open backpacks
  285.         tmpBP = Container.GetFromIndex(indexes[i])
  286.         table.insert(open, tmpBP:ID()) -- Store this backpack
  287.     end
  288.     return open -- Return found backpacks
  289. end
  290.  
  291. --[[
  292. resetBackpacks([tries])
  293. Checks if all backpacks were reopened correctly. If not it will start over up to a maximum number of times defined by 'tries' or 3 if omitted.
  294. ]]
  295. function resetBackpacks(tries)
  296.     setWalkerEnabled(false)
  297.     local open = getOpenBackpacks() -- Save a list of open backpacks
  298.     local tries = 3 -- Give the script 3 tries to achieve a successful reset.
  299.     repeat
  300.         closeBackpacks() -- Close all backpacks
  301.         wait(600, 800) -- wait a little bit
  302.         local reopen = openBackpacks(unpack(open)) -- I store the return from openBackpacks, true if successfull, false otherwise
  303.         if tries == 0 then -- Check how many tries function has left
  304.             print("BackpackReset failed!") -- Tell the user reset has failed
  305.             return false
  306.         end
  307.         tries = tries - 1 -- One try has been spent
  308.     until reopen -- If reopen is true it means all backpacks were opened successfully and function is done
  309.     print("BackpackReset was successfull!") -- Tell user reset was successful
  310.     setWalkerEnabled(true)
  311.     return true
  312. end
  313.  
  314. Self.CloseBackpacks = closeBackpacks
  315. Self.OpenBackpacks = openBackpacks
  316. Self.ResetBackpacks = resetBackpacks
  317. Self.GetOpenBackpacks = getOpenBackpacks
  318.  
  319. --teleportWalker(32111, 33106, 7, labelName, "Teleport1" "PassedTeleport1")
  320. -- Please do not omit labelName (exactly like it is) as it is needed for the function to know which label the walker is on.
  321. function teleportWalker(x, y, z, labelName, label1, label2)
  322.     if not label1 then
  323.         label1 = "Teleport"
  324.     end
  325.     if not label2 then
  326.         label2 = "PassedTeleport"
  327.     end
  328.     if labelName == label1 then
  329.         wait(2000)
  330.         gotoLabel(label2)
  331.     elseif labelName == label2 then
  332.         delayWalker(2000)
  333.         if Self.Position().x ~= x or Self.Position().y ~= y or Self.Position().z ~= z then
  334.             gotoLabel(label1)
  335.         end
  336.     end
  337. end
  338.  
  339. Self.TelepotWalker = teleportWalker
  340.  
  341. -- openDoor(direction[, key])
  342. -- also accepts position as a table, openDoor({x, y, z}) or as normal x, y, z
  343. function openDoor(x, y, z, keyid)
  344.     if not x then -- assumes doorpos is 1sqm ahead in the direction the char is facing
  345.         pos = Self.LookPos(1)
  346.     elseif type(x) == "table" then
  347.         pos = {x = x[1], x = x[2], z = x[3]}
  348.         keyid = y
  349.     elseif x < 50 then
  350.         pos = getPositionFromDirection(Self.Position(), x, 1)
  351.         keyid = y
  352.     else
  353.         pos = {x = x, y = y, z = z}
  354.     end
  355.     local door = Map.GetTopUseItem(pos.x, pos.y, pos.z)
  356.     if table.contains(CLOSED_DOORS, door.id) then -- door is closed
  357.         local tries = 0
  358.         if keyid then
  359.             local spot = getSpotByID(keyid)
  360.             if spot then
  361.                 repeat
  362.                     if tries >= 3 then
  363.                         print("OpenDoor: Failed to open door!")
  364.                         return false
  365.                     end
  366.                     Container:UseItemWithGround(spot, pos.x, pos.y, pos.z)
  367.                     wait(500, 800)
  368.                     door = Map.GetTopUseItem(pos.x, pos.y, pos.z)
  369.                     tries = tries + 1
  370.                 until table.contains(OPENED_DOORS, door.id)
  371.             else
  372.                 print("OpenDoor: Could not find key %s.", keyid)
  373.                 return false
  374.             end
  375.         else
  376.             repeat
  377.                 if tries >= 3 then
  378.                     print("OpenDoor: Failed to open door!  Is it locked?")
  379.                     return false
  380.                 end
  381.                 Self.UseItemFromGround(pos.x, pos.y, pos.z)
  382.                 wait(500, 800)
  383.                 door = Map.GetTopUseItem(pos.x, pos.y, pos.z)
  384.                 tries = tries + 1
  385.             until table.contains(OPENED_DOORS, door.id)
  386.         end
  387.     end
  388.     return true
  389. end
  390.  
  391. -- Same usage as openDoor
  392. function closeDoor(x, y, z, keyid)
  393.     if not x then -- assumes doorpos is 1sqm ahead in the direction the char is facing
  394.         pos = Self.LookPos(1)
  395.     elseif type(x) == "table" then
  396.         pos = {x = x[1], x = x[2], z = x[3]}
  397.         keyid = y
  398.     elseif x < 50 then
  399.         pos = getPositionFromDirection(Self.Position(), x, 1)
  400.         keyid = y
  401.     else
  402.         pos = {x = x, y = y, z = z}
  403.     end
  404.     local door = Map.GetTopUseItem(pos.x, pos.y, pos.z)
  405.     if table.contains(OPENED_DOORS, door.id) then -- door is open
  406.         if keyid then
  407.             spot = getSpotByID(keyid)
  408.             repeat
  409.                 Container:UseItemWithGround(spot, pos.x, pos.y, pos.z)
  410.                 wait(500, 800)
  411.                 door = Map.GetTopUseItem(pos.x, pos.y, pos.z)
  412.             until table.contains(CLOSED_DOORS, door.id)
  413.         else
  414.             repeat
  415.                 Self.UseItemFromGround(pos.x, pos.y, pos.z)
  416.                 wait(500, 800)
  417.                 door = Map.GetTopUseItem(pos.x, pos.y, pos.z)
  418.             until table.contains(CLOSED_DOORS, door.id)
  419.         end
  420.     end
  421.     return true
  422. end
  423.  
  424. Self.BuyItemsUpTo = function(item, count)
  425.     amount = Self.ItemCount(item)
  426.     needed = math.abs(count - amount)
  427.     if type(item) ~= "number" then
  428.         item = Item.GetID(item)
  429.     end
  430.     if amount < count then
  431.         return Self.ShopBuyItem(item, needed)
  432.     else
  433.         return 1
  434.     end
  435. end
  436.  
  437. Self.SellItemsDownTo = function(item, count)
  438.     amount = Self.ItemCount(item)
  439.     sell = math.abs(amount - count)
  440.     if type(item) == "string" then
  441.         item = Item.GetID(item)
  442.     end
  443.     while amount > count do
  444.         Self.ShopSellItem(item, sell)
  445.         amount = Self.ItemCount(item)
  446.         sell = math.abs(amount - count)
  447.     end
  448.     return 1
  449. end
  450.  
  451. Self.ShopBuyItemsUpTo = Self.BuyItemsUpTo
  452. Self.ShopSellItemsDownTo = Self.SellItemsDownTo
  453.  
  454. function skinCreature(tool, range, ...)
  455.     if type(tool) == "string" then
  456.         tool = Item.GetID(tool)
  457.     end
  458.     if Self.ItemCount(tool) == 0 then
  459.         print("Could not find %s in any open container.", Item.GetName(tool))
  460.         return false
  461.     end
  462.     local bodies = {...}
  463.     for i = 1, #bodies do
  464.         local pos = Map.FindUseItem(bodies[i])
  465.         if pos ~= 0 then
  466.             if Self.DistanceFromPosition(pos.x, pos.y, pos.z) <= range then
  467.                 setWalkerEnabled(false)
  468.                 setLooterEnabled(false)
  469.                 while getDistanceBetween(Self.Position(), pos) > 1 do
  470.                     Self.UseItemWithGround(tool, pos.x, pos.y, pos.z)
  471.                     wait(1500, 2500)
  472.                 end
  473.                 setWalkerEnabled(true)
  474.                 setLooterEnabled(true)
  475.                 return 1
  476.             end
  477.         end
  478.     end
  479.     return 0
  480. end
  481.  
  482. Self.Skin = function (range, ...)
  483.     return skinCreature(5908, range, ...)
  484. end
  485.  
  486. Self.Stake = function (range, ...)
  487.     return skinCreature(5942, range, ...)
  488. end
  489.  
  490. Self.Fish = function (range, ...)
  491.     return skinCreature(3483, range, ...)
  492. end
  493.  
  494. Self.Target = function ()
  495.     return Creature.GetByID(Self.TargetID())
  496. end
  497.  
  498. Self.AutoFish = function (miss)
  499.     local function findWater()
  500.         local FISH_POS = {}
  501.         local EMPTY_POS = {}
  502.         local WATER_FISH = {4597, 4598, 4599, 4601, 4602}
  503.         local WATER_EMPTY = {4603, 4604, 4605, 4606, 4607, 4608, 4609, 4610, 4611, 4612, 4613}
  504.         for x = -7, 7 do
  505.             for y = -5, 5 do
  506.                 tile = Map.GetTopUseItem(Self.Position().x + x, Self.Position().y + y, Self.Position().z)
  507.                 if table.contains(WATER_FISH, tile.id) then
  508.                     table.insert(FISH_POS, {x = Self.Position().x + x, y = Self.Position().y + y, z = Self.Position().z})
  509.                 elseif table.contains(WATER_EMPTY, tile.id) then
  510.                     table.insert(EMPTY_POS, {x = Self.Position().x + x, y = Self.Position().y + y, z = Self.Position().z})
  511.                 end
  512.             end
  513.         end
  514.         return FISH_POS, EMPTY_POS
  515.     end
  516.    
  517.     if Self.ItemCount(3492) > 0 then
  518.         local oldCount = Self.ItemCount(3492)
  519.         if not pos or pos.x ~= Self.Position().x or pos.y ~= Self.Position().y then
  520.             fish, empty = findWater()
  521.             pos = Self.Position()
  522.         end
  523.         if miss and type(miss) ~= 'boolean' then
  524.             print("AutoFish: Invalid agument. Valid arguments are 'true' or 'false'.")
  525.             return false
  526.         end
  527.         if miss then
  528.             for i = 1, #empty do
  529.                 table.insert(fish, empty[i])
  530.             end
  531.         end
  532.         if #fish > 0 then
  533.             local spot = math.random(1, #fish)
  534.             local tile = Map.GetTopUseItem(fish[spot].x, fish[spot].y, fish[spot].z)
  535.             Self.UseItemWithGround(Item.GetID("Fishing rod"), fish[spot].x, fish[spot].y, fish[spot].z)
  536.             sleep(500)
  537.             if Self.ItemCount(3492) < oldCount then
  538.                 result = 2
  539.             else
  540.                 result = 1
  541.             end
  542.         end
  543.         wait(500, 800)
  544.     end
  545.     return result or 0
  546. end
  547.  
  548. Self.ReachDepot = function (tries)
  549.     local tries = tries or 3
  550.     setWalkerEnabled(false)
  551.     local DepotIDs = {3497, 3498, 3499, 3500}
  552.     local DepotPos = {}
  553.     for i = 1, #DepotIDs do
  554.         local dps = Map.GetUseItems(DepotIDs[i])
  555.         for j = 1, #dps do
  556.             table.insert(DepotPos, dps[j])
  557.         end
  558.     end
  559.     local function gotoDepot()
  560.         local pos = Self.Position()
  561.         print("Depots found: " .. tostring(#DepotPos))
  562.         for i = 1, #DepotPos do
  563.             location = DepotPos[i]
  564.             Self.UseItemFromGround(location.x, location.y, location.z)
  565.             wait(1000, 2000)
  566.             if Self.DistanceFromPosition(pos.x, pos.y, pos.z) >= 1 then
  567.                 wait(5000, 6000)
  568.                 if Self.DistanceFromPosition(location.x, location.y, location.z) == 1 then
  569.                     setWalkerEnabled(true)
  570.                     return true
  571.                 end
  572.             else
  573.                 print("Something is blocking the path. Trying next depot.")
  574.             end
  575.         end
  576.         return false
  577.     end
  578.    
  579.     repeat
  580.         reachedDP = gotoDepot()
  581.         if reachedDP then
  582.             return true
  583.         end
  584.         tries = tries - 1
  585.         sleep(100)
  586.         print("Attempt to reach depot was unsuccessfull. " .. tries .. " tries left.")
  587.     until tries <= 0
  588.  
  589.     return false
  590. end
  591.  
  592. ----------------------------------------------------
  593. -------------------[ Map Tools ]--------------------
  594. ----------------------------------------------------
  595.  
  596. Map.FindUseItem = function (id)
  597.     if type(id) == "string" then
  598.         id = Item.GetID(id)
  599.     end
  600.     local pos = Self.Position()
  601.     for x = -7, 7 do
  602.         for y = -5, 5 do
  603.             if Map.GetTopUseItem(pos.x + x, pos.y + y, pos.z).id == id then
  604.                 itemPos = {x = pos.x + x, y = pos.y + y, z = pos.z}
  605.                 return itemPos
  606.             end
  607.         end
  608.     end
  609.     return 0
  610. end
  611.  
  612. Map.FindMoveItem = function (id)
  613.     if type(id) == "string" then
  614.         id = Item.GetID(id)
  615.     end
  616.     local pos = Self.Position()
  617.     for x = -7, 7 do
  618.         for y = -5, 5 do
  619.             if Map.GetTopMoveItem(pos.x + x, pos.y + y, pos.z).id == id then
  620.                 itemPos = {x = pos.x + x, y = pos.y + y, z = pos.z}
  621.                 return itemPos
  622.             end
  623.         end
  624.     end
  625.     return 0
  626. end
  627.  
  628. Map.GetUseItems = function (id)
  629.     if type(id) == "string" then
  630.         id = Item.GetID(id)
  631.     end
  632.     local pos = Self.Position()
  633.     local store = {}
  634.     for x = -7, 7 do
  635.         for y = -5, 5 do
  636.             if Map.GetTopUseItem(pos.x + x, pos.y + y, pos.z).id == id then
  637.                 itemPos = {x = pos.x + x, y = pos.y + y, z = pos.z}
  638.                 table.insert(store, itemPos)
  639.             end
  640.         end
  641.     end
  642.     return store
  643. end
  644.  
  645. Map.GetMoveItems = function (id)
  646.     if type(id) == "string" then
  647.         id = Item.GetID(id)
  648.     end
  649.     local pos = Self.Position()
  650.     local store = {}
  651.     for x = -7, 7 do
  652.         for y = -5, 5 do
  653.             if Map.GetTopMoveItem(pos.x + x, pos.y + y, pos.z).id == id then
  654.                 itemPos = {x = pos.x + x, y = pos.y + y, z = pos.z}
  655.                 table.insert(store, itemPos)
  656.             end
  657.         end
  658.     end
  659.     return store
  660. end
  661.  
  662. ----------------------------------------------------
  663. -------------------[ Item Tools ]-------------------
  664. ----------------------------------------------------
  665.  
  666. -- getSpotByID(id[, container]) Container name/index is optional.
  667. function getSpotByID(id, container)
  668.     if container then
  669.         if type(container) == "string" then
  670.             cont = Container.GetByName(container)
  671.         elseif type(container) == "number" then
  672.             cont = Container.GetFromIndex(container)
  673.         end
  674.     else
  675.         cont = Container.GetFirst()
  676.     end
  677.     while cont:isOpen() do
  678.         for spot = 0, cont:ItemCount() do
  679.             item = cont:GetItemData(spot)
  680.             if item.id == id then
  681.                 return spot, cont
  682.             end
  683.         end
  684.         if container then
  685.             print("GetSpotByID: Item of id " .. id .. " could not be found in " .. cont:Name() .. ".")
  686.             return false
  687.         else
  688.             cont = cont:GetNext()
  689.         end
  690.     end
  691.     print("GetSpotByID: Item of id " .. id .. " could not be found in any open container.")
  692.     return false
  693. end
  694.  
  695. Item.GetSpotByID = getSpotByID
  696.  
  697. function getItemFromSpot(spot, container)
  698.     cont = Container.GetByName(container)
  699.     item = cont:GetItemData(spot)
  700.     return item.id
  701. end
  702.  
  703. -------------------------------------------------------------
  704. -----------------------[ War tools ]-------------------------
  705. -------------------------------------------------------------
  706. -- [NOT TESTED] --
  707. function warEnemies(range)
  708.     p = getPlayersAround(range)
  709.     enemies = {}
  710.     for i = 1, #p do
  711.         if p[i]:isWarEnemy() then
  712.             table.insert(enemies, p[i])
  713.         end
  714.     end
  715.     return #enemies
  716. end
  717.  
  718. function warAllies(range)
  719.     p = getPlayersAround(range)
  720.     allies = {}
  721.     for i = 1, #p do
  722.         if p[i]:isWarAlly() then
  723.             table.insert(allies, p[i])
  724.         end
  725.     end
  726.     return #allies
  727. end
  728.  
  729. function getWarAllies(range)
  730.     p = getPlayersAround(range)
  731.     allies = {}
  732.     for i = 1, #p do
  733.         if p[i]:isWarAlly() then
  734.             table.insert(allies, p[i])
  735.         end
  736.     end
  737.     if #allies > 0 then
  738.         return allies
  739.     else
  740.         return false
  741.     end
  742. end
  743.  
  744. function getWarEnemies(range)
  745.     p = getPlayersAround(range)
  746.     enemies = {}
  747.     for i = 1, #p do
  748.         local player = p[i]
  749.         if player:isWarEnemy() then
  750.             table.insert(enemies, player)
  751.         end
  752.     end
  753.     if #enemies > 0 then
  754.         return enemies
  755.     else
  756.         return false
  757.     end
  758. end
  759.  
  760. Self.WarEnemies = warEnemies
  761. Self.WarAllies = warAllies
  762. Self.GetWarEnemies = getWarEnemies
  763. Self.GetWarAllies = getWarAllies
Advertisement
Add Comment
Please, Sign In to add comment