• 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!

TFS 1.x Game.sendTextOnPosition(message, position[, effect = false])

4Marsupilami

Intermediate OT User
Joined
Feb 25, 2016
Messages
64
Reaction score
120
Hey Tibian Brothers,

I don't like it when I see new scripts that duplicate the same code many times. That's why today I offer you a new feature that will say goodbye to the senseless duplication of one code.

The Game.sendTextOnPosition(message, position[, effect = false]) function has three parameters:
  • message - message content
  • position - text and effects display position
  • effect - Type of effect (optional parameter)
Thanks to this feature, many scripts will be shortened and we will eliminate multiple code duplication.

I will show this on the example of TP room text / effects:
Lua:
local effects = {
    {position = Position(1000, 1000, 7), text = false, effect = CONST_ME_GROUNDSHAKER},
    {position = Position(1000, 1002, 7), text = 'TP Room', effect = false}, -- text only
    {position = Position(1002, 1000, 7), text = 'Event', effect = CONST_ME_GROUNDSHAKER},
}

function onThink(interval)
    for i = 1, #effects do
        local settings = effects[i]
        Game.sendTextOnPosition(settings.text, settings.position, settings.effect)
    end
   
    return true
end


  • Installation:
In /data/lib/core/game.lua at the end of the file add:
Lua:
function Game.sendTextOnPosition(message, position, effect)
    local spectators = Game.getSpectators(position, false, false, 7, 7, 5, 5)

    if #spectators > 0 then
        if message then
            for i = 1, #spectators do
                spectators[i]:say(message, TALKTYPE_MONSTER_SAY, false, spectators[i], position)
            end
        end

        if effect then
            position:sendMagicEffect(effect)
        end
    end

    return true
end

Simple and effective :)
 
How can I do to script repeat " position:sendMagicEffect(effect)" for each 2 seconds for 5 times?
 
Back
Top