• 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+ Send a message when the boss comes down

abdala ragab

Veteran OT User
Joined
Aug 18, 2018
Messages
447
Solutions
11
Reaction score
331
Location
gamelaot.sytes.net
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."}...
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.
There is something I do not understand
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
Where do I put this exactly?
I don't have anything like this in globalevents
 
Back
Top