<?xml version="1.0" encoding="UTF-8"?>
<mod name="Fire_Storm_Event" version="3.0" author="CollocorpuseK" contact="otland.net" enabled="yes">
<config name="config_fire_storm_event">
<![CDATA[
configFireStormEvent = {
storages = {
main = '13335', -- set free storage
player = '13336', -- set free storage
joining = '13337', -- set free storage
exhaust = '13338', -- set free storage
countEvent = '13339' -- set free storage
},
position = {x=852 ,y=975,z=7}, -- position which player is teleported to
room = {
from = {x=851,y=974,z=7}, -- left top corner of event room
to = {x=873,y=996,z=7} -- right bottom corner of event room
},
rewards = {2472, 8982, 5785, 2365}, -- reward id which player can win (reward is random)
players = {
max = 50,
min = 2,
minLevel = 100
},
days = {
['Tuesday'] = {'20:00:00'},
['Thursday'] = {'18:37:00'},
['Sunday'] = {'15:00:00'}
},
fireStormDelay = 1000, -- milisecond
delayTime = 5.0, -- time in which players who joined to event are teleporting to teleport position
startEvent = 1, -- time from teleport to start event
text = 'To win and get a Rewards, stay as long as possible in the arena.'
}
fight = createConditionObject(CONDITION_INFIGHT)
setConditionParam(fight, CONDITION_PARAM_TICKS, -1)
y, x = 1, 1 -- don't change it
]]>
</config>
<lib name="lib_fire_storm_event">
<![CDATA[
function doStartFireStormEvent()
doSetStorage(configFireStormEvent.storages.joining, -1)
if configFireStormEvent.players.min <= doCountPlayersFireStormEvent() then
for _, cid in ipairs(getPlayersOnline()) do
if getCreatureStorage(cid, configFireStormEvent.storages.player) > 0 then
doCreatureSetNoMove(cid, false)
doRemoveCondition(cid, CONDITION_INFIGHT)
doTeleportThing(cid, configFireStormEvent.position)
doCreatureSetStorage(cid, configFireStormEvent.storages.player, -1)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'Get ready. Fire Storm starts in '..configFireStormEvent.startEvent..' seconds.')
end
end
addEvent(doSetStorage, configFireStormEvent.startEvent * 1000, configFireStormEvent.storages.main, 1)
addEvent(doRepeatCheckFireStorm, configFireStormEvent.startEvent * 1000 + 2000)
doBroadcastMessage('Fire Storm has started. LET\'S GO!')
else
for _, cid in ipairs(getPlayersOnline()) do
if getCreatureStorage(cid, configFireStormEvent.storages.player) > 0 then
doCreatureSetNoMove(cid, false)
doRemoveCondition(cid, CONDITION_INFIGHT)
end
end
doBroadcastMessage('Fire Storm hasn\'t started beacuse there were not enough players.')
end
end
function doRepeatCheckFireStorm()
if getStorage(configFireStormEvent.storages.main) > 0 then
local xTable, yTable, playerTable = {}, {}, {}
for x = configFireStormEvent.room.from.x, configFireStormEvent.room.to.x do
for y = configFireStormEvent.room.from.y, configFireStormEvent.room.to.y do
table.insert(xTable, x)
table.insert(yTable, y)
local n, i = getTileInfo({x=x, y=y, z=configFireStormEvent.room.to.z}).creatures, 1
if n ~= 0 then
local v = getThingfromPos({x=x, y=y, z=configFireStormEvent.room.to.z, stackpos=i}).uid
while v ~= 0 do
if isPlayer(v) then
table.insert(playerTable, v)
if n == #playerTable then
break
end
end
i = i + 1
v = getThingfromPos({x=x, y=y, z=configFireStormEvent.room.to.z, stackpos=i}).uid
end
end
end
end
if #playerTable == 1 then
local prize = math.random(#configFireStormEvent.rewards)
doCreatureAddHealth(playerTable[1], getCreatureMaxHealth(playerTable[1]) - getCreatureHealth(playerTable[1]))
doCreatureAddMana(playerTable[1], getCreatureMaxMana(playerTable[1]) - getCreatureMana(playerTable[1]))
doTeleportThing(playerTable[1], getTownTemplePosition(getPlayerTown(playerTable[1])), true)
doPlayerAddItem(playerTable[1], configFireStormEvent.rewards[prize], 1)
doPlayerSendTextMessage(playerTable[1], MESSAGE_EVENT_ADVANCE, 'You win! You have received ' .. getItemNameById(configFireStormEvent.rewards[prize]) .. ' as reward.')
doBroadcastMessage('Fire Storm has finished. The winner is ' .. getCreatureName(playerTable[1]) .. '. Congratulations.')
doSetStorage(configFireStormEvent.storages.main, -1)
db.executeQuery("INSERT INTO `events` (`event_name`, `winner_name`, `won_item`, `time_win`) VALUES (\"Fire\", \"" .. getCreatureName(playerTable[1]) .. "\", \"" .. getItemNameById(configFireStormEvent.rewards[prize]) .. "\", " .. getStorage(configFireStormEvent.storages.countEvent) ..");")
doSetStorage(configFireStormEvent.storages.countEvent, getStorage(configFireStormEvent.storages.countEvent) + 1)
x, y = 1, 1
elseif #playerTable > 1 then
for a = 1, y do
addEvent(
function()
local pos = {x=xTable[math.random(#xTable)], y=yTable[math.random(#yTable)], z=7}
for _, player in ipairs(playerTable) do
local pPos = getThingPos(player)
if pPos.x == pos.x and pPos.y == pos.y and pPos.z == pos.z then
doCreatureAddHealth(player, - getCreatureMaxHealth(player))
end
end
doSendDistanceShoot({x = pos.x - math.random(4, 6), y = pos.y - 5, z = pos.z}, pos, CONST_ANI_FIRE)
addEvent(doSendMagicEffect, 150, pos, CONST_ME_HITBYFIRE)
addEvent(doSendMagicEffect, 150, pos, CONST_ME_FIREAREA)
end,
math.random(100,1000)
)
end
if x == 5 * y then
y = y + 1
end
x = x + 1
else
doBroadcastMessage('No one survived the Fire Storm.')
doSetStorage(configFireStormEvent.storages.main, -1)
doSetStorage(configFireStormEvent.storages.countEvent, getStorage(configFireStormEvent.storages.countEvent) + 1)
x, y = 1, 1
end
addEvent(doRepeatCheckFireStorm, configFireStormEvent.fireStormDelay)
end
end
function doCountPlayersFireStormEvent()
local x = 0
for _, cid in ipairs(getPlayersOnline()) do
if getCreatureStorage(cid, configFireStormEvent.storages.player) > 0 then
x = x + 1
end
end
return x
end
function doStartCountingFireStormEvent(x)
if configFireStormEvent.delayTime-x > 0 then
doBroadcastMessage('Fire Storm will start in '..configFireStormEvent.delayTime-x..' minutes. You can join to the event by say "!fire join".')
addEvent(doStartCountingFireStormEvent, 60*1000, x+1)
end
end
]]>
</lib>