Marco Oliveira
Well-Known Member
- Joined
- Jan 5, 2019
- Messages
- 76
- Solutions
- 3
- Reaction score
- 78
- Location
- Minas Gerais - Brazil
- GitHub
- omarcopires
- Twitch
- omarcopires
Hello, I am reviewing my server scripts and I came across the following event:
The following code is initiated by an action: addEvent(ativarGeyser, 1 * 60)
It apparently works well, so my question is about the way in which it was written, is it safe to use it in this way or could it be improved?
The event is similar to the video attached below.
Lua:
local geyser = {
[1] = Position(33132, 31917, 15),
[2] = Position(33135, 31919, 15),
[3] = Position(33135, 31923, 15),
[4] = Position(33128, 31922, 15),
[5] = Position(33128, 31918, 15),
[6] = Position(33124, 31920, 15),
[7] = Position(33124, 31925, 15),
[8] = Position(33131, 31927, 15),
[9] = Position(33135, 31926, 15),
[10] = Position(33128, 31929, 15),
[11] = Position(33133, 31930, 15),
[12] = Position(33127, 31933, 15)
}
local function ativarGeyser(player)
local frompos = Position(33119, 31913, 15)
local topos = Position(33142, 31936, 15)
if(isPlayerInArea(frompos, topos)) then
addEvent(function()
local rand = math.random(1,12)
local geyserPos = Position(geyser[rand])
local checar1 = Tile(Position(geyserPos)):getItemById(28868)
if checar1 then
addEvent(function()
local player1 = Game.getPlayers()[1]
Game.createItem(28869, 1, geyserPos)
player1:say("SPLASH!", TALKTYPE_MONSTER_SAY, false, false, geyserPos)
addEvent(function()
local checar2 = Tile(Position(geyserPos)):getItemById(28869)
if checar2 then
checar2:remove()
end
end, 9 * 1000)
end, 5 * 1000)
elseif checar2 then
return false
end
addEvent(function()
ativarGeyser() end, 1 * 1000)
end, 8 * 1000)
end
return true
end
The following code is initiated by an action: addEvent(ativarGeyser, 1 * 60)
It apparently works well, so my question is about the way in which it was written, is it safe to use it in this way or could it be improved?
The event is similar to the video attached below.