• 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.X+ golden prison key doesnt dissapear if used in ground

Thorn

Spriting since 2013
Joined
Sep 24, 2012
Messages
2,203
Solutions
1
Reaction score
922
Location
Chile
hello guys, im using tfs 1.3 and i got this script from otx global, but it has a bug and i have no idea how to fix it

if the person uses the key in the shrine (key in his bp) it dissapears, but if the player put the key in the ground and use it on the shrine, the key remains in the floor :S

is there anyway to fix this? making the key dissapear or making imopssible to use it from the ground? :S

Code:
local function isPlayerInArea(fromPos, toPos)
    for _x = fromPos.x, toPos.x do
        for _y = fromPos.y, toPos.y do
            for _z = fromPos.z, toPos.z do
                creature = getTopCreature({x = _x, y = _y, z = _z})
                    if (isPlayer(creature.uid)) then
                    return true
                end
            end
        end
    end
    return false
end



function onUse(cid, item, fromPosition, itemEx)
    local player = Player(cid)
    if not player then
        return true
    end
        if(item.itemid == 22607) then
        if(itemEx.itemid == 22641) then
            if player:getStorageValue(1) and not isPlayerInArea({x = 545, y = 1689, z = 12, stackpos = 255}, {x = 564, y = 1704, z = 12, stackpos = 255}) then
                pos1 = {x = 633, y = 1724, z = getCreaturePosition(cid).z}
                pos2 = {x = 634, y = 1724, z = getCreaturePosition(cid).z}
                pos3 = {x = 635, y = 1724, z = getCreaturePosition(cid).z}
                pos4 = {x = 636, y = 1724, z = getCreaturePosition(cid).z}
                pos5 = {x = 637, y = 1724, z = getCreaturePosition(cid).z}
                if(isPlayer(getTopCreature(pos1).uid)) then
                if(isPlayer(getTopCreature(pos2).uid)) then
                if(isPlayer(getTopCreature(pos3).uid)) then
                if(isPlayer(getTopCreature(pos4).uid)) then
                if(isPlayer(getTopCreature(pos5).uid)) then
                    doTeleportThing(getTopCreature(pos1).uid, {x = 554, y = 1703, z = 12})
                    doTeleportThing(getTopCreature(pos2).uid, {x = 554, y = 1703, z = 12})
                    doTeleportThing(getTopCreature(pos3).uid, {x = 554, y = 1703, z = 12})
                    doTeleportThing(getTopCreature(pos4).uid, {x = 554, y = 1703, z = 12})
                    doTeleportThing(getTopCreature(pos5).uid, {x = 554, y = 1703, z = 12})
           -- doSummonCreature("prince drazzak", {x=33528, y=32333, z=12})
           local monster = Game.createMonster("Jiren", Position(554, 1695, 12)) 
            monster:setReward(true)
            doRemoveItem(item.uid, 1)
            end
            end
           end
      end
     end
end
end
end
    return true
end
 
Not tested !
LUA:
local config = {
    centerPos = Position(548, 1705, 12),
    rangeX = 10,
    rangeY = 10,
    playerPositions = {
        Position(633, 1724, 12),
        Position(634, 1724, 12),
        Position(635, 1724, 12),
        Position(636, 1724, 12)
        Position(637, 1724, 12)
    },
    newPositions = {
        Position(554, 1703, 12),
        Position(554, 1703, 12),
        Position(554, 1703, 12),
        Position(554, 1703, 12)
    }
}

