• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

TFS 1.X+ Send a message when the boss comes down

abdala ragab

Banned User
Joined
Aug 18, 2018
Messages
308
Solutions
10
Reaction score
272
iam use tfs 1.2 How can there be a message when the boss comes down to let people know?
I prepared this boss from rme And he comes down every hour after his killers
I only have 4 boss How do I do this I want a text for this and an explanation
Thanks in advance
 
Solution
iam use tfs 1.2 How can there be a message when the boss comes down to let people know?
I prepared this boss from rme And he comes down every hour after his killers
I only have 4 boss How do I do this I want a text for this and an explanation
Thanks in advance
Maybe a globalevent onThink using getSpectators

Untested.

Set to check once per minute. (60000 = 60 seconds)
XML:
<globalevent name="bossAnnouncer" interval="60000" script="bossAnnouncer.lua"/>

Loop through all boss locations, and if a new boss is found at that location, broadcast message.
Lua:
local bosses = {
    {spawnPosition = Position(1000, 1000, 7), creatureName = "munster", message = "An oversized rat has been spotted in Thais sewers."}...

Dakos

Active Member
Joined
Jan 1, 2010
Messages
73
Solutions
12
Reaction score
35
data/events/scripts/monster.lua

replace onSpawn func to this:
Lua:
local bosses = { "Orshabaal", "Demodras" }
function Monster:onSpawn(position, startup, artificial)
    local name = self:getName()
    local _sendMessage = true

    if isInArray(bosses, name) then
       if _sendMessage then
          Game.broadcastMessage("Attention! " .. name .. " has been spawned.", MESSAGE_STATUS_WARNING)
       end
       self:registerEvent("BOSS_SYSTEM_onDeath")
    end
 
    if hasEventCallback(EVENT_CALLBACK_ONSPAWN) then
        return EventCallback(EVENT_CALLBACK_ONSPAWN, self, position, startup, artificial)
    else
        return true
    end
end
make sure onSpawn its enabled in data/events/events.xml
XML:
<event class="Monster" method="onSpawn" enabled="1" />
then create a file "bossDeath.lua" in data/scripts
Lua:
local creaturescript = CreatureEvent("BOSS_SYSTEM_onDeath")
function creaturescript.onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    local name = creature:getName()
    Game.broadcastMessage("Attention! " .. name .. " has been defeated.", MESSAGE_STATUS_WARNING)
    return true
end
creaturescript:register()
 
Last edited:
OP
OP
abdala ragab

abdala ragab

Banned User
Joined
Aug 18, 2018
Messages
308
Solutions
10
Reaction score
272
data/events/scripts/monster.lua

replace onSpawn func to this:
Lua:
local bosses = { "Orshabaal", "Demodras" }
function Monster:onSpawn(position, startup, artificial)
    local name = self:getName()
    local _sendMessage = true

    if isInArray(bosses, name) then
       if _sendMessage then
          Game.broadcastMessage("Attention! " .. name .. " has been spawned.", MESSAGE_STATUS_WARNING)
       end
       self:registerEvent("BOSS_SYSTEM_onDeath")
    end
 
    if hasEventCallback(EVENT_CALLBACK_ONSPAWN) then
        return EventCallback(EVENT_CALLBACK_ONSPAWN, self, position, startup, artificial)
    else
        return true
    end
end
make sure onSpawn its enabled in data/events/events.xml
XML:
<event class="Monster" method="onSpawn" enabled="1" />
then create a file "bossDeath.lua" in data/scripts
Lua:
local creaturescript = CreatureEvent("BOSS_SYSTEM_onDeath")
function creaturescript.onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    local name = creature:getName()
    Game.broadcastMessage("Attention! " .. name .. " has been defeated.", MESSAGE_STATUS_WARNING)
    return true
end
creaturescript:register()
This text does not work, I tried to start the engine, but it does not appear and disappears
iam use tfs 1.2
 

Dakos

Active Member
Joined
Jan 1, 2010
Messages
73
Solutions
12
Reaction score
35
This text does not work, I tried to start the engine, but it does not appear and disappears
iam use tfs 1.2
check on prints if scripts are executed correctly, maybe i misspeled the BroadcastMessage func.

Lua:
local bosses = { "Orshabaal", "Demodras" }
function Monster:onSpawn(position, startup, artificial)
    local name = self:getName()
    local _sendMessage = true

    if isInArray(bosses, name) then
       print("[Boss System] - Spawned")
       if _sendMessage then
          Game.broadcastMessage("Attention! " .. name .. " has been spawned.", MESSAGE_STATUS_WARNING)
       end
       self:registerEvent("BOSS_SYSTEM_onDeath")
    end
 
    if hasEventCallback(EVENT_CALLBACK_ONSPAWN) then
        return EventCallback(EVENT_CALLBACK_ONSPAWN, self, position, startup, artificial)
    else
        return true
    end
end


Lua:
local creaturescript = CreatureEvent("BOSS_SYSTEM_onDeath")
function creaturescript.onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    print("[Boss System] - Boss Defeated")
    local name = creature:getName()
    Game.broadcastMessage("Attention! " .. name .. " has been defeated.", MESSAGE_STATUS_WARNING)
    return true
end
creaturescript:register()
 
OP
OP
abdala ragab

abdala ragab

Banned User
Joined
Aug 18, 2018
Messages
308
Solutions
10
Reaction score
272
check on prints if scripts are executed correctly, maybe i misspeled the BroadcastMessage func.

Lua:
local bosses = { "Orshabaal", "Demodras" }
function Monster:onSpawn(position, startup, artificial)
    local name = self:getName()
    local _sendMessage = true

    if isInArray(bosses, name) then
       print("[Boss System] - Spawned")
       if _sendMessage then
          Game.broadcastMessage("Attention! " .. name .. " has been spawned.", MESSAGE_STATUS_WARNING)
       end
       self:registerEvent("BOSS_SYSTEM_onDeath")
    end
 
    if hasEventCallback(EVENT_CALLBACK_ONSPAWN) then
        return EventCallback(EVENT_CALLBACK_ONSPAWN, self, position, startup, artificial)
    else
        return true
    end
end


Lua:
local creaturescript = CreatureEvent("BOSS_SYSTEM_onDeath")
function creaturescript.onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    print("[Boss System] - Boss Defeated")
    local name = creature:getName()
    Game.broadcastMessage("Attention! " .. name .. " has been defeated.", MESSAGE_STATUS_WARNING)
    return true
end
creaturescript:register()
no work man look when i reload events ot close :D
msg.png
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
6,107
Solutions
506
Reaction score
4,274
iam use tfs 1.2 How can there be a message when the boss comes down to let people know?
I prepared this boss from rme And he comes down every hour after his killers
I only have 4 boss How do I do this I want a text for this and an explanation
Thanks in advance
Maybe a globalevent onThink using getSpectators

Untested.

Set to check once per minute. (60000 = 60 seconds)
XML:
<globalevent name="bossAnnouncer" interval="60000" script="bossAnnouncer.lua"/>

Loop through all boss locations, and if a new boss is found at that location, broadcast message.
Lua:
local bosses = {
    {spawnPosition = Position(1000, 1000, 7), creatureName = "munster", message = "An oversized rat has been spotted in Thais sewers."},
    {spawnPosition = Position(1000, 1000, 7), creatureName = "boss_name", message = "A boss_name has spawned."},
}
local creatureIds = {}

function onThink(interval, lastExecution)
    for i = 1, #bosses do
        local spectators = Game.getSpectators(bosses[i].spawnPosition)
        for _, creature in ipairs(spectators) do
            if creature:getName():lower() == bosses[i].creatureName:lower() then
                if not creatureIds[i] or creatureIds[i] ~= creature:getId() then
                    creatureIds[i] = creature:getId()
                    Game.broadcastMessage(bosses[i].message, MESSAGE_STATUS_CONSOLE_ORANGE)
                end
                break
            end
        end
    end
    return true
end
 
Solution
OP
OP
abdala ragab

abdala ragab

Banned User
Joined
Aug 18, 2018
Messages
308
Solutions
10
Reaction score
272
Untested.

Set to check once per minute. (60000 = 60 seconds)
XML:
<globalevent name="bossAnnouncer" interval="60000" script="bossAnnouncer.lua"/>

Loop through all boss locations, and if a new boss is found at that location, broadcast message.
Lua:
local bosses = {
    {spawnPosition = Position(1000, 1000, 7), creatureName = "munster", message = "An oversized rat has been spotted in Thais sewers."},
    {spawnPosition = Position(1000, 1000, 7), creatureName = "boss_name", message = "A boss_name has spawned."},
}
local creatureIds = {}

function onThink(interval, lastExecution)
    for i = 1, #bosses do
        local spectators = Game.getSpectators(bosses[i].spawnPosition)
        for _, creature in ipairs(spectators) do
            if creature:getName():lower() == bosses[i].creatureName:lower() then
                if not creatureIds[i] or creatureIds[i] ~= creature:getId() then
                    creatureIds[i] = creature:getId()
                    Game.broadcastMessage(bosses[i].message, MESSAGE_STATUS_CONSOLE_ORANGE)
                end
                break
            end
        end
    end
    return true
end
Thank you it works well
 

Itutorial

Excellent OT User
Joined
Dec 23, 2014
Messages
2,141
Solutions
61
Reaction score
762
If you would like a way that doesn't require onThink and check for spectators you can do this.

add a file in data/lib name it mapbosses.lua
Lua:
--[[
name: Boss name
pos: Position he should spawn
time: How long after server start up should the boss spawn. (minutes)
respawn: How long after it is killed for it to spawn again. (minutes)
msg: Message when the boss spawns
msgKilled: Message when the boss is killed
]]--

MAP_BOSSES_CONFIG = {
    [1] = {id = 1, name = "Demon", pos = Position(1000, 1000, 7), time = 30, respawn = 60, msg = "Demon Spawned!", msgKilled = "Demon has been slain!"},
    [2] = {id = 2, name = "Morgaroth", pos = Position(1000, 1000, 7), time = 45, respawn = 60, msg = "Morgaroth Spawned!", msgKilled = "Morgaroth has been slain!"}
}

MAP_BOSSES_IDS = {}

for i = 1, #MAP_BOSSES_CONFIG do
    MAP_BOSSES_IDS[i] = 0
end

function spawnMapBoss(id)
    local bossConf = MAP_BOSSES_CONFIG[id]
    if not bossConf then return true end
    
    if MAP_BOSSES_IDS[id] and MAP_BOSSES_IDS[id] ~= 0 then return true end
    
    local BOSS = Game.createMonster(bossConf.name, bossConf.pos)
    MAP_BOSSES_IDS[id] = BOSS:getId()
    return true
end

Make sure in data/lib/lib.lua you include the file
Lua:
dofile('data/lib/mapbosses.lua')

Change the onThink to onStartup in globalevents
Lua:
function onStartUp()
    for i = 1, #MAP_BOSSES_CONFIG do
        addEvent(spawnMapBoss, MAP_BOSSES_CONFIG[i].time * 60 * 1000, MAP_BOSSES_CONFIG[i].id)
    end
    return true
end

add a file in data/creaturescripts/scripts name is mapbosskill.lua
Lua:
function onKill(creature, target)
    if not creature:isPlayer() then return true end
    if not target:isMonster() then return true end
    
    for i = 1, #MAP_BOSSES_IDS do
        if target:getId() == MAP_BOSSES_IDS[i] then
            Game.broadcastMessage(MAP_BOSSES_CONFIG[i].msgKilled, 1)
            addEvent(spawnMapBoss, MAP_BOSSES_CONFIG[i].respawn * 60 * 1000, i)
            MAP_BOSSES_IDS[i] = 0
        end
    end    
    return true
end

in data/creaturescripts/creaturescripts.xml add
XML:
<event type="kill" name="MapBossKill" script="mapbosskill.lua" />

and last in data/creaturescripts/scripts/login.lua add
Lua:
player:registerEvent("MapBossKill")

This has a little more configuration and will just store the bosses id's in memory. The main problem with the pervious code is if the boss is pulled far enough away another will spawn even if its not dead.
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
6,107
Solutions
506
Reaction score
4,274
The main problem with the pervious code is if the boss is pulled far enough away another will spawn even if its not dead.
Slight caveat, in that rme is spawning the boss, not the code. xP

Otherwise yeah it'd be way easier, and not need spectator checks at all, since we'd have full control of the creature ids inside the script.
 

Itutorial

Excellent OT User
Joined
Dec 23, 2014
Messages
2,141
Solutions
61
Reaction score
762
Slight caveat, in that rme is spawning the boss, not the code. xP

Otherwise yeah it'd be way easier, and not need spectator checks at all, since we'd have full control of the creature ids inside the script.
True, this will make it so bosses don't need to be added in RME. Good catch Xikini
 
Top