Marco Oliveira
Well-Known Member
- Joined
- Jan 5, 2019
- Messages
- 76
- Solutions
- 3
- Reaction score
- 77
- Location
- Minas Gerais - Brazil
- GitHub
- omarcopires
- Twitch
- omarcopires
Short description:
This GlobalEvent creates an event called "Animated Texts" that runs every 20 seconds. Inside the onThink function, a loop is looped through a list of effects (which is not defined in this code) and for each effect it is checked if there are players within a given area around the effect position. If there are players in the area, it checks to see if there is text and an effect associated with the effect. If the text exists, it is sent to all players within the area. If the effect exists, it is sent to the effect position. At the end of the function, true is returned to keep the event running.
animatedTextsEvent.lua
This GlobalEvent creates an event called "Animated Texts" that runs every 20 seconds. Inside the onThink function, a loop is looped through a list of effects (which is not defined in this code) and for each effect it is checked if there are players within a given area around the effect position. If there are players in the area, it checks to see if there is text and an effect associated with the effect. If the text exists, it is sent to all players within the area. If the effect exists, it is sent to the effect position. At the end of the function, true is returned to keep the event running.
animatedTextsEvent.lua
Lua:
-- Table containing the effects to be applied to the positions
local effects = {
{text = "Depots", position = Position(1000, 1000, 7), effect = CONST_ME_TUTORIALSQUARE},
}
-- Create the global event
local animatedTextsEvent = GlobalEvent("Animated Texts")
-- Function that will be called every 20 seconds by the event
function animatedTextsEvent.onThink(interval)
-- Iterate over the effects table
for i, effect in ipairs(effects) do
-- Retrieve the list of players that are watching the specific position
local spectators = Game.getSpectators(effect.position, false, true, 8, 8, 8, 8)
if #spectators > 0 then
-- If there's a text to display, make all the spectators say the text
if effect.text then
for i = 1, #spectators do
spectators[i]:say(effect.text, TALKTYPE_MONSTER_SAY, false, spectators[i], effect.position)
end
end
-- If there's an effect to display, send the effect to the position
if effect.magicEffect then
effect.position:sendMagicEffect(effect.magicEffect)
end
end
end
return true
end
-- Register the event and set the interval between onThink calls to 20 seconds
animatedTextsEvent:interval(20 * 1000)
animatedTextsEvent:register()