• 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 How to allow to spawn only on tile

Tbol

Well-Known Member
Joined
Apr 7, 2019
Messages
529
Reaction score
56
Hello, I created this code that I found from Oen and edited it a bit. I'm wondering how I can prevent it from spawning on trees and other objects. Is it possible to allow it to spawn only on walkable ground? I've tried something like this, but it still spawns on stairs or mountains.

Basically this code spawns in area x,y,z and in radius of 6 and it allows only to spawn 10 objects in that area
Lua:
CURSED_CHESTS_AID = 9000

CURSED_CHESTS_SPAWNS = {
    [1] = {
        pos = Position(96, 210, 7),
        radius = 6,
        limit = 10,
        item = 19512,
        spawnedCount = 0
    }
}

function onThink(cid, interval, lastExecution)
    for _, data in pairs(CURSED_CHESTS_SPAWNS) do
        if data.spawnedCount < data.limit then
            local spawnPos = Position(data.pos.x + math.random(-data.radius, data.radius), data.pos.y + math.random(-data.radius, data.radius), data.pos.z)

            local tile = Tile(spawnPos)
            if tile and tile:getGround() then
                local chest = Game.createItem(data.item, 1, spawnPos)
                if chest then
                    chest:setActionId(CURSED_CHESTS_AID)
                    data.spawnedCount = data.spawnedCount + 1
                end
            end
        end
    end

    return true
end
 
So this is the last result. Anyone see a way how to optimize this code? Because i think i havent writen it well
Lua:
CURSED_CHESTS_AID = 9000

CURSED_CHESTS_SPAWNS = {
    [1] = {
        pos = Position(96, 210, 7),
        radius = 6,
        limit = 10,
        item = 19512,
        spawnedCount = 0
    }
}

function onThink(cid, interval, lastExecution)
    for _, data in pairs(CURSED_CHESTS_SPAWNS) do
        if data.spawnedCount < data.limit then
            local spawnPos = Position(data.pos.x + math.random(-data.radius, data.radius), data.pos.y + math.random(-data.radius, data.radius), data.pos.z)

            local tile = Tile(spawnPos)
            if tile and tile:isWalkable() then
                local chest = Game.createItem(data.item, 1, spawnPos)
                if chest then
                    chest:setActionId(CURSED_CHESTS_AID)
                    data.spawnedCount = data.spawnedCount + 1
                end
            end
        end
    end

    return true
end
 
Back
Top