local function isPlayerInArea(centerPos, rangeX, rangeY)
    local spectators = Game.getSpectators(centerPos, false, true, rangeX, rangeX, rangeY, rangeY)
    for i = 1, #spectators do
        local spec = spectators[i]
        if spec:isPlayer() then
            return true
        end
    end
    return false
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid ~= 22641 then
        return false
    end

    if isPlayerInArea(config.centerPos, config.rangeX, config.rangeY) then
        return false
    end
   
    local storePlayers, playerTile = {}
    for i = 1, #config.playerPositions do
        playerTile = Tile(config.playerPositions[i]):getTopCreature()
        if not playerTile or not playerTile:isPlayer() then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need 4 players.")
            return true
        end

        storePlayers[#storePlayers + 1] = playerTile
    end

    item:remove(1)
    local players
    for i = 1, #storePlayers do
        players = storePlayers[i]
        config.playerPositions[i]:sendMagicEffect(CONST_ME_POFF)
        players:teleportTo(config.newPositions[i])
        config.newPositions[i]:sendMagicEffect(CONST_ME_ENERGYAREA)
    end

    local monster = Game.createMonster("Jiren", Position(554, 1695, 12))
    monster:setReward(true)
    return true
end
 
Last edited:
I quote what @Mark told me a while ago

Always use getSpectators for that task. getSpectators is highly optimized for that task and getTopCreature will miss creatures that are standing in a stack (as the function name says topcreature)
 
oh yeah, I agree, I know how that function works, I put it that way, because there was no notion of the proportion of the boss's room, but it's easy to be corrected. And thank you for your note!


I edit my post
Great that you took the feedback. Since you ticked the option onlyPlayers. Then you can only do this, instead of checking inside a loop:
Code:
local function isPlayerInArea(centerPos, rangeX, rangeY)
    local spectators = Game.getSpectators(centerPos, false, true, rangeX, rangeX, rangeY, rangeY)
    return #spectators != 0 and true or false
end
 
Great that you took the feedback. Since you ticked the option onlyPlayers. Then you can only do this, instead of checking inside a loop:
Code:
local function isPlayerInArea(centerPos, rangeX, rangeY)
    local spectators = Game.getSpectators(centerPos, false, true, rangeX, rangeX, rangeY, rangeY)
    return #spectators != 0 and true or false
end
oh great ! every day we learn more and more !
 
Not tested !
LUA:
local config = {
    centerPos = Position(548, 1705, 12),
    rangeX = 10,
    rangeY = 10,
    playerPositions = {
        Position(633, 1724, 12),
        Position(634, 1724, 12),
        Position(635, 1724, 12),
        Position(636, 1724, 12)
        Position(637, 1724, 12)
    },
    newPositions = {
        Position(554, 1703, 12),
        Position(554, 1703, 12),
        Position(554, 1703, 12),
        Position(554, 1703, 12)
    }
}

local function isPlayerInArea(centerPos, rangeX, rangeY)
    local spectators = Game.getSpectators(centerPos, false, true, rangeX, rangeX, rangeY, rangeY)
    for i = 1, #spectators do
        local spec = spectators[i]
        if spec:isPlayer() then
            return true
        end
    end
    return false
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid ~= 22641 then
        return false
    end

    if isPlayerInArea(config.centerPos, config.rangeX, config.rangeY) then
        return false
    end
  
    local storePlayers, playerTile = {}
    for i = 1, #config.playerPositions do
        playerTile = Tile(config.playerPositions[i]):getTopCreature()
        if not playerTile or not playerTile:isPlayer() then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need 4 players.")
            return true
        end

        storePlayers[#storePlayers + 1] = playerTile
    end

    item:remove(1)
    local players
    for i = 1, #storePlayers do
        players = storePlayers[i]
        config.playerPositions[i]:sendMagicEffect(CONST_ME_POFF)
        players:teleportTo(config.newPositions[i])
        config.newPositions[i]:sendMagicEffect(CONST_ME_ENERGYAREA)
    end

    local monster = Game.createMonster("Jiren", Position(554, 1695, 12))
    monster:setReward(true)
    return true
end

hello man thanks for taking the time! i added another new position that i think was missing xD
but i get an error, here is the code

LUA:
local config = {
    centerPos = Position(548, 1705, 12),
    rangeX = 10,
    rangeY = 10,
    playerPositions = {
        Position(633, 1724, 12),
        Position(634, 1724, 12),
        Position(635, 1724, 12),
        Position(636, 1724, 12)
        Position(637, 1724, 12)
    },
    newPositions = {
        Position(554, 1703, 12),
        Position(554, 1703, 12),
        Position(554, 1703, 12),
        Position(554, 1703, 12),
        Position(554, 1703, 12)
    }
}
local function isPlayerInArea(centerPos, rangeX, rangeY)
    local spectators = Game.getSpectators(centerPos, false, true, rangeX, rangeX, rangeY, rangeY)
    for i = 1, #spectators do
        local spec = spectators[i]
        if spec:isPlayer() then
            return true
        end
    end
    return false
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid ~= 22641 then
        return false
    end
    if isPlayerInArea(config.centerPos, config.rangeX, config.rangeY) then
        return false
    end
  
    local storePlayers, playerTile = {}
    for i = 1, #config.playerPositions do
        playerTile = Tile(config.playerPositions[i]):getTopCreature()
        if not playerTile or not playerTile:isPlayer() then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need 4 players.")
            return true
        end
        storePlayers[#storePlayers + 1] = playerTile
    end
    item:remove(1)
    local players
    for i = 1, #storePlayers do
        players = storePlayers[i]
        config.playerPositions[i]:sendMagicEffect(CONST_ME_POFF)
        players:teleportTo(config.newPositions[i])
        config.newPositions[i]:sendMagicEffect(CONST_ME_ENERGYAREA)
    end
    local monster = Game.createMonster("Jiren", Position(554, 1695, 12))
    monster:setReward(true)
    return true
end

and the error
Code:
[Warning - Event::checkScript] Can not load script: scripts/prison/golden.lua
data/actions/scripts/prison/golden.lua:10: '}' expected (to close '{' at line 5) near 'Position'
 
LUA:
local config = {
    centerPos = Position(548, 1705, 12),
    rangeX = 10,
    rangeY = 10,
    playerPositions = {
        Position(633, 1724, 12),
        Position(634, 1724, 12),
        Position(635, 1724, 12),
        Position(636, 1724, 12),
        Position(637, 1724, 12)
    },
    newPositions = {
        Position(554, 1703, 12),
        Position(554, 1703, 12),
        Position(554, 1703, 12),
        Position(554, 1703, 12),
        Position(554, 1703, 12)
    }
}

local function isPlayerInArea(centerPos, rangeX, rangeY)
    local spectators = Game.getSpectators(centerPos, false, true, rangeX, rangeX, rangeY, rangeY)
    return #spectators ~= 0 and true or false
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid ~= 22641 then
        return false
    end
    if isPlayerInArea(config.centerPos, config.rangeX, config.rangeY) then
        return false
    end
    local storePlayers, playerTile = {}
    for i = 1, #config.playerPositions do
        playerTile = Tile(config.playerPositions[i]):getTopCreature()
        if not playerTile or not playerTile:isPlayer() then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need 4 players.")
            return true
        end
        storePlayers[#storePlayers + 1] = playerTile
    end
    item:remove(1)
    local players
    for i = 1, #storePlayers do
        players = storePlayers[i]
        config.playerPositions[i]:sendMagicEffect(CONST_ME_POFF)
        players:teleportTo(config.newPositions[i])
        config.newPositions[i]:sendMagicEffect(CONST_ME_ENERGYAREA)
    end
    local monster = Game.createMonster("Jiren", Position(554, 1695, 12))
    monster:setReward(true)
    return true
end
 
Back
Top