• 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.2 Shitty code that doesnt work how it should

Tbol

Well-Known Member
Joined
Apr 7, 2019
Messages
526
Reaction score
54
So have issue with this code especially when multiple creatures get involved it doesnt create teleport. I will comment the parts that works and the part that doesnt work.
Lua:
local config = {
    {mobs = {"Test 1", "Test 2", "Super Test 1", "Super Test 2", "Elite Test 1", "Elite Test 2"}, pos = Position(1039, 1122, 8), destination = Position(1138, 1191, 8), duration = 15}, -- DOESNT WORK
    {mobs = {"Test10 (1)"}, pos = Position(1027, 1165, 7), destination = Position(1047, 1160, 7), duration = 10}, -- WORKS PERFECT
    {mobs = {"Test10 (2)"}, pos = Position(1047, 1154, 7), destination = Position(1039, 1173, 7), duration = 10}, -- WORKS PERFECT
    {mobs = {"Test11 (1)"}, pos = Position(1067, 1174, 7), destination = Position(1015, 1187, 7), duration = 10}, -- WORKS PERFECT
    {mobs = {"Test11 (2)"}, pos = Position(1011, 1209, 7), destination = Position(1041, 1186, 7), duration = 10}, -- WORKS PERFECT
    {mobs = {"Test12 (1)"}, pos = Position(1038, 1210, 7), destination = Position(1063, 1188, 7), duration = 10}, -- WORKS PERFECT
    {mobs = {"Test12 (2)"}, pos = Position(1119, 1193, 7), destination = Position(1039, 1240, 8), duration = 10}, -- WORKS PERFECT
}

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

You see this part i commented that doesnt work so i tested it on localhost and with admin i killed those creatures so it created the portal, but then i tried go a hard way being regular player i noticed that it didnt created the portal maybe because it took like a lot of time to kill all monsters so code for some reason didnt created it. Basically its like really unstable code i would say.
 
Are you sure there are no other monsters with names:
"Test 1", "Test 2", "Super Test 1", "Super Test 2", "Elite Test 1", "Elite Test 2"
on server? Didn't any of them duplicated by spawn script?

You can try to test it on GOD by typing:
Code:
/goto Test 1
/goto Test 2
...
It should teleport you to monster, if its somewhere on map.

EDIT:
You script is based on unique names of monsters. Teleport appears only when all monsters from list are not spawned ANYWHERE on server.
 
Last edited:
Are you sure there are no other monsters with names:
"Test 1", "Test 2", "Super Test 1", "Super Test 2", "Elite Test 1", "Elite Test 2"
on server? Didn't any of them duplicated by spawn script?

You can try to test it on GOD by typing:
Code:
/goto Test 1
/goto Test 2
...
It should teleport you to monster, if its somewhere on map.
Yes 100000% sure

Maybe this code executes like for example if you kill Test 1 even when you didnt killed all of the monsters it still summons the teleport or does something stupid?
 
Yes 100000% sure

Maybe this code executes like for example if you kill Test 1 even when you didnt killed all of the monsters it still summons the teleport or does something stupid?
All monsters from list:
Code:
mobs = {"Test 1", "Test 2", "Super Test 1", "Super Test 2", "Elite Test 1", "Elite Test 2"}
must be not spawned anywhere on server.

EDIT:
It's super 'unstable'. It alsy detects.. PLAYERS AND NPCS. So if there is any player or NPC with name 'Test 1' script will be blocked.
 
All monsters from list:
Code:
mobs = {"Test 1", "Test 2", "Super Test 1", "Super Test 2", "Elite Test 1", "Elite Test 2"}
must be not spawned anywhere on server.

EDIT:
It's super 'unstable'. It alsy detects.. PLAYERS AND NPCS. So if there is any player or NPC with name 'Test 1' script will be blocked.
There is no players with name like this, there is no npcs with name like this. Checked the map there isnt spawned any monster with this name anywhere else only in that place. So im not sure where is the issue
 
Try this

Lua:
local config = {
    [1] = {mobs = {"Test 1", "Test 2", "Super Test 1", "Super Test 2", "Elite Test 1", "Elite Test 2"}, pos = Position(1039, 1122, 8), destination = Position(1138, 1191, 8), duration = 15}, -- DOESNT WORK
    [2] = {mobs = {"Test10 (1)"}, pos = Position(1027, 1165, 7), destination = Position(1047, 1160, 7), duration = 10}, -- WORKS PERFECT
    [3] = {mobs = {"Test10 (2)"}, pos = Position(1047, 1154, 7), destination = Position(1039, 1173, 7), duration = 10}, -- WORKS PERFECT
    [4] = {mobs = {"Test11 (1)"}, pos = Position(1067, 1174, 7), destination = Position(1015, 1187, 7), duration = 10}, -- WORKS PERFECT
    [5] = {mobs = {"Test11 (2)"}, pos = Position(1011, 1209, 7), destination = Position(1041, 1186, 7), duration = 10}, -- WORKS PERFECT
    [6] = {mobs = {"Test12 (1)"}, pos = Position(1038, 1210, 7), destination = Position(1063, 1188, 7), duration = 10}, -- WORKS PERFECT
    [7] = {mobs = {"Test12 (2)"}, pos = Position(1119, 1193, 7), destination = Position(1039, 1240, 8), duration = 10} -- WORKS PERFECT
}

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified)
    if not creature:isMonster() and killer:isPlayer() then return true end
   
    local CONF = nil
   
    for i = 1, #config do
        if isInArray(config[i].mobs, creature:getName()) then
            CONF = config[i]
            break
        end
    end

    if not CONF then return true end
   
    local createPortal = true
   
    if #CONF.mobs > 1 then
        for    i, v in ipairs(CONF.mobs) do
            local checkMonster = Monster(CONF.mobs[v])
            if checkMonster then
                createPortal = false
                break
            end
       
        end
    end
   
    if createPortal then
        local portal = doCreateTeleport(1387, CONF.destination, CONF.pos)
        if portal then
            if killer then
                local string = "You have " .. CONF.duration .. " " .. (CONF.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, CONF.duration * 60 * 1000, CONF.pos)
        end
    end
    return true
end
 
Try this

Lua:
local config = {
    [1] = {mobs = {"Test 1", "Test 2", "Super Test 1", "Super Test 2", "Elite Test 1", "Elite Test 2"}, pos = Position(1039, 1122, 8), destination = Position(1138, 1191, 8), duration = 15}, -- DOESNT WORK
    [2] = {mobs = {"Test10 (1)"}, pos = Position(1027, 1165, 7), destination = Position(1047, 1160, 7), duration = 10}, -- WORKS PERFECT
    [3] = {mobs = {"Test10 (2)"}, pos = Position(1047, 1154, 7), destination = Position(1039, 1173, 7), duration = 10}, -- WORKS PERFECT
    [4] = {mobs = {"Test11 (1)"}, pos = Position(1067, 1174, 7), destination = Position(1015, 1187, 7), duration = 10}, -- WORKS PERFECT
    [5] = {mobs = {"Test11 (2)"}, pos = Position(1011, 1209, 7), destination = Position(1041, 1186, 7), duration = 10}, -- WORKS PERFECT
    [6] = {mobs = {"Test12 (1)"}, pos = Position(1038, 1210, 7), destination = Position(1063, 1188, 7), duration = 10}, -- WORKS PERFECT
    [7] = {mobs = {"Test12 (2)"}, pos = Position(1119, 1193, 7), destination = Position(1039, 1240, 8), duration = 10} -- WORKS PERFECT
}

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified)
    if not creature:isMonster() and killer:isPlayer() then return true end
 
    local CONF = nil
 
    for i = 1, #config do
        if isInArray(config[i].mobs, creature:getName()) then
            CONF = config[i]
            break
        end
    end

    if not CONF then return true end
 
    local createPortal = true
 
    if #CONF.mobs > 1 then
        for    i, v in ipairs(CONF.mobs) do
            local checkMonster = Monster(CONF.mobs[v])
            if checkMonster then
                createPortal = false
                break
            end
     
        end
    end
 
    if createPortal then
        local portal = doCreateTeleport(1387, CONF.destination, CONF.pos)
        if portal then
            if killer then
                local string = "You have " .. CONF.duration .. " " .. (CONF.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, CONF.duration * 60 * 1000, CONF.pos)
        end
    end
    return true
