Advertisement
Guest User

[TFS 1.2] The Silencer Plateau - Lure Silencers By OMIN

a guest
Oct 3rd, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.54 KB | None | 0 0
  1. -- Autor Omin - https://otland.net/members/omin.56933/
  2.  
  3.  
  4. --Config
  5. local config = {
  6.     item = 22535,
  7.     storage = 34380,
  8.     position = {
  9.         Position(33637, 32516, 5), -- Top Left
  10.         Position(33664, 32537, 5), -- botton Right
  11.         Position(33650, 32527, 5)  -- Center
  12.     },
  13.     raid = {
  14.         [1] = {"silencer", math.random(8,15) },
  15.         [2] = {"silencer", math.random(11,18) },
  16.         [3] = {"silencer", math.random(8,15) },
  17.         [4] = {"Sight of Surrender", math.random(3,8) }
  18.     },
  19.     globalEventTime = 30 * 60 * 1000, -- [30min] waiting time to get started again
  20.     timeBetweenraid = 1  * 60 * 1000, -- [1min] Waiting time between each raid
  21.     cleanraid = true -- Clean zone after globalEventTime
  22. }
  23.  
  24.  
  25. local function isWalkable(position)
  26.     local tile = Tile(position)
  27.     if not tile then
  28.         return false
  29.     end
  30.  
  31.     local ground = tile:getGround()
  32.     if not ground or ground:hasProperty(CONST_PROP_BLOCKSOLID) then
  33.         return false
  34.     end
  35.  
  36.     local items = tile:getItems()
  37.     for i = 1, tile:getItemCount() do
  38.         local item = items[i]
  39.         local itemType = item:getType()
  40.         if itemType:getType() ~= ITEM_TYPE_MAGICFIELD and not itemType:isMovable() and item:hasProperty(CONST_PROP_BLOCKSOLID) then
  41.             return false
  42.         end
  43.     end
  44.     return true
  45. end
  46.  
  47. local function raids(monster)
  48.     local randX,randY,randZ = 0,0,0
  49.     randX = math.random(config.position[1].x, config.position[2].x)
  50.     randY = math.random(config.position[1].y, config.position[2].y)
  51.     randZ = math.random(config.position[1].z, config.position[2].z)
  52.     if isWalkable(Position(randX, randY, randZ)) then
  53.         Game.createMonster(monster, Position(randX, randY, randZ))
  54.     else
  55.         raids(monster)
  56.     end
  57. end
  58.  
  59. local function cleanRaid()
  60.     local mostersraid= Game.getSpectators(config.position[3], false, false, 13, 13, 11, 11)
  61.     for i = 1, #mostersraid do
  62.         if mostersraid[i]:isMonster() then
  63.             mostersraid[i]:remove()
  64.         end
  65.     end
  66. end
  67.  
  68. function onUse(cid, item, fromPosition, itemEx, toPosition)
  69.     local player = Player(cid)
  70.     local max,time,monster = 0,0,""
  71.  
  72.     if item.itemid ~= config.item then
  73.         return true
  74.     end
  75.     local spectators,hasPlayer,hasMonsters = Game.getSpectators(config.position[3], false, false, 13, 13, 11, 11),false,false
  76.     for i = 1, #spectators do
  77.         if spectators[i]:isPlayer() then
  78.             if spectators[i]:getName() == player:getName() then
  79.                 hasPlayer = true
  80.             end
  81.         elseif spectators[i]:isMonster() then
  82.             hasMonsters = true
  83.         end
  84.     end
  85.     if not hasPlayer then
  86.         player:sendCancelMessage('Use on Silencer Plateau is located in the south-eastern part of Roshamuul')
  87.         return true
  88.     end
  89.     if hasMonsters then
  90.         player:sendCancelMessage('You need kill all monsters')
  91.         return true
  92.     end
  93.  
  94.  
  95.     if Game.getStorageValue(config.storage) <= 0 then
  96.         if math.random(0,10000) < 7000 then
  97.             player:say("PRRRR...*crackle*", TALKTYPE_MONSTER_SAY)
  98.             item:remove(1)
  99.             return true
  100.         else
  101.             player:say("PRRRROOOOOAAAAAHHHH!!!", TALKTYPE_MONSTER_SAY)
  102.         end
  103.         local raid = config.raid
  104.         for y, x in pairs(raid) do
  105.             local i = 1
  106.             while i <= #x  do
  107.                 print(x[i])
  108.                 print(x[i+1])
  109.                 time = time + config.timeBetweenraid
  110.                 for j = 1, x[i+1] do
  111.                     Game.setStorageValue(config.storage,x[i+1])
  112.                     addEvent(raids,time,x[i])
  113.                 end
  114.                 i = i + 2
  115.             end
  116.         end
  117.         addEvent(Game.setStorageValue, config.globalEventTime, config.storage, 0)
  118.         if config.cleanraid then
  119.             addEvent(cleanRaid, config.globalEventTime)
  120.         end
  121.         item:remove(1)
  122.     else
  123.         player:sendCancelMessage('You need to wait')
  124.     end
  125. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement