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

broadcast Message boss summon(action)

_M4G0_

Well-Known Member
Joined
Feb 6, 2016
Messages
504
Solutions
16
Reaction score
98
I need add three warning before summon boss tfs 1.2
first warning "two minutes for boss"
after 1 minute second warning "one minute for boss"
now "the evil forces summon a creature "
Lua:
local monsters = {[26195] = "world devourer", "evergrove ancient", "world devourer"}
function onUse(player, item, fromPosition, itemEx)
    Game.broadcastMessage(0, 'test', MESSAGE_STATUS_WARNING)
    local position = player:getPosition()
    local gift = monsters[math.random(#monsters)]
    local monster = Game.createMonster(gift, position)
    monster:setReward(true)
    position:sendMagicEffect(CONST_ME_MAGIC_RED)
    item:transform(26196)
    return true
end
 
Solution
My bad tired...

Code:
local monsters = {[1] = "world devourer", [2] = "evergrove ancient", [3] = "world devourer"}

local time_between_msg_in_seconds = 60

function onUse(player, item, fromPosition, itemEx)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    item:transform(26196)
    Game.broadcastMessage('First message', MESSAGE_STATUS_WARNING)
    addEvent(msgTwo, 0, player)
    return true
end

function msgTwo(player)
    Game.broadcastMessage('Second message', MESSAGE_STATUS_WARNING)
    addEvent(finalMsg, time_between_msg_in_seconds * 1000, player)
end

function finalMsg(player)
    Game.broadcastMessage('Final Message', MESSAGE_STATUS_WARNING)
    local boss = math.random(1, 3)
    local monster =...
Er... You have some work to do... setReward isn't even a function I don't believe.

Code:
local monsters = {[1] = "world devourer", [2] = "evergrove ancient", [3] = "world devourer"}

local time_between_msg_in_seconds = 60

function onUse(player, item, fromPosition, itemEx)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    item:transform(26196)
    addEvent(msgOne, 0)
    return true
end

function msgOne()
    Game.broadcastMessage('First message', MESSAGE_STATUS_WARNING)
    addEvent(msgTwo, time_between_msg_in_seconds * 1000)
end

function msgTwo()
    Game.broadcastMessage('Second message', MESSAGE_STATUS_WARNING)
    addEvent(finalMsg, time_between_msg_in_seconds * 1000)
end

function finalMsg()
    Game.broadcastMessage('Final Message', MESSAGE_STATUS_WARNING)
    local boss = math.random(1, 3)
    local monster = Game.createMonster(monsters[boss], player:getPosition())
    --monster:setReward(true) not sure what this is--
end
 
the messages work but
Code:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/actions/scripts/custom/summon.lua:25: attempt to index local 'player' (a ni
l value)
stack traceback:
        [C]: in function '__index'
        data/actions/scripts/custom/summon.lua:25: in function <data/actions/scr
ipts/custom/summon.lua:22>
 
My bad tired...

Code:
local monsters = {[1] = "world devourer", [2] = "evergrove ancient", [3] = "world devourer"}

local time_between_msg_in_seconds = 60

function onUse(player, item, fromPosition, itemEx)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    item:transform(26196)
    Game.broadcastMessage('First message', MESSAGE_STATUS_WARNING)
    addEvent(msgTwo, 0, player)
    return true
end

function msgTwo(player)
    Game.broadcastMessage('Second message', MESSAGE_STATUS_WARNING)
    addEvent(finalMsg, time_between_msg_in_seconds * 1000, player)
end

function finalMsg(player)
    Game.broadcastMessage('Final Message', MESSAGE_STATUS_WARNING)
    local boss = math.random(1, 3)
    local monster = Game.createMonster(monsters[boss], player:getPosition())
    --monster:setReward(true) not sure what this is--
end
 
first erro
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/custom/summon.lua:onUse
LuaScriptInterface::luaAddEvent(). Argument #3 is unsafe
stack traceback:
        [C]: in function 'addEvent'
        data/actions/scripts/custom/summon.lua:9: in function <data/actions/scri
pts/custom/summon.lua:5>

again
Code:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/actions/scripts/custom/summon.lua:21: attempt to index local 'player' (a nu
mber value)
stack traceback:
        [C]: in function '__index'
        data/actions/scripts/custom/summon.lua:21: in function <data/actions/scr
ipts/custom/summon.lua:18>

but i have solved using

Lua:
local monster = Game.createMonster(monsters[boss], Position(5516, 5929, 7))

Very thanks man :D
 
My bad tired...

Code:
local monsters = {[1] = "world devourer", [2] = "evergrove ancient", [3] = "world devourer"}

local time_between_msg_in_seconds = 60

function onUse(player, item, fromPosition, itemEx)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    item:transform(26196)
    Game.broadcastMessage('First message', MESSAGE_STATUS_WARNING)
    addEvent(msgTwo, 0, player)
    return true
end

function msgTwo(player)
    Game.broadcastMessage('Second message', MESSAGE_STATUS_WARNING)
    addEvent(finalMsg, time_between_msg_in_seconds * 1000, player)
end

function finalMsg(player)
    Game.broadcastMessage('Final Message', MESSAGE_STATUS_WARNING)
    local boss = math.random(1, 3)
    local monster = Game.createMonster(monsters[boss], player:getPosition())
    --monster:setReward(true) not sure what this is--
end
please do not pass userdata through addEvent
instead use cid and reconstruct the object, and check if it was reconstructed
if the player logs out or dies and you try to execute a method on it like player:getPosition(), the server will crash since it's a dangling pointer
Lua:
local monsters = {"world devourer", "evergrove ancient", "world devourer"}

local timeBetweenMsg = 60

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    item:transform(26196)
    Game.broadcastMessage('First message', MESSAGE_STATUS_WARNING)
    addEvent(msgTwo, timeBetweenMsg * 1000, player:getId())
    return true
end

function msgTwo(cid)
    local player = Player(cid)
    if not player then
        return
    end
    Game.broadcastMessage('Second message', MESSAGE_STATUS_WARNING)
    addEvent(finalMsg, timeBetweenMsg * 1000, cid)
end

function finalMsg(cid)
    local player = Player(cid)
    if not player then
        return
    end
    Game.broadcastMessage('Final Message', MESSAGE_STATUS_WARNING)
    local monster = Game.createMonster(monsters[math.random(#monsters)], player:getPosition())
    --monster:setReward(true) not sure what this is--
end
 
Solution
Lua:
local monsters = {"world devourer", "evergrove ancient", "world devourer"}
local messages = {
    [1] = {time = 1, msg = "First Message"},
    [2] = {time = 60, msg = "Second Message"},
    [3] = {time = 60, msg = "Final Message"}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local count = 0
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    item:transform(26196)
    local playerid = player:getId()
    for i = 1, #messages do
        addEvent(function(cid, txt), messages[i].time * 1000, playerid, messages[i],
            local p = Player(cid)
            if not p then
                return false
            end
            count = count + txt.time
            Game.broadcastMessage(txt.msg, MESSAGE_STATUS_WARNING)
            if count >= 120 then
                local monster = Game.createMonster(monsters[math.random(#monsters)], p:getPosition())
                monster:setReward(true)
            end
        )
    end
    return true
end
 
Last edited:
Back
Top