• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

GlobalEvent [TFS 1.1] Rain Items

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
3,323
Solutions
26
Reaction score
2,690
Location
Poland
rain items event rewritten to 1.1
two versions available: globalevent and command

globalevents.xml
XML:
<globalevent type="startup" name="RainItems" script="rainitems.lua"/>

rainitems.lua
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

talkactions.xml
XML:
<talkaction words="/rainitems" separator=" " script="rainitems_command.lua"/>
rainitems_command.lua
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
 
Last edited by a moderator:
This is just an event that makes items randomly drop on the map for players?
 
spawns items randomly on selected area and time
it's free items globalevent popular on 0.4 high exp servers

I don't know why someone would want it in his server, but it was on my request list and was pretty popular so I rewrote it.
 
Keep up the great work Zbizu, Everything you're doing is Amazing and will be used for sure on many servers.

Kind Regards,
Eldin.
 
it spawns items inside houses, also its configured:
from = {x = 956, y = 929, z = 7},
to = {x = 1068, y = 1018, z = 7}
but items appear only at range:
x = 956 y = 929 z = 7
x = 959 y = 1018 z = 7
 
Back
Top