• 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:
Can you just post the whole script instead of just the function?
not need it ...
the script is simple function on use, if not have fungus will call another function ...
anothers parts of the script are correct, works perfectly
for "not have fungus" is the function that try find some item in the array
 
so i glanced at the link.
You are making onUse function?
Yet why is it so hard to say me what you want to make?
Probably would take 10mins for any of us to present the working script...
okay, I'll try explain better... what my function have to do is:
first: my function getFungusInArea, is a function called in a function onUse ...
second: the function getFungusInArea check if have FUNGUS in the map ...
fungus = itemIds = {13592, 13598, 13599, 13600, 13585, 13586, 13587, 13588, 13589, 13593}
if the function found fungus in map will return true
if not found fungus will return false
just it, if you don't understand me yet, let me try explain again ;)
 
I'm pretty sure he wants a function to check an entire area for an array of item IDs. If any tile in the entire area (floor or wall tile) contains an item ID in the array, return true else return false.
Functions should be able to work independently of the script system they're being implemented in.

Red
 
okay, I'll try explain better... what my function have to do is:
first: my function getFungusInArea, is a function called in a function onUse ...
second: the function getFungusInArea check if have FUNGUS in the map ...
fungus = itemIds = {13592, 13598, 13599, 13600, 13585, 13586, 13587, 13588, 13589, 13593}
if the function found fungus in map will return true
if not found fungus will return false
just it, if you don't understand me yet, let me try explain again ;)
I'm pretty sure he wants a function to check an entire area for an array of item IDs. If any tile in the entire area (floor or wall tile) contains an item ID in the array, return true else return false.
Functions should be able to work independently of the script system they're being implemented in.
Is red correct?

Also, are you using another item to trigger this? (using item will not check is it in fungus area, but using item what should identify is the itemEx in fungus area)
 
Is red correct?

Also, are you using another item to trigger this? (using item will not check is it in fungus area, but using item what should identify is the itemEx in fungus area)
yes, using the slime globber in a item target (is a fungus) will check if have more fungus in the area...
 
1 last thing. is areas squarelike or "random shape"?
EDIT: actaully nvm.. not going to make exact area drawer..
 
Could be here some typos, nor didn't test it. But should be easy enough to understand and fix.

Code:
fungusAreas = { --{{top left corner}, {bottom right corner}} YOU CAN CHOOSE NONTILE AREAS, just make sure square covers entire area.
    {{x=1,y=1,z=9},{x=3,y=3,z=9}},
    {{x=1,y=1,z=9},{x=3,y=3,z=9}},
end

-- Create x*y position table
function createSquarePosTabel2(startPos, endPos)
local positions = {}

    for i=startPos.x, endPos.x do
        for j=startPos.y, endPos.y do
            if Tile({x=i, y=j, z=startPos.z}) then
                table.insert(positions, {x=i, y=j, z=startPos.z})
            end
        end
    end
return positions
end

local fungusArea = {}
for x=1, #fungusAreas do
    fungusArea[x] = createSquarePosTabel2(fungusAreas[x][1], fungusAreas[x][2])
end

function getFungusInArea(player)
local fungusID = {13592, 13598, 13599, 13600, 13585, 13586, 13587, 13588, 13589, 13593}

    for area, t in pairs(fungusArea) do
        for i, position in pairs(t) do
            for x=1, #fungusID do
                if Tile(position):getItemById(fungusID[x]) then
                    return player:say('true...', TALKTYPE_MONSTER_SAY)
                end
            end
        end
    end
    player:say('false ...', TALKTYPE_MONSTER_SAY)
    return false
end
 
Could be here some typos, nor didn't test it. But should be easy enough to understand and fix.

Code:
fungusAreas = { --{{top left corner}, {bottom right corner}} YOU CAN CHOOSE NONTILE AREAS, just make sure square covers entire area.
    {{x=1,y=1,z=9},{x=3,y=3,z=9}},
    {{x=1,y=1,z=9},{x=3,y=3,z=9}},
end

-- Create x*y position table
function createSquarePosTabel2(startPos, endPos)
local positions = {}

    for i=startPos.x, endPos.x do
        for j=startPos.y, endPos.y do
            if Tile({x=i, y=j, z=startPos.z}) then
                table.insert(positions, {x=i, y=j, z=startPos.z})
            end
        end
    end
return positions
end

local fungusArea = {}
for x=1, #fungusAreas do
    fungusArea[x] = createSquarePosTabel2(fungusAreas[x][1], fungusAreas[x][2])
end

function getFungusInArea(player)
local fungusID = {13592, 13598, 13599, 13600, 13585, 13586, 13587, 13588, 13589, 13593}

    for area, t in pairs(fungusArea) do
        for i, position in pairs(t) do
            for x=1, #fungusID do
                if Tile(position):getItemById(fungusID[x]) then
                    return player:say('true...', TALKTYPE_MONSTER_SAY)
                end
            end
        end
    end
    player:say('false ...', TALKTYPE_MONSTER_SAY)
    return false
end
GREAT!!!! IT WORK, I find the error, was my bad :(
I call the function before remove the fungus, so the function will try find before I remove it, always will return true, will try find when have a fungus, when I put the call later works perfectly!
 
Last edited:
Back
Top