Ir para conteúdo

[TFS 1.1] Chuva de items


Furabio

Posts Recomendados

Tem duas versões, em forma de globalevent e talkaction

 

 

 

GLOBAL EVENT --

 

globalevents.xml

<globalevent type="startup" name="RainItems" script="rainitems.lua"/>

rainitems.lua

local config = {
   items = {{8306,1}, {2157,2}, {7735,1}, {8306,1}, {2184,1}, {9932,1}, {8306,1}, {9693,1}, {2148, 100}},
   interval = 1000, -- time between checks
   areas = {
     [1] = {
       startHour = 19,
       startMin = 15,
       waves = 10,
       interval = 10000,
       chancePerTile = 10, -- %
       maxItemsPerWave = 15,
       from = {x = 1021, y = 994, z = 7},
       to = {x = 1024, y = 998, z = 7}
     },
     [2] = {
       startHour = 18,
       startMin = 43,
       waves = 10,
       interval = 10000,
       chancePerTile = 10,
       maxItemsPerWave = 15,
       from = {x = 1026, y = 995, z = 7},
       to = {x = 1028, y = 1001, z = 7}
     }
   }
}

local executed = {}

function Position.isPathable(pos)
   local tile = Tile(pos)
   if tile == nil then
     return false
   end

   return not tile:hasFlag(TILESTATE_BLOCKSOLID)
end

function rainWave(arena)
   local from = config.areas[arena].from
   local to = config.areas[arena].to
   local items_spawned = 0
   for x = from.x, to.x do
   for y = from.y, to.y do
   for z = from.z, to.z do
     if math.random(1, 100) < config.areas[arena].chancePerTile and items_spawned < config.areas[arena].maxItemsPerWave then
       local pos = {x = x, y = y, z = z}
       if Position(pos):isPathable() then
         local item = math.random(1, #config.items)
         doCreateItem(config.items[item][1], math.random(1, config.items[item][2]), pos)
         Position(pos):sendMagicEffect(CONST_ME_MAGIC_RED)
         items_spawned = items_spawned + 1
       end
     end
   end
   end
   end
end

function startRain(arena)
   broadcastMessage("Rain item event begins!")
   for i = 1, config.areas[arena].waves do
     if i == 1 then
       rainWave(arena)
     else
       addEvent(rainWave, config.areas[arena].interval * (i - 1), arena)
     end
   end
   addEvent(broadcastMessage, config.areas[arena].interval * (config.areas[arena].waves - 1), "Rain items event ended.")
end

function checkRain()
   local hour = tonumber(os.date("%H"))
   local min = tonumber(os.date("%M"))
   if not executed[hour] then executed[hour] = {} end
   
   for i = 1, #config.areas do
     if hour == config.areas[i].startHour and min == config.areas[i].startMin then
       if not executed[hour][min] then
         startRain(i)
         addEvent(checkRain, config.interval)
         executed[hour][min] = true
       end
     end
     
     if tonumber(os.date("%H", os.time() + (30 * 60))) == config.areas[i].startHour and tonumber(os.date("%M", os.time() + (30 * 60))) == config.areas[i].startMin then
       if not executed[hour][min] then
         broadcastMessage("Rain items event will start in 30 minutes.")
         addEvent(checkRain, config.interval)
         executed[hour][min] = true
       end
     end
     
     if tonumber(os.date("%H", os.time() + (1 * 60))) == config.areas[i].startHour and tonumber(os.date("%M", os.time() + (1 * 60))) == config.areas[i].startMin then
       if not executed[hour][min] then
         broadcastMessage("Rain items event will start in 1 minute.")
         addEvent(checkRain, config.interval)
         executed[hour][min] = true
       end
     end
   end
   addEvent(checkRain, config.interval)
end

function onStartup()
   addEvent(checkRain, 100)
end

TALK ACTION --

 

talkactions.xml

<talkaction words="/rainitems" separator=" " script="rainitems_command.lua"/>

rainitems_command.lua

local config = {
   items = {{8306,1}, {2157,2}, {7735,1}, {8306,1}, {2184,1}, {9932,1}, {8306,1}, {9693,1}, {2148, 100}},
   interval = 1000, -- time between checks
   areas = {
     [1] = {
       waves = 10,
       interval = 10000,
       chancePerTile = 10, -- %
       maxItemsPerWave = 15,
       from = {x = 1021, y = 994, z = 7},
       to = {x = 1024, y = 998, z = 7}
     },
     [2] = {
       waves = 10,
       interval = 10000,
       chancePerTile = 10,
       maxItemsPerWave = 15,
       from = {x = 1026, y = 995, z = 7},
       to = {x = 1028, y = 1001, z = 7}
     }
   }
}

function Position.isPathable(pos)
   local tile = Tile(pos)
   if tile == nil then
     return false
   end

   return not tile:hasFlag(TILESTATE_BLOCKSOLID)
end

function rainWave(arena)
   local from = config.areas[arena].from
   local to = config.areas[arena].to
   local items_spawned = 0
   for x = from.x, to.x do
   for y = from.y, to.y do
   for z = from.z, to.z do
     if math.random(1, 100) < config.areas[arena].chancePerTile and items_spawned < config.areas[arena].maxItemsPerWave then
       local pos = {x = x, y = y, z = z}
       if Position(pos):isPathable() then
         local item = math.random(1, #config.items)
         doCreateItem(config.items[item][1], math.random(1, config.items[item][2]), pos)
         Position(pos):sendMagicEffect(CONST_ME_MAGIC_RED)
         items_spawned = items_spawned + 1
       end
     end
   end
   end
   end
end

function startRain(arena)
   broadcastMessage("Rain item event begins!")
   for i = 1, config.areas[arena].waves do
     if i == 1 then
       rainWave(arena)
     else
       addEvent(rainWave, config.areas[arena].interval * (i - 1), arena)
     end
   end
   addEvent(broadcastMessage, config.areas[arena].interval * (config.areas[arena].waves - 1), "Rain items event ended.")
end

function onSay(player, words, param)
   if not player:getGroup():getAccess() then return false end
   
   if tonumber(param) then
     startRain(tonumber(param))
   else
     player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, words .. " eventid")
   end
   return false
end

Créditos : zbisu

Editado por ScreaM
Link para o comentário
Compartilhar em outros sites

Muito bom script, tanto a codificação quanto o efeito. Se souber, poderia me explicar na seção de dúvidas (eu criei um tópico) sobre como funciona a função "random" utilizada no seu script?

Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...