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

getFungusInArea Error [TFS 1.2]

flaviiojr

Active Member
Joined
Jan 20, 2017
Messages
230
Solutions
13
Reaction score
39
When using the globber in the fungus, this error appears, already tried to register in the lib, but not stop giving this error, could you help me? Thank you very much in advance!

R8Mbomb.png

Lua:
local position = {
    Position(33313, 31852, 9),
    Position(33313, 31865, 9),
    Position(33313, 31881, 9),
    Position(33328, 31860, 9),
    Position(33328, 31885, 9),
    Position(33308, 31873, 9),
    Position(33320, 31873, 9),
    Position(33336, 31914, 9),
    Position(33343, 31914, 9),
    Position(33361, 31914, 9),
    Position(33352, 31900, 9),
    Position(33355, 31861, 9),
    Position(33355, 31885, 9),
    Position(33345, 31864, 9),
    Position(33345, 31881, 9),
    Position(33309, 31867, 9),
    Position(33311, 31854, 9),
    Position(33334, 31889, 9),
    Position(33340, 31890, 9),
    Position(33347, 31889, 9)
}

local creatureNames = {
    'iron servant',
    'golden servant',
    'diamond servant'
}

local function getFungusInArea(fromPos, toPos)
    for x = fromPos.x, toPos.x do
        for y = fromPos.y, toPos.y do
            for itemId = 13585, 13589 do
                if Tile(Position(x, y, fromPos.z)):getItemById(itemId) then
                    return true
                end
            end
        end
    end
    return false
end

local function summonMonster(name, position)
    Game.createMonster(name, position)
    position:sendMagicEffect(CONST_ME_TELEPORT)
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not isInArray({13585, 13586, 13587, 13588, 13589}, target.itemid) then
        return false
    end

    if player:getStorageValue(Storage.TheirMastersVoice.SlimeGobblerTimeout) < os.time() then
        target:transform(13590)
        player:setStorageValue(Storage.TheirMastersVoice.SlimeGobblerTimeout, os.time() + 5)
        player:say('The slime gobbler gobbles large chunks of the slime fungus with great satisfaction.', TALKTYPE_MONSTER_SAY)
        player:addExperience(20, true, true)
        if not getFungusInArea(Position(33306, 31847, 9), Position(33369, 31919, 9)) then
            for i = 1, #position do
                addEvent(summonMonster, 5 * 1000, creatureNames[math.random(#creatureNames)], position[i])
            end
            player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
            player:say('COME! My servants! RISE!', TALKTYPE_MONSTER_SAY)
            Game.setStorageValue(GlobalStorage.TheirMastersVoice.ServantsKilled, 0)
            Game.setStorageValue(GlobalStorage.TheirMastersVoice.CurrentServantWave, 0)
        end
    end
    return true
end
 
Last edited:
Solution
Lua:
local function getFungusInArea(fromPos, toPos)
    for x = fromPos.x, toPos.x do
        for y = fromPos.y, toPos.y do
            for itemId = 13585, 13589 do
                local tile = Tile(Position(x, y, fromPos.z))
                if tile and tile:getItemById(itemId) then
                    return true
                end
            end
        end
    end
    return false
end
Add this to your script (slimeGobbler.lua):
Lua:
local function getFungusInArea(fromPos, toPos)
    for x = fromPos.x, toPos.x do
        for y = fromPos.y, toPos.y do
            for itemId = 13585, 13589 do
                if Tile(Position(x, y, fromPos.z)):getItemById(itemId) then
                    return true
                end
            end
        end
    end
    return false
end
 
Lua:
local function getFungusInArea(fromPos, toPos)
    for x = fromPos.x, toPos.x do
        for y = fromPos.y, toPos.y do
            for itemId = 13585, 13589 do
                local tile = Tile(Position(x, y, fromPos.z))
                if tile and tile:getItemById(itemId) then
                    return true
                end
            end
        end
    end
    return false
end
 
Solution
Lua:
local function getFungusInArea(fromPos, toPos)
    for x = fromPos.x, toPos.x do
        for y = fromPos.y, toPos.y do
            for itemId = 13585, 13589 do
                local tile = Tile(Position(x, y, fromPos.z))
                if tile and tile:getItemById(itemId) then
                    return true
                end
            end
        end
    end
    return false
end
IT WORKED! Many thanks @Xeraphus !
But without being abused, I could add a simple thing:
If the player tries to use the item, and has not finished os.time () + 5), return a sentence that he can not use the item now.
 
Lua:
local exhaust = {}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local endTime = exhaust[player:getId()]
    if endTime and (os.mtime() < endTime) then
        player:sendCancelMessage("You are exhausted.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end
    if not isInArray({13585, 13586, 13587, 13588, 13589}, target.itemid) then
        return false
    end

    if player:getStorageValue(Storage.TheirMastersVoice.SlimeGobblerTimeout) < os.time() then
        target:transform(13590)
        player:setStorageValue(Storage.TheirMastersVoice.SlimeGobblerTimeout, os.time() + 5)
        player:say('The slime gobbler gobbles large chunks of the slime fungus with great satisfaction.', TALKTYPE_MONSTER_SAY)
        player:addExperience(20, true, true)
        if not getFungusInArea(Position(33306, 31847, 9), Position(33369, 31919, 9)) then
            for i = 1, #position do
                addEvent(summonMonster, 5 * 1000, creatureNames[math.random(#creatureNames)], position[i])
            end
            player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
            player:say('COME! My servants! RISE!', TALKTYPE_MONSTER_SAY)
            Game.setStorageValue(GlobalStorage.TheirMastersVoice.ServantsKilled, 0)
            Game.setStorageValue(GlobalStorage.TheirMastersVoice.CurrentServantWave, 0)
        end
    end
    exhaust[player:getId()] = os.mtime() + 5000
    return true
end
 
@Xeraphus, Can I send you a private message? With a little problem the relation of this script, and I do not know how to work to synchronize the two.

Only gives the first horde of creatures, when the message appears gives the first respawn and then to ... something missing in the script?

Lua:
local exhaust = {}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local endTime = exhaust[player:getId()]
    if endTime and (os.mtime() < endTime) then
        player:sendCancelMessage("You are exhausted.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end
    if not isInArray({13585, 13586, 13587, 13588, 13589}, target.itemid) then
        return false
    end

    if player:getStorageValue(Storage.TheirMastersVoice.SlimeGobblerTimeout) < os.time() then
        target:transform(13590)
        player:setStorageValue(Storage.TheirMastersVoice.SlimeGobblerTimeout, os.time() + 5)
        player:say('The slime gobbler gobbles large chunks of the slime fungus with great satisfaction.', TALKTYPE_MONSTER_SAY)
        player:addExperience(20, true, true)
        if not getFungusInArea(Position(33306, 31847, 9), Position(33369, 31919, 9)) then
            for i = 1, #position do
                addEvent(summonMonster, 5 * 1000, creatureNames[math.random(#creatureNames)], position[i])
            end
            player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
            player:say('COME! My servants! RISE!', TALKTYPE_MONSTER_SAY)
            Game.setStorageValue(GlobalStorage.TheirMastersVoice.ServantsKilled, 0)
            Game.setStorageValue(GlobalStorage.TheirMastersVoice.CurrentServantWave, 0)
        end
    end
    exhaust[player:getId()] = os.mtime() + 5000
    return true
end

Did not run, did not appear exhausted message, need to add exhaust time?
 
Last edited by a moderator:
@Xeraphus, Can I send you a private message? With a little problem the relation of this script, and I do not know how to work to synchronize the two.

Only gives the first horde of creatures, when the message appears gives the first respawn and then to ... something missing in the script?
i don't understand what you mean
it doesnt spawn any more creatures after using it once?
use this instead since i didn't see the storage value was used for time
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not isInArray({13585, 13586, 13587, 13588, 13589}, target.itemid) then
        return false
    end

    if player:getStorageValue(Storage.TheirMastersVoice.SlimeGobblerTimeout) < os.time() then
        target:transform(13590)
        player:setStorageValue(Storage.TheirMastersVoice.SlimeGobblerTimeout, os.time() + 5)
        player:say('The slime gobbler gobbles large chunks of the slime fungus with great satisfaction.', TALKTYPE_MONSTER_SAY)
        player:addExperience(20, true, true)
        if not getFungusInArea(Position(33306, 31847, 9), Position(33369, 31919, 9)) then
            for i = 1, #position do
                addEvent(summonMonster, 5 * 1000, creatureNames[math.random(#creatureNames)], position[i])
            end
            player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
            player:say('COME! My servants! RISE!', TALKTYPE_MONSTER_SAY)
            Game.setStorageValue(GlobalStorage.TheirMastersVoice.ServantsKilled, 0)
            Game.setStorageValue(GlobalStorage.TheirMastersVoice.CurrentServantWave, 0)
        end
    else
        player:sendCancelMessage("You are exhausted.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end
    return true
end
 
it doesnt spawn any more creatures after using it once?
It does not generate more creatures after the first respawn, for sure it was to have 20 turns of respawn, it only generates the first turn and stop.

use this instead since i didn't see the storage value was used for time
Still does not display the exhausted message :((

And once again, thank you, @Xeraphus
 
It does not generate more creatures after the first respawn, for sure it was to have 20 turns of respawn, it only generates the first turn and stop.


Still does not display the exhausted message :((

And once again, thank you, @Xeraphus
it isn't automatic, you have to wait 5 seconds to spawn them again (edit: the fungus function probably returns true after the 1st wave, so it wouldn't spawn anything after the fungus function doesnt find any item ids)
as for the exhaust message it should show at the bottom of youur tibia screen in the white text
if it doesnt, change return false to return true
 
it isn't automatic, you have to wait 5 seconds to spawn them again
Should not work like this, it should work as follows:
1. By removing all the fungus from the room, it would start a wave of creatures
2. 20 waves of automatic respawn
3. After all the respawns are killed, the fungus reappears on the floor of the room

This is the creaturescript that verifies how many creatures were killed to give the respawn of mad mage.

Lua:
local magePositions = {
    Position(33328, 31859, 9),
    Position(33367, 31873, 9),
    Position(33349, 31899, 9)
}

local positions = {
    Position(33313, 31852, 9),
    Position(33313, 31865, 9),
    Position(33313, 31881, 9),
    Position(33328, 31860, 9),
    Position(33328, 31873, 9),
    Position(33328, 31885, 9),
    Position(33308, 31873, 9),
    Position(33320, 31873, 9),
    Position(33335, 31873, 9),
    Position(33360, 31873, 9),
    Position(33336, 31914, 9),
    Position(33343, 31914, 9),
    Position(33353, 31914, 9),
    Position(33361, 31914, 9),
    Position(33345, 31900, 9),
    Position(33352, 31900, 9),
    Position(33355, 31854, 9),
    Position(33355, 31861, 9),
    Position(33355, 31885, 9),
    Position(33345, 31864, 9),
    Position(33345, 31881, 9),
    Position(33309, 31867, 9),
    Position(33317, 31879, 9),
    Position(33311, 31854, 9),
    Position(33334, 31889, 9),
    Position(33340, 31890, 9),
    Position(33347, 31889, 9)
}

local servants = {
    'iron servant',
    'golden servant',
    'diamond servant'
}

local function fillFungus(fromPosition, toPosition)
    for x = fromPosition.x, toPosition.x do
        for y = fromPosition.y, toPosition.y do
            local position = Position(x, y, 9)
            local tile = Tile(position)
            if tile then
                local item = tile:getItemById(13590)
                if item then
                    item:transform(math.random(13585, 13589))
                    position:sendMagicEffect(CONST_ME_YELLOW_RINGS)
                end
            end
        end
    end
end

local function summonServant(position)
    Game.createMonster(servants[math.random(#servants)], position)
    position:sendMagicEffect(CONST_ME_TELEPORT)
end

function onKill(creature, target)
    local targetMonster = target:getMonster()
    if not targetMonster then
        return true
    end

    if not isInArray(servants, targetMonster:getName():lower()) then
        return true
    end

    local wave, killedAmount = Game.getStorageValue(GlobalStorage.TheirMastersVoice.CurrentServantWave), Game.getStorageValue(GlobalStorage.TheirMastersVoice.ServantsKilled)
    if killedAmount == #positions and wave < 25 then
        Game.setStorageValue(GlobalStorage.TheirMastersVoice.ServantsKilled, 0)
        Game.setStorageValue(GlobalStorage.TheirMastersVoice.CurrentServantWave, wave + 1)

        for i = 1, #positions do
            addEvent(summonServant, 5 * 1000, positions[i])
        end

    elseif killedAmount < #positions and wave < 25 then
        Game.setStorageValue(GlobalStorage.TheirMastersVoice.ServantsKilled, killedAmount + 1)

    elseif killedAmount == #positions and wave == 25 then
        Game.createMonster('mad mage', magePositions[math.random(#magePositions)])
        targetMonster:say('The Mad Mage has been spawned!', TALKTYPE_MONSTER_SAY)
        fillFungus({x = 33306, y = 31847}, {x = 33369, y = 31919})
    end
    return true
end

if it doesnt, change return false to return true
It worked! Thank you man @Xeraphus
 
Last edited:
Back
Top