Advertisement
jdrecarp

Annihilator Quest

Jun 20th, 2019
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.84 KB | None | 0 0
  1. local config = {
  2.     daily = "no", -- allow only one team to enter per day? (like in global)
  3.     level = 100,
  4.     storage = 30015,
  5.     room = {
  6.         {x = 33218, y = 31656, z = 13},
  7.         {x = 33225, y = 31662, z = 13}
  8.     },
  9.     stand = {
  10.         {x = 33225, y = 31671, z = 13},
  11.         {x = 33224, y = 31671, z = 13},
  12.         {x = 33223, y = 31671, z = 13},
  13.         {x = 33222, y = 31671, z = 13}
  14.     },
  15.     destination = {
  16.         {x = 33222, y = 31659, z = 13},
  17.         {x = 33221, y = 31659, z = 13},
  18.         {x = 33220, y = 31671, z = 13},
  19.         {x = 33219, y = 31671, z = 13}
  20.     },
  21.     wall = {
  22.         {x = 33225, y = 31659, z = 13}
  23.     },
  24.     rocks = {
  25.         {x = 33219, y = 31657, z = 13},
  26.         {x = 33221, y = 31657, z = 13},
  27.         {x = 33219, y = 31659, z = 13},
  28.         {x = 33220, y = 31659, z = 13},
  29.         {x = 33221, y = 31659, z = 13},
  30.         {x = 33222, y = 31659, z = 13},
  31.         {x = 33223, y = 31659, z = 13},
  32.         {x = 33224, y = 31659, z = 13},
  33.         {x = 33220, y = 31661, z = 13},
  34.         {x = 33222, y = 31661, z = 13}
  35.     },
  36.     demons = {
  37.         {x = 33219, y = 31657, z = 13},
  38.         {x = 33221, y = 31657, z = 13},
  39.         {x = 33223, y = 31659, z = 13},
  40.         {x = 33224, y = 31659, z = 13},
  41.         {x = 33220, y = 31661, z = 13},
  42.         {x = 33222, y = 31661, z = 13}
  43.     }
  44. }
  45.  
  46. local function areaCheck(area)
  47.     local monsters, players = {}, {}
  48.     for x = config.room[1].x, config.room[2].x do
  49.         for y = config.room[1].y, config.room[2].y do
  50.             local t = getThingFromPos({x=x, y=y, z=config.room[1].z, stackpos=253})
  51.             if t.uid > 0 then
  52.                 if isPlayer(t.uid) then
  53.                     table.insert(players, t.uid)
  54.                 elseif isMonster(t.uid) then
  55.                     table.insert(monsters, t.uid)
  56.                 end
  57.             end
  58.         end
  59.     end
  60.     return monsters, players
  61. end
  62.  
  63. config.daily = getBooleanFromString(config.daily)
  64. function onUse(cid, item, fromPosition, itemEx, toPosition)
  65.     if(item.itemid == 1945) then
  66.         if(config.daily) then
  67.             return doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
  68.         else
  69.             local monsters, players = areaCheck(config.room)
  70.             if #players > 0 then
  71.                 return doPlayerSendCancel(cid, "There are players inside, please be patient.")
  72.             elseif #monsters > 0 then
  73.                 for _, k in pairs(monsters) do
  74.                     doRemoveThing(k)
  75.                 end
  76.             end
  77.  
  78.             for _, v in ipairs(config.rocks) do
  79.                 doCreateItem(1285, 1, v)
  80.             end
  81.  
  82.             local closed, open = getTileItemById(config.wall[1], 5108), getTileItemById(config.wall[1], 5109)
  83.             if(closed.uid > 0) then
  84.                 doTransformItem(closed.uid, 1025)
  85.             elseif(open.uid > 0) then
  86.                 doTransformItem(open.uid, 1025)
  87.             end
  88.  
  89.             doTransformItem(item.uid, item.itemid + 1)
  90.         end
  91.         return true
  92.     end
  93.  
  94.     if(item.itemid ~= 1946) then
  95.         return true
  96.     end
  97.  
  98.     local players = {}
  99.     for _, position in ipairs(config.stand) do
  100.         local pid = getTopCreature(position).uid
  101.         if(pid == 0 or not isPlayer(pid)) then
  102.             return doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
  103.         elseif(getCreatureStorage(pid, config.storage) > 0) then
  104.             return doPlayerSendCancel(cid, "Someone has already completed this quest.")
  105.         elseif(getPlayerLevel(pid) < config.level) then
  106.             return doPlayerSendCancel(cid, "Someone is below level 100.")
  107.         end
  108.  
  109.         table.insert(players, pid)
  110.     end
  111.  
  112.     local stones = {}
  113.     for _, v in ipairs(config.rocks) do
  114.         local st = getTileItemById(v, 1285)
  115.         table.insert(stones, st)
  116.     end
  117.  
  118.     for _, st in ipairs(stones) do
  119.         doRemoveItem(st.uid, 1)
  120.     end
  121.  
  122.     local wall = getTileItemById(config.wall[1], 1025)
  123.     if(wall.uid > 0) then
  124.         doTransformItem(wall.uid, 5108)
  125.     end
  126.  
  127.     for _, pos in ipairs(config.demons) do
  128.         doCreateMonster("Demon", pos, false, false) --TFS 0.3.6 -> [ doCreateMonster("Demon", pos) ]
  129.         doSendMagicEffect(pos, CONST_ME_ENERGYAREA)
  130.     end
  131.  
  132.     for i, pid in ipairs(players) do
  133.         doSendMagicEffect(config.stand[i], CONST_ME_POFF)
  134.         doTeleportThing(pid, config.destination[i], false)
  135.         doSendMagicEffect(config.destination[i], CONST_ME_TELEPORT)
  136.     end
  137.  
  138.     doTransformItem(item.uid, item.itemid - 1)
  139.     return true
  140. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement