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

Lua Remove Creature from area.

Dibis

Member
Joined
Dec 1, 2022
Messages
73
Reaction score
16
Location
POLAND
Hello.
I have problem with this moveevents scripts. When in room have monster, not remove him.
Create next , and next...
Who can edit this for me?

Lua:
local teleports = {
    -- Tile UID = {storage of task, amount of monsters, monsters to spawn}
    [1054] = {monsters = {"Necropharus"}, telePos = {x = 270, y = 374, z = 11}, spawnPos = {x = 270, y = 371, z = 11}, from = {x = 267, y = 367, z = 11}, to = {x = 272, y = 374, z = 11}},
    [1009] = {monsters = {"The Horned Fox"}, telePos = {x = 1880, y = 1266, z = 9}, spawnPos = {x = 1884, y = 1265, z = 9}, from = {x = 1882, y = 1261, z = 9}, to = {x = 1886, y = 1266, z = 9}},
    [1053] = {monsters = {"Ron The Ripper"}, telePos = {x = 343, y = 864, z = 6}, spawnPos = {x = 344, y = 858, z = 6}, from = {x = 341, y = 860, z = 6}, to = {x = 347, y = 864, z = 6}},
    [1022] = {monsters = {"Demodras"}, telePos = {x = 1876, y = 1271, z = 8}, spawnPos = {x = 1878, y = 1267, z = 8}, from = {x = 1878, y = 1265, z = 8}, to = {x = 1881, y = 1269, z = 8}},
    [1029] = {monsters = {"Tiquandas Revenge"}, telePos = {x = 1417, y = 814, z = 7}, spawnPos = {x = 1415, y = 807, z = 7}, from = {x = 1412, y = 805, z = 7}, to = {x = 1420, y = 811, z = 7}},
}

local function getCreaturesInArea(fromPos, toPos, creatureType)
    local creatures = {}
    for x = fromPos.x, toPos.x do
        for y = fromPos.y, toPos.y do
            for z = fromPos.z, toPos.z do
                local creature = getTopCreature({x = x, y = y, z = z}).uid
                local cType  creatureType:lower()
                if (cType == "players" and isPlayer(creature)) then
                    table.insert(creatures, creature)
                elseif (cType == "monsters" and isMonster(creature)) then
                    table.insert(creatures, creature)
                elseif (cType == "npcs" and isNpc(creature)) then
                    table.insert(creatures, creature)
                elseif (cType == "all") then
                    table.insert(creatures, creature)
                end
            end
        end
    end
    return creatures
end

function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
local now = teleports[item.uid]
    if (#getCreaturesInArea(now.from, now.to, "players") > 0) then
        doTeleportThing(cid, fromPosition, true)
        doPlayerSendCancel(cid, "Someone else is in the room.")
    end

    if getPlayerStorageValue(cid,(90000+item.uid)) == 999 then
        for _, monster in ipairs(getCreaturesInArea(now.from, now.to, "monsters")) do
            doRemoveCreature(monster)
        end
        setPlayerStorageValue(cid,(90000+item.uid),1000)
        doTeleportThing(cid, now.telePos)
        doSendMagicEffect(now.telePos, CONST_ME_TELEPORT)
        doCreatureSay(cid, "This is your last chance to kill this boss!", TALKTYPE_ORANGE_1, false, cid)
        doSummonCreature(now.monsters[math.random(#now.monsters)], now.spawnPos)
        doSendMagicEffect(now.spawnPos, CONST_ME_TELEPORT)
        return true
    end
    
    doPlayerOpenChannel(cid, 16)
    doPlayerSendChannelMessage(cid,"Daniel Steelsoul","You already kill this boss or you do not have a completed task.", TALKTYPE_CHANNEL_MANAGEMENT, 16)
    doTeleportThing(cid, fromPosition, true)
    return true
end
 
Since you using only one monster in "monsters" array not multiplies as the script was designed to (it draws a random monster from the monsters array), I just refactored it to only one monster, however arena should be cleaned from all existing monsters + instead of huge ifology i reorganized it and applied some early returns, try it:
Lua:
local teleports = {
    [1054] = {boss = "Necropharus", telePos = {x = 270, y = 374, z = 11}, spawnPos = {x = 270, y = 371, z = 11}, from = {x = 267, y = 367, z = 11}, to = {x = 272, y = 374, z = 11}},
    [1009] = {boss = "The Horned Fox", telePos = {x = 1880, y = 1266, z = 9}, spawnPos = {x = 1884, y = 1265, z = 9}, from = {x = 1882, y = 1261, z = 9}, to = {x = 1886, y = 1266, z = 9}},
    [1053] = {boss = "Ron The Ripper", telePos = {x = 343, y = 864, z = 6}, spawnPos = {x = 344, y = 858, z = 6}, from = {x = 341, y = 860, z = 6}, to = {x = 347, y = 864, z = 6}},
    [1022] = {boss = "Demodras", telePos = {x = 1876, y = 1271, z = 8}, spawnPos = {x = 1878, y = 1267, z = 8}, from = {x = 1878, y = 1265, z = 8}, to = {x = 1881, y = 1269, z = 8}},
    [1029] = {boss = "Tiquandas Revenge", telePos = {x = 1417, y = 814, z = 7}, spawnPos = {x = 1415, y = 807, z = 7}, from = {x = 1412, y = 805, z = 7}, to = {x = 1420, y = 811, z = 7}},
}

-- This function is complete nonsense but you have it, so whatever
local function getCreaturesInArena(fromPos, toPos, getMonsters)
    local creaturesInArena = {}
    for x = fromPos.x, toPos.x do
        for y = fromPos.y, toPos.y do
            for z = fromPos.z, toPos.z do
                local creature = getTopCreature({x = x, y = y, z = z}).uid
                if creature and (getMonsters and isMonster(creature) or not getMonsters and isPlayer(creature)) then
                    table.insert(creaturesInArena, creature)
                end
            end
        end
    end
    return creaturesInArena
end

function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
    -- Variables from table
    local arena = teleports[item.uid] -- Key
    local boss = arena.boss -- Value: "boss"

    -- Early return : Check if someone is already in arena
    if (#getCreaturesInArena(arena.from, arena.to, false) > 0) then
        doTeleportThing(cid, fromPosition, true)
        doPlayerSendCancel(cid, "Someone else is in the room.")
        return true
    end

    -- Early return : Check if player is eligable to enter arena (have required storage)
    if not (getPlayerStorageValue(cid, (90000+item.uid)) == 999) then
        doPlayerOpenChannel(cid, 16)
        doPlayerSendChannelMessage(cid,"Daniel Steelsoul","You already killed ".. boss .." or you do not have a completed task.", TALKTYPE_CHANNEL_MANAGEMENT, 16)
        doTeleportThing(cid, fromPosition, true)
        return true
    end

    -- Cleanup existing bosses in arena
    if (#getCreaturesInArena(arena.from, arena.to, true) > 0) then
        for _, anyMonsterOnArena in ipairs(getCreaturesInArena(arena.from, arena.to, true)) do
            doRemoveCreature(anyMonsterOnArena)
        end
    end

    setPlayerStorageValue(cid, (90000+item.uid), 1000)
    doTeleportThing(cid, arena.telePos)
    doSendMagicEffect(arena.telePos, CONST_ME_TELEPORT)
    doCreatureSay(cid, "This is your last chance to kill ".. boss .."!", TALKTYPE_ORANGE_1, false, cid)
    doSummonCreature(boss, arena.spawnPos)
    doSendMagicEffect(arena.spawnPos, CONST_ME_TELEPORT)
    return true
end
Let me know if any errors occur
 
Last edited:
Since you using only one monster in "monsters" array not multiplies as the script was designed to (it draws a random monster from the monsters array), I just refactored it to only one monster, however arena should be cleaned from all existing monsters + instead of huge ifology i reorganized it and applied some early returns, try it:
Lua:
local teleports = {
    [1054] = {boss = {"Necropharus"}, telePos = {x = 270, y = 374, z = 11}, spawnPos = {x = 270, y = 371, z = 11}, from = {x = 267, y = 367, z = 11}, to = {x = 272, y = 374, z = 11}},
    [1009] = {boss = {"The Horned Fox"}, telePos = {x = 1880, y = 1266, z = 9}, spawnPos = {x = 1884, y = 1265, z = 9}, from = {x = 1882, y = 1261, z = 9}, to = {x = 1886, y = 1266, z = 9}},
    [1053] = {boss = {"Ron The Ripper"}, telePos = {x = 343, y = 864, z = 6}, spawnPos = {x = 344, y = 858, z = 6}, from = {x = 341, y = 860, z = 6}, to = {x = 347, y = 864, z = 6}},
    [1022] = {boss = {"Demodras"}, telePos = {x = 1876, y = 1271, z = 8}, spawnPos = {x = 1878, y = 1267, z = 8}, from = {x = 1878, y = 1265, z = 8}, to = {x = 1881, y = 1269, z = 8}},
    [1029] = {boss = {"Tiquandas Revenge"}, telePos = {x = 1417, y = 814, z = 7}, spawnPos = {x = 1415, y = 807, z = 7}, from = {x = 1412, y = 805, z = 7}, to = {x = 1420, y = 811, z = 7}},
}

local function getCreaturesInArea(fromPos, toPos, creatureType)
    local creatures = {}
    for x = fromPos.x, toPos.x do
        for y = fromPos.y, toPos.y do
            for z = fromPos.z, toPos.z do
                local creature = getTopCreature({x = x, y = y, z = z}).uid
                if (creatureType == "players" and isPlayer(creature)) or
                   (creatureType == "monsters" and isMonster(creature)) or
                   (creatureType == "npcs" and isNpc(creature)) or
                   (creatureType == "all") then
                    table.insert(creatures, creature)
                end
            end
        end
    end
    return creatures
end

function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
    -- Variables from table
    local arena = teleports[item.uid] -- Key
    local boss = arena.monster -- Value: "boss"

    -- Early return : Check if someone is already in arena
    if (#getCreaturesInArea(arena.from, arena.to, "players") > 0) then
        doTeleportThing(cid, fromPosition, true)
        doPlayerSendCancel(cid, "Someone else is in the room.")
        return true
    end

    -- Early return : Check if player is eligable to enter arena (have required storage)
    if not getPlayerStorageValue(cid, (90000+item.uid)) == 999 then
        doPlayerOpenChannel(cid, 16)
        doPlayerSendChannelMessage(cid,"Daniel Steelsoul","You already kill this boss or you do not have a completed task.", TALKTYPE_CHANNEL_MANAGEMENT, 16)
        doTeleportThing(cid, fromPosition, true)
        return true
    end

    -- Cleanup existing bosses in arena
    if (#getCreaturesInArea(arena.from, arena.to, "monsters") > 0) then
        for _, anyMonsterOnArena in ipairs(getCreaturesInArea(arena.from, arena.to, "monsters")) do
            if isMonster(anyMonsterOnArena) then
                doRemoveCreature(anyMonsterOnArena)
            end
        end
    end

    setPlayerStorageValue(cid, (90000+item.uid), 1000)
    doTeleportThing(cid, arena.telePos)
    doSendMagicEffect(arena.telePos, CONST_ME_TELEPORT)
    doCreatureSay(cid, "This is your last chance to kill this boss!", TALKTYPE_ORANGE_1, false, cid)
    doSummonCreature(boss, arena.spawnPos)
    doSendMagicEffect(arena.spawnPos, CONST_ME_TELEPORT)
    return true
end
Let me know if any errors occur

I try check your script.
You know how change this line:
doPlayerSendChannelMessage(cid,"Daniel Steelsoul","You already kill this boss or you do not have a completed task.",
"this boss" to boss name in table etc "The Horned Fox" ?
 
Yes, I edited my post included your boss name request in strings.

Not working.

First problem: string.format
Second: No create monster, only delete monster in area. (when i delete strings).

[00:15:29.543] [Error - MoveEvents Interface]
[00:15:29.543] data/movements/scripts/tasks.lua:eek:nStepIn
[00:15:29.543] Description:
[00:15:29.543] data/movements/scripts/tasks.lua:55: bad argument #2 to 'format' (string expected, got nil)
[00:15:29.543] stack traceback:
[00:15:29.543] [C]: in function 'format'
[00:15:29.543] data/movements/scripts/tasks.lua:55: in function <data/movements/scripts/tasks.lua:25>

And when delete strings problem i have tnext problem:

[00:17:25.185] [Error - MoveEvents Interface]
[00:17:25.185] data/movements/scripts/tasks.lua:eek:nStepIn
[00:17:25.185] Description:
[00:17:25.185] (luaDoCreateMonster) Monster with name '' not found
[00:17:25.185] [Warning - Npc::createNpc] Cannot find npc with name: .

[00:17:25.185] [Error - MoveEvents Interface]
[00:17:25.185] data/movements/scripts/tasks.lua:eek:nStepIn
[00:17:25.185] Description:
[00:17:25.185] (luaDoCreateNpc) Npc with name '' not found

[00:17:31.792] [Error - MoveEvents Interface]
[00:17:31.792] data/movements/scripts/tasks.lua:eek:nStepIn
[00:17:31.792] Description:
[00:17:31.792] (luaDoCreateMonster) Monster with name '' not found
[00:17:31.792] [Warning - Npc::createNpc] Cannot find npc with name: .

[00:17:31.792] [Error - MoveEvents Interface]
[00:17:31.792] data/movements/scripts/tasks.lua:eek:nStepIn
[00:17:31.792] Description:
[00:17:31.792] (luaDoCreateNpc) Npc with name '' not found
 
Last edited:
@Xikini @Gesior.pl @M0ustafa ?
I edited my post, check now.

No working, now this problem.

And this line:
setPlayerStorageValue(cid, (90000+item.uid), 1000)
Why If not?

if not getPlayerStorageValue(cid, (90000+item.uid)) == 999 then

Not working, not check storage and not set storage...

[00:38:24.813] [Error - MoveEvents Interface]
[00:38:24.813] data/movements/scripts/tasks.lua:eek:nStepIn
[00:38:24.813] Description:
[00:38:24.813] data/movements/scripts/tasks.lua:55: attempt to concatenate local 'boss' (a nil value)
[00:38:24.813] stack traceback:
[00:38:24.813] data/movements/scripts/tasks.lua:55: in function <data/movements/scripts/tasks.lua:25>
 
Last edited:
Oh I forget that I reworked it to single monster and the boss name shouldn't be in array (brackets) in table anymore, edited.
 
Oh I forget that I reworked it to single monster and the boss name shouldn't be in array (brackets) in table anymore, edited.

Not working.

[00:52:10.583] [Error - MoveEvents Interface]
[00:52:10.583] data/movements/scripts/tasks.lua:eek:nStepIn
[00:52:10.583] Description:
[00:52:10.583] data/movements/scripts/tasks.lua:40: attempt to concatenate local 'boss' (a nil value)
[00:52:10.583] stack traceback:
[00:52:10.583] data/movements/scripts/tasks.lua:40: in function <data/movements/scripts/tasks.lua:25>
 
One more request, is it possible to add storage after killing a boss?
To do it you need to create script in creaturescripts with event onDeath or onKill (don't know names, because they are different in different TFS distros).. and there you need to write logic, if have storage then give storage etc.
 
Back
Top