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

Solved SOLVED, PLEASE CLOSE

silveralol

Advanced OT User
Joined
Mar 16, 2010
Messages
1,484
Solutions
9
Reaction score
217
hello folks, I'm trying make some script that compare if have some ground in fromPos, toPos...
Code:
local function getFungusInArea(fromPos, toPos)
    for x = fromPos.x, toPos.x do
        for y = fromPos.y, toPos.y do   
            local itemIds = {13592, 13598, 13599, 13600, 13585, 13586, 13587, 13588, 13589, 13593}
            for i = 0, #itemIds do
                local item = Tile(x, y, 9):getItemById(itemIds[i])
                if item then
                    player:say('true...', TALKTYPE_MONSTER_SAY)
                    return true
                end
            end
        end
    end
    player:say('false ...', TALKTYPE_MONSTER_SAY)
    return false
end
this is my test, I already try use the function from orts data pack but there are wrong too e.e
my call of the function is:
Code:
    if not getFungusInArea(Position(33306, 31847, 9), Position(33369, 31919, 9)) then
 
Last edited:
It will search for items in itemIds list in the tile items and tile ground item, not tested:

Code:
local itemIds = {13592, 13598, 13599, 13600, 13585, 13586, 13587, 13588, 13589, 13593}
local function getFungusInArea(fromPos, toPos)
    for x = fromPos.x, toPos.x do
        for y = fromPos.y, toPos.y do
            for z = fromPos.z, toPos.z do
                local tile = Tile(x, y, z)
                if tile then
                    local found = false
                    local ground = tile:getGround()
                 
                    found = ground and isInArray(itemIds, ground:getId())
                 
                    if not found then
                        for _, itemId in ipairs(itemIds) do
                            if tile:getItemById(itemId) then
                                found = true
                                break
                            end
                        end
                    end
                 
                    if found then
                        player:say('true...', TALKTYPE_MONSTER_SAY)
                        return true
                    end
                end
            end
        end
    end
 
    player:say('false ...', TALKTYPE_MONSTER_SAY)
    return false
end
 
It will search for items in itemIds list in the tile items and tile ground item, not tested:

Code:
local itemIds = {13592, 13598, 13599, 13600, 13585, 13586, 13587, 13588, 13589, 13593}
local function getFungusInArea(fromPos, toPos)
    for x = fromPos.x, toPos.x do
        for y = fromPos.y, toPos.y do
            for z = fromPos.z, toPos.z do
                local tile = Tile(x, y, z)
                if tile then
                    local found = false
                    local ground = tile:getGround()
                
                    found = ground and isInArray(itemIds, ground:getId())
                
                    if not found then
                        for _, itemId in ipairs(itemIds) do
                            if tile:getItemById(itemId) then
                                found = true
                                break
                            end
                        end
                    end
                
                    if found then
                        player:say('true...', TALKTYPE_MONSTER_SAY)
                        return true
                    end
                end
            end
        end
    end

    player:say('false ...', TALKTYPE_MONSTER_SAY)
    return false
end
some items in array is not a ground
it will give trouble
 
Try this
Code:
    local itemIds = {13592, 13598, 13599, 13600, 13585, 13586, 13587, 13588, 13589, 13593}
    local function getFungusInArea(fromPos, toPos)
        local found = false
        for x = fromPos.x, toPos.x do
            for y = fromPos.y, toPos.y do
                for z = fromPos.z, toPos.z do
                    local tile = Tile(x, y, z)
                    if tile then
                        found = isInArray( itemIds, tile:getGround():getId() )
                        if found then
                            break
                        end
                    end
                end
            end
        end
        player:say(tostring(found)..'...', TALKTYPE_MONSTER_SAY)
        return found
    end
 
Last edited:
Try this
Code:
    local itemIds = {13592, 13598, 13599, 13600, 13585, 13586, 13587, 13588, 13589, 13593}
    local function getFungusInArea(fromPos, toPos)
        local found = false
        for x = fromPos.x, toPos.x do
            for y = fromPos.y, toPos.y do
                for z = fromPos.z, toPos.z do
                    local tile = Tile(x, y, z)
                    if tile then
                        found = isInArray( itemIds, tile:getGround():getId() )
                        if found then
                            break
                        end
                    end
                end
            end
        end
        player:say(tostring(found)..'...', TALKTYPE_MONSTER_SAY)
        return found
    end
give error of attempt to index a nil value...
line: found = isInArray( itemIds, tile:getGround():getId() )

the problem is: some items in the array is not a ground...
how to get the grounds and not grounds?
 
Last edited:
give error of attempt to index a nil value...
line: found = isInArray( itemIds, tile:getGround():getId() )

the problem is: some items in the array is not a ground...
how to get the grounds and not grounds?
Code:
    local itemIds = {13592, 13598, 13599, 13600, 13585, 13586, 13587, 13588, 13589, 13593}
    local function getFungusInArea(fromPos, toPos)
        local found = false
        for x = fromPos.x, toPos.x do
            for y = fromPos.y, toPos.y do
                for z = fromPos.z, toPos.z do
                    local tile = Tile(x, y, z)
                    if tile and tile:getGround() then
                        found = isInArray( itemIds, tile:getGround():getId() )
                        if found then
                            break
                        end
                    end
                end
            end
        end
        player:say(tostring(found)..'...', TALKTYPE_MONSTER_SAY)
        return found
    end
 
Code:
    local itemIds = {13592, 13598, 13599, 13600, 13585, 13586, 13587, 13588, 13589, 13593}
    local function getFungusInArea(fromPos, toPos)
        local found = false
        for x = fromPos.x, toPos.x do
            for y = fromPos.y, toPos.y do
                for z = fromPos.z, toPos.z do
                    local tile = Tile(x, y, z)
                    if tile and tile:getGround() then
                        found = isInArray( itemIds, tile:getGround():getId() )
                        if found then
                            break
                        end
                    end
                end
            end
        end
        player:say(tostring(found)..'...', TALKTYPE_MONSTER_SAY)
        return found
    end
it return false always
my attempt:
Code:
local function getFungusInArea(fromPos, toPos, player)
    local itemIds = {13585, 13586, 13587, 13588, 13589, 13593}
    local fungusIds = {13592, 13598, 13599, 13600}
    for x = fromPos.x, toPos.x do
        for y = fromPos.y, toPos.y do
            local ground = Tile(Position(x, y, 9)):getGround()
            local fungus = Tile(Position(x, y, 9)):getItemById(itemIds)
            if ground:getName():lower()~= 'slime fungus' then
                player:say('FALSE,... mean NOT have fungus', TALKTYPE_MONSTER_SAY)
                return false
            elseif fungus:getName():lower() ~= 'slime fungus' then
                player:say('FALSE,... mean NOT have fungus', TALKTYPE_MONSTER_SAY)
                return false
            end
        end
    end
    player:say('TRUE,... mean that HAVE fungus', TALKTYPE_MONSTER_SAY)
    return true
end
I try with the name of the item, the id of the item :S try alot of ways but not have success
 
Try printing the name of the item and remove the return statements inside the if / else clauses.

This doesn't look like it will allow the script to work
Code:
local fungus = Tile(Position(x, y, 9)):getItemById(itemIds)
Since itemIds is a table and not a number if your not generating an error there is something else wrong in the script.

Also once a return statement is called it ends the script, i'll give you an example.
Code:
function test(a, b)
    for i = a, b do
        -- lets say hypothetically this is the ground:getName():lower()~= 'slime fungus' condition
        if i + 2 == b then
            print("the script has ended in the if statement where i equals "..i)
            return false
        -- and this is hypothetically the fungus:getName():lower() ~= 'slime fungus' condition
        elseif i == b-1 then
            -- this will never execute
            print("the script has ended in the elseif statement where i equals "..i)
            return false
        end
        print(i)
    end
    -- neither will this
    print("this is the return statement.")
    return true
end

test(1,10)
This is the output of that function
Code:
1
2
3
4
5
6
7
the script has ended in the if statement where i equals 8
As you can see the return statement that is used in the if / elseif clause prevents the function from reaching the max value of b, only executing the if statement and never the elseif statement or the return value outside of the loop
Once the function encounters a return statement it ends the scripts execution, there is more to this but I don't want to confuse you any further :p

This is why when writing scripts it is extremely important to have a good grasp on the core language in this case lua, not just the tfs framework :)
 
Last edited:
Try printing the name of the item and remove the return statements inside the if / else clauses.

This doesn't look like it will allow the script to work
Code:
local fungus = Tile(Position(x, y, 9)):getItemById(itemIds)
Since itemIds is a table and not a number if your not generating an error there is something else wrong in the script.

Also once a return statement is called it ends the script, i'll give you an example.
Code:
function test(a, b)
    for i = a, b do
        -- lets say hypothetically this is the ground:getName():lower()~= 'slime fungus' condition
        if i + 2 == b then
            print("the script has ended in the if statement where i equals "..i)
            return false
        -- and this is hypothetically the fungus:getName():lower() ~= 'slime fungus' condition
        elseif i == b-1 then
            -- this will never execute
            print("the script has ended in the elseif statement where i equals "..i)
            return false
        end
        print(i)
    end
    -- neither will this
    print("this is the return statement.")
    return true
end

test(1,10)
This is the output of that function
Code:
1
2
3
4
5
6
7
the script has ended in the if statement where i equals 8
As you can see the return statement that is used in the if / elseif clause prevents the function from reaching the max value of b, only executing the if statement and never the elseif statement or the return value outside of the loop
Once the function encounters a return statement it ends the scripts execution, there is more to this but I don't want to confuse you any further :p

This is why when writing scripts it is extremely important to have a good grasp on the core language in this case lua, not just the tfs framework :)
will try something!!! thank you
ah, orts data pack have a function like a function that I need, but there get a small error
see:
Code:
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
we can try fix this
 
well, I'm trying make a real "their master voice quest" ... the gobbler will eat the fungus, all time will check if have more fungus, if not have fungus will start the waves of servants
 
If there are errors you need to post them, otherwise your just making debugging the script next to impossible.
 
If there are errors you need to post them, otherwise your just making debugging the script next to impossible.
here the error of the function from orts
JR70xtK.png
 
well, I'm trying make a real "their master voice quest" ... the gobbler will eat the fungus, all time will check if have more fungus, if not have fungus will start the waves of servants
never heard of this quest.
who is gobbler? player name?
check for more fungus? what? how much he ate before?
If not ate then creatures spawn?
 
Back
Top