end
[1] = {mobs = {"Test 1", "Test 2", "Super Test 1", "Super Test 2", "Elite Test 1", "Elite Test 2"}, pos = Position(1039, 1122, 8), destination = Position(1138, 1191, 8),

So i killed Super Test 1 as a first creature and it created a teleport not sure why it did that. It should have created teleport only when all creature are killed in the list.
 
Try this

Lua:
local config = {
    [1] = {mobs = {"Test 1", "Test 2", "Super Test 1", "Super Test 2", "Elite Test 1", "Elite Test 2"}, pos = Position(1039, 1122, 8), destination = Position(1138, 1191, 8), duration = 15}, -- DOESNT WORK
    [2] = {mobs = {"Test10 (1)"}, pos = Position(1027, 1165, 7), destination = Position(1047, 1160, 7), duration = 10}, -- WORKS PERFECT
    [3] = {mobs = {"Test10 (2)"}, pos = Position(1047, 1154, 7), destination = Position(1039, 1173, 7), duration = 10}, -- WORKS PERFECT
    [4] = {mobs = {"Test11 (1)"}, pos = Position(1067, 1174, 7), destination = Position(1015, 1187, 7), duration = 10}, -- WORKS PERFECT
    [5] = {mobs = {"Test11 (2)"}, pos = Position(1011, 1209, 7), destination = Position(1041, 1186, 7), duration = 10}, -- WORKS PERFECT
    [6] = {mobs = {"Test12 (1)"}, pos = Position(1038, 1210, 7), destination = Position(1063, 1188, 7), duration = 10}, -- WORKS PERFECT
    [7] = {mobs = {"Test12 (2)"}, pos = Position(1119, 1193, 7), destination = Position(1039, 1240, 8), duration = 10} -- WORKS PERFECT
}

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified)
    if not creature:isMonster() and killer:isPlayer() then return true end
    
    local CONF = nil
    
    for i = 1, #config do
        if isInArray(config[i].mobs, creature:getName()) then
            CONF = config[i]
            break
        end
    end
    
    if not CONF then return true end
    
    local createPortal = true
    
    if #CONF.mobs > 1 then
        for    i = 1 #CONF.mobs do
            local checkMonster = Monster(CONF.mobs[i])
            if checkMonster then
                createPortal = false
                break
            end
        end
    end
    
    if createPortal then
        local portal = doCreateTeleport(1387, CONF.destination, CONF.pos)
        if portal then
            if killer then
                local string = "You have " .. CONF.duration .. " " .. (CONF.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, CONF.duration * 60 * 1000, CONF.pos)
        end
    end
    return true
end
 
Try this

Lua:
local config = {
    [1] = {mobs = {"Test 1", "Test 2", "Super Test 1", "Super Test 2", "Elite Test 1", "Elite Test 2"}, pos = Position(1039, 1122, 8), destination = Position(1138, 1191, 8), duration = 15}, -- DOESNT WORK
    [2] = {mobs = {"Test10 (1)"}, pos = Position(1027, 1165, 7), destination = Position(1047, 1160, 7), duration = 10}, -- WORKS PERFECT
    [3] = {mobs = {"Test10 (2)"}, pos = Position(1047, 1154, 7), destination = Position(1039, 1173, 7), duration = 10}, -- WORKS PERFECT
    [4] = {mobs = {"Test11 (1)"}, pos = Position(1067, 1174, 7), destination = Position(1015, 1187, 7), duration = 10}, -- WORKS PERFECT
    [5] = {mobs = {"Test11 (2)"}, pos = Position(1011, 1209, 7), destination = Position(1041, 1186, 7), duration = 10}, -- WORKS PERFECT
    [6] = {mobs = {"Test12 (1)"}, pos = Position(1038, 1210, 7), destination = Position(1063, 1188, 7), duration = 10}, -- WORKS PERFECT
    [7] = {mobs = {"Test12 (2)"}, pos = Position(1119, 1193, 7), destination = Position(1039, 1240, 8), duration = 10} -- WORKS PERFECT
}

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified)
    if not creature:isMonster() and killer:isPlayer() then return true end
   
    local CONF = nil
   
    for i = 1, #config do
        if isInArray(config[i].mobs, creature:getName()) then
            CONF = config[i]
            break
        end
    end
   
    if not CONF then return true end
   
    local createPortal = true
   
    if #CONF.mobs > 1 then
        for    i = 1 #CONF.mobs do
            local checkMonster = Monster(CONF.mobs[i])
            if checkMonster then
                createPortal = false
                break
            end
        end
    end
   
    if createPortal then
        local portal = doCreateTeleport(1387, CONF.destination, CONF.pos)
        if portal then
            if killer then
                local string = "You have " .. CONF.duration .. " " .. (CONF.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, CONF.duration * 60 * 1000, CONF.pos)
        end
    end
    return true
end
Same
 
Try this

Lua:
            local checkMonster = Monster(CONF.mobs[i])
Function Monster(param) accepts 2 types of parameter:
1. id- id of creature (know as cid 'creature id')
2. userdata - other instance of Monster or instance of Creature that is monster
Passing name of monster always return nil which is false in LUA:
Post automatically merged:

@Tbol
Try this script:
Code:
local config = {
    {mobs = {"Test 1", "Test 2", "Super Test 1", "Super Test 2", "Elite Test 1", "Elite Test 2"}, pos = Position(1039, 1122, 8), destination = Position(1138, 1191, 8), duration = 15}, -- DOESNT WORK
    {mobs = {"Test10 (1)"}, pos = Position(1027, 1165, 7), destination = Position(1047, 1160, 7), duration = 10}, -- WORKS PERFECT
    {mobs = {"Test10 (2)"}, pos = Position(1047, 1154, 7), destination = Position(1039, 1173, 7), duration = 10}, -- WORKS PERFECT
    {mobs = {"Test11 (1)"}, pos = Position(1067, 1174, 7), destination = Position(1015, 1187, 7), duration = 10}, -- WORKS PERFECT
    {mobs = {"Test11 (2)"}, pos = Position(1011, 1209, 7), destination = Position(1041, 1186, 7), duration = 10}, -- WORKS PERFECT
    {mobs = {"Test12 (1)"}, pos = Position(1038, 1210, 7), destination = Position(1063, 1188, 7), duration = 10}, -- WORKS PERFECT
    {mobs = {"Test12 (2)"}, pos = Position(1119, 1193, 7), destination = Position(1039, 1240, 8), duration = 10}, -- WORKS PERFECT
}

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
                    local mobPosition = mob_temp:getPosition()
                    print('onDeath mobs - FOUND CREATURE: ' .. mob .. '! Position: ' .. mobPosition.x .. ', y=' .. mobPosition.y .. ', z=' .. mobPosition.z)
                    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)
            else
                print('onDeath mobs - failed to create teleport!')
            end
            break
        end
    end
    return true
end
It will show in server console one of errors after you kill mobs:
- "onDeath mobs - FOUND CREATURE ... (here position)" - there is somewhere creature with given name
- "onDeath mobs - failed to create teleport!" - it was impossible to create teleport on given position, probably some item on that position blocked it

"onDeath mobs - FOUND CREATURE ... (here position)" SHOULD appear after kill of every mob from 'mobs' list, but not after killing last one. If it appears after killing last one, go to position from error and check what is there.
 
Last edited:
Function Monster(param) accepts 2 types of parameter:
1. id- id of creature (know as cid 'creature id')
2. userdata - other instance of Monster or instance of Creature that is monster
Passing name of monster always return nil which is false in LUA:
Post automatically merged:

@Tbol
Try this script:
Code:
local config = {
    {mobs = {"Test 1", "Test 2", "Super Test 1", "Super Test 2", "Elite Test 1", "Elite Test 2"}, pos = Position(1039, 1122, 8), destination = Position(1138, 1191, 8), duration = 15}, -- DOESNT WORK
    {mobs = {"Test10 (1)"}, pos = Position(1027, 1165, 7), destination = Position(1047, 1160, 7), duration = 10}, -- WORKS PERFECT
    {mobs = {"Test10 (2)"}, pos = Position(1047, 1154, 7), destination = Position(1039, 1173, 7), duration = 10}, -- WORKS PERFECT
    {mobs = {"Test11 (1)"}, pos = Position(1067, 1174, 7), destination = Position(1015, 1187, 7), duration = 10}, -- WORKS PERFECT
    {mobs = {"Test11 (2)"}, pos = Position(1011, 1209, 7), destination = Position(1041, 1186, 7), duration = 10}, -- WORKS PERFECT
    {mobs = {"Test12 (1)"}, pos = Position(1038, 1210, 7), destination = Position(1063, 1188, 7), duration = 10}, -- WORKS PERFECT
    {mobs = {"Test12 (2)"}, pos = Position(1119, 1193, 7), destination = Position(1039, 1240, 8), duration = 10}, -- WORKS PERFECT
}

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
                    local mobPosition = mob_temp:getPosition()
                    print('onDeath mobs - FOUND CREATURE: ' .. mob .. '! Position: ' .. mobPosition.x .. ', y=' .. mobPosition.y .. ', z=' .. mobPosition.z)
                    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)
            else
                print('onDeath mobs - failed to create teleport!')
            end
            break
        end
    end
    return true
end
It will show in server console one of errors after you kill mobs:
- "onDeath mobs - FOUND CREATURE ... (here position)" - there is somewhere creature with given name
- "onDeath mobs - failed to create teleport!" - it was impossible to create teleport on given position, probably some item on that position blocked it

"onDeath mobs - FOUND CREATURE ... (here position)" SHOULD appear after kill of every mob from 'mobs' list, but not after killing last one. If it appears after killing last one, go to position from error and check what is there.
Wait it prints wrong creature name. So i killed Elite Test 1 but it printed Test 1. Checked the monster files to make sure if they created just fine (called fine) and everything looked just perfect from monster side. So it says that its something wrong the the code?
 
Wait it prints wrong creature name. So i killed Elite Test 1 but it printed Test 1. Checked the monster files to make sure if they created just fine (called fine) and everything looked just perfect from monster side. So it says that its something wrong the the code?
Its fine. It prints name of creature that is still alive and must be killed to create portal.
 
Its fine. It prints name of creature that is still alive and must be killed to create portal.
Hmm it works but pretty sure you didnt changed anything just added some prints? :D I mentioned above that code worked fine when you test it with admin on (localhost), but when you do it with regular player its a story for some reason. But if you changed something in the code who knows maybe it will work.
 
Hmm it works but pretty sure you didnt changed anything just added some prints? :D I mentioned above that code worked fine when you test it with admin on (localhost), but when you do it with regular player its a story for some reason. But if you changed something in the code who knows maybe it will work.
Nothing changed. Just added prints to debug what is a problem.
 
Back
Top