• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

How to add multiple monsters in this code

SixNine

Active Member
Joined
Dec 12, 2018
Messages
484
Reaction score
46
Hello. TFS 1.2
so i wondering how to add multiple monsters and different teleports for every monster because now this code have just one condition there is no options to create another teleport with different monster
 
Solution
and different teleports for every monster
Your explanations never cease to confuse me. lol

Try this one, it checks if any of the creatures exist in the name array, and if they do it wont create teleport. So if you have another boss of the same name in another positions on map it wont work. If you need to keep two of the same bosses on the map then we can figure out a different approach.
LUA:
local config = {
    {mobs = {"Golgordan", "Latrivan"}, pos = Position(1000, 1000, 7), destination = Position(1000, 1000, 7), duration = 10},
    {mobs = {"Orshabaal"}, pos = Position(1000, 1000, 7), destination = Position(1000, 1000, 7), duration = 10},
}

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified)...
Hello. TFS 1.2
so i wondering how to add multiple monsters and different teleports for every monster because now this code have just one condition there is no options to create another teleport with different monster
Probably better to do this script as an onDeath instead of onKill, since it'll call the function less often.

creaturescripts.xml
XML:
<event type="death" name="ScriptName" script="scriptName.lua" />

In each monsters xml file that is used:
XML:
    <script>
        <event name="ScriptName" />
    </script>

LUA:
local mobs = {
    ['Golgordan'] = {pos = Position(1000, 1000, 7), destination = Position(1000, 1000, 7), duration = 10},
    ['Latrivan'] = {pos = Position(1000, 1000, 7), destination = Position(1000, 1000, 7), duration = 10},
}

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified)
    local mob_array = creature and mobs[creature:getName()]
    if not killer or not mob_array then return true end

    local portal = doCreateTeleport(1387, mob_array.destination, mob_array.pos)
    if portal then
        local string = "You have " .. mob_array.duration .. " " .. (mob_array.duration > 1 and 'minutes' or 'minute') .. " to enter the portal."
        killer:say(string, TALKTYPE_MONSTER_SAY)
        addEvent(function(pos)
            local portal = Tile(pos):getItemById(1387)
            if portal then
                portal:remove()
                pos:sendMagicEffect(CONST_ME_POFF)
            end
        end, mob_array.duration * 60 * 1000, mob_array.pos)
    end
    return true
end
 
Probably better to do this script as an onDeath instead of onKill, since it'll call the function less often.

creaturescripts.xml
XML:
<event type="death" name="ScriptName" script="scriptName.lua" />

In each monsters xml file that is used:
XML:
    <script>
        <event name="ScriptName" />
    </script>

LUA:
local mobs = {
    ['Golgordan'] = {pos = Position(1000, 1000, 7), destination = Position(1000, 1000, 7), duration = 10},
    ['Latrivan'] = {pos = Position(1000, 1000, 7), destination = Position(1000, 1000, 7), duration = 10},
}

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified)
    local mob_array = creature and mobs[creature:getName()]
    if not killer or not mob_array then return true end

    local portal = doCreateTeleport(1387, mob_array.destination, mob_array.pos)
    if portal then
        local string = "You have " .. mob_array.duration .. " " .. (mob_array.duration > 1 and 'minutes' or 'minute') .. " to enter the portal."
        killer:say(string, TALKTYPE_MONSTER_SAY)
        addEvent(function(pos)
            local portal = Tile(pos):getItemById(1387)
            if portal then
                portal:remove()
                pos:sendMagicEffect(CONST_ME_POFF)
            end
        end, mob_array.duration * 60 * 1000, mob_array.pos)
    end
    return true
end
Okay thats pretty close but it lost important part what if you have to kill multiple monster for teleport to appear?
 
and different teleports for every monster
Your explanations never cease to confuse me. lol

Try this one, it checks if any of the creatures exist in the name array, and if they do it wont create teleport. So if you have another boss of the same name in another positions on map it wont work. If you need to keep two of the same bosses on the map then we can figure out a different approach.
LUA:
local config = {
    {mobs = {"Golgordan", "Latrivan"}, pos = Position(1000, 1000, 7), destination = Position(1000, 1000, 7), duration = 10},
    {mobs = {"Orshabaal"}, pos = Position(1000, 1000, 7), destination = Position(1000, 1000, 7), duration = 10},
}

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified)
    local name = creature:getName()
    for _, mob_array in pairs(config) do
        if isInArray(mob_array.mobs, name) then
            for _, mob in pairs(mob_array.mobs) do
                local mob_temp = Creature(mob)
                if mob_temp and mob_temp.uid ~= creature.uid then
                    return true
                end
            end

            local portal = doCreateTeleport(1387, mob_array.destination, mob_array.pos)
            if portal then
                if killer then
                    local string = "You have " .. mob_array.duration .. " " .. (mob_array.duration > 1 and 'minutes' or 'minute') .. " to enter the portal."
                    killer:say(string, TALKTYPE_MONSTER_SAY)
                end
                addEvent(function(pos)
                    local portal = Tile(pos):getItemById(1387)
                    if portal then
                        portal:remove()
                        pos:sendMagicEffect(CONST_ME_POFF)
                    end
                end, mob_array.duration * 60 * 1000, mob_array.pos)
            end
            break
        end
    end
    return true
end
 
Last edited:
Solution
Your explanations never cease to confuse me. lol

Try this one, it checks if any of the creatures exist in the name array, and if they do it wont create teleport. So if you have another boss of the same name in another positions on map it wont work. If you need to keep two of the same bosses on the map then we can figure out a different approach.
LUA:
function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified)
    local name = creature:getName()
    for _, mob_array in pairs(config) do
        if isInArray(mob_array.mobs, name) then
            for _, mob in pairs(mob_array.mobs) do
                local mob_temp = Creature(mob)
                if mob_temp and mob_temp.uid ~= creature.uid then
                    return true
                end
            end

            local portal = doCreateTeleport(1387, mob_array.destination, mob_array.pos)
            if portal then
                if killer then
                    local string = "You have " .. mob_array.duration .. " " .. (mob_array.duration > 1 and 'minutes' or 'minute') .. " to enter the portal."
                    killer:say(string, TALKTYPE_MONSTER_SAY)
                end
                addEvent(function(pos)
                    local portal = Tile(pos):getItemById(1387)
                    if portal then
                        portal:remove()
                        pos:sendMagicEffect(CONST_ME_POFF)
                    end
                end, mob_array.duration * 60 * 1000, mob_array.pos)
            end
            break
        end
    end
    return true
end
So loca should look like this?
LUA:
local mobs = {
    ['Golgordan'] = {pos = Position(1000, 1000, 7), destination = Position(1000, 1000, 7), duration = 10},
    ['Latrivan', 'Latrivan Second'] = {pos = Position(1000, 1000, 7), destination = Position(1000, 1000, 7), duration = 10},
}
 
So loca should look like this?
LUA:
local mobs = {
    ['Golgordan'] = {pos = Position(1000, 1000, 7), destination = Position(1000, 1000, 7), duration = 10},
    ['Latrivan', 'Latrivan Second'] = {pos = Position(1000, 1000, 7), destination = Position(1000, 1000, 7), duration = 10},
}
My mistake, forgot to add it:
LUA:
local config = {
    {mobs = {"Golgordan", "Latrivan"}, pos = Position(1000, 1000, 7), destination = Position(1000, 1000, 7), duration = 10},
    {mobs = {"Orshabaal"}, pos = Position(1000, 1000, 7), destination = Position(1000, 1000, 7), duration = 10},
}
 
Back
Top