• 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+ boss room check

T

Tibia Demon

Guest
i am trying to check if 1 of the 4 player made boss then it stop team from going inside but it tp 1 player inside [the one with no storage] so i have something wrong. can someone help with this and help to add a check if players inside the room then no other teams can enter.
Lua:
local config = {
    playerPositions = {
        Position(989, 1011, 7),
        Position(987, 1011, 7),
        Position(989, 1016, 7),
        Position(987, 1016, 7),
    },
    newPositions = {
        Position(988, 1020, 7),
        Position(987, 1020, 7),
        Position(988, 1021, 7),
        Position(987, 1021, 7),
    },
    items = {
        {position = Position(989, 1010, 7), itemid = 1950},
        {position = Position(987, 1010, 7), itemid = 1950},
        {position = Position(989, 1017, 7), itemid = 1950},
        {position = Position(987, 1017, 7), itemid = 1950},
    },
}

local BossLever = Action()
function BossLever.onUse(player, item, fromPosition, target, toPosition, isHotkey)
        if not player or player:isInGhostMode() then
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            return true
        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:getPosition():sendMagicEffect(CONST_ME_POFF)
               return true
        end
               storePlayers[#storePlayers + 1] = playerTile
        end
        local requiredItems, foundItem = {}
        for _, requiredItem in ipairs(config.items) do
            foundItem = Tile(requiredItem.position):getItemById(requiredItem.itemid)
        if foundItem == nil then
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            return true
        end
            requiredItems[#requiredItems + 1] = foundItem
        end
        local players
        for i = 1, #storePlayers do
            players = storePlayers[i]
        if players and players:getStorageValue(PlayerStorageKeys.bossfourplayers) == 1 then
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            return true
        end
        for _, itemToRemove in ipairs(requiredItems) do
            itemToRemove:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
            itemToRemove:remove(1)
        end
            players:teleportTo(config.newPositions[i])
            players:setDirection(DIRECTION_EAST)
            players:setStorageValue(PlayerStorageKeys.bossfourplayers, 1)
        end
            item:transform(item.itemid == 1946 and 1945 or 1946)
    return true
end
BossLever:aid(5892)
BossLever:register()
and kick players inside room after 15 minutes. i think this need 1 more script check?
 
Last edited by a moderator:
Solution
You should take some time and learn how to tab your scripts properly.
If you are spending 80%+ of your time reading your scripts, You want that process to be as easy as possible.
Lua Beautifier Online (https://codebeautify.org/lua-beautifier) is a decent website to help you learn.

As far as the script is concerned, you should check everything about the player requirements, before adding the player to the table.
So, check that a player is on the tile, check if that player has the correct storage, check that this player also has the correct item...
If all these checks go through, then add them to the table, and check the next player.

Only after all players are checked and confirmed to be able to go through, that is when you remove...
You should take some time and learn how to tab your scripts properly.
If you are spending 80%+ of your time reading your scripts, You want that process to be as easy as possible.
Lua Beautifier Online (https://codebeautify.org/lua-beautifier) is a decent website to help you learn.

As far as the script is concerned, you should check everything about the player requirements, before adding the player to the table.
So, check that a player is on the tile, check if that player has the correct storage, check that this player also has the correct item...
If all these checks go through, then add them to the table, and check the next player.

Only after all players are checked and confirmed to be able to go through, that is when you remove items, change storages, set direction and teleport them.
 
Solution
i am sorry for bad looking script and thank you for the tips.
i tested script and it work like this 100%
Lua:
local config = {
   playerPositions = {
      Position(989, 1011, 7),
      Position(987, 1011, 7),
      Position(989, 1016, 7),
      Position(987, 1016, 7),
   },
   newPositions = {
      Position(988, 1020, 7),
      Position(987, 1020, 7),
      Position(988, 1021, 7),
      Position(987, 1021, 7),
   },
   items = {
      {position = Position(989, 1010, 7), itemid = 1950},
      {position = Position(987, 1010, 7), itemid = 1950},
      {position = Position(989, 1017, 7), itemid = 1950},
      {position = Position(987, 1017, 7), itemid = 1950},
   },
}

local BossLever = Action()
function BossLever.onUse(player, item, fromPosition, target, toPosition, isHotkey)
   if not player or player:isInGhostMode() then
      player:getPosition():sendMagicEffect(CONST_ME_POFF)
      return true
   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:getPosition():sendMagicEffect(CONST_ME_POFF)
         return true
      end
      storePlayers[#storePlayers + 1] = playerTile
   end
   local requiredItems, foundItem = {}
   for _, requiredItem in ipairs(config.items) do
      foundItem = Tile(requiredItem.position):getItemById(requiredItem.itemid)
      if foundItem == nil then
         player:getPosition():sendMagicEffect(CONST_ME_POFF)
         return true
      end
      requiredItems[#requiredItems + 1] = foundItem
   end
   for _, itemToRemove in ipairs(requiredItems) do
      itemToRemove:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
      itemToRemove:remove(1)
   end
   local players
   for i = 1, #storePlayers do
      players = storePlayers[i]
      players:teleportTo(config.newPositions[i])
      players:setDirection(DIRECTION_EAST)
      players:setStorageValue(PlayerStorageKeys.bossfourplayers, 1)
   end
   item:transform(item.itemid == 1946 and 1945 or 1946)
   return true
end
BossLever:aid(5892)
BossLever:register()
but when i try add this check shits start
Lua:
if players and players:getStorageValue(PlayerStorageKeys.bossfourplayers) == 1 then
   player:getPosition():sendMagicEffect(CONST_ME_POFF)
   return true
end
if i add after remove item check it remove item and dont tp players
if i add before remove item check it tp 1 player only not 4
i didnt try to add the check player inside room because this one not working so i try this first.
 
i am sorry for bad looking script and thank you for the tips.
i tested script and it work like this 100%
Lua:
local config = {
   playerPositions = {
      Position(989, 1011, 7),
      Position(987, 1011, 7),
      Position(989, 1016, 7),
      Position(987, 1016, 7),
   },
   newPositions = {
      Position(988, 1020, 7),
      Position(987, 1020, 7),
      Position(988, 1021, 7),
      Position(987, 1021, 7),
   },
   items = {
      {position = Position(989, 1010, 7), itemid = 1950},
      {position = Position(987, 1010, 7), itemid = 1950},
      {position = Position(989, 1017, 7), itemid = 1950},
      {position = Position(987, 1017, 7), itemid = 1950},
   },
}

local BossLever = Action()
function BossLever.onUse(player, item, fromPosition, target, toPosition, isHotkey)
   if not player or player:isInGhostMode() then
      player:getPosition():sendMagicEffect(CONST_ME_POFF)
      return true
   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:getPosition():sendMagicEffect(CONST_ME_POFF)
         return true
      end
      storePlayers[#storePlayers + 1] = playerTile
   end
   local requiredItems, foundItem = {}
   for _, requiredItem in ipairs(config.items) do
      foundItem = Tile(requiredItem.position):getItemById(requiredItem.itemid)
      if foundItem == nil then
         player:getPosition():sendMagicEffect(CONST_ME_POFF)
         return true
      end
      requiredItems[#requiredItems + 1] = foundItem
   end
   for _, itemToRemove in ipairs(requiredItems) do
      itemToRemove:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
      itemToRemove:remove(1)
   end
   local players
   for i = 1, #storePlayers do
      players = storePlayers[i]
      players:teleportTo(config.newPositions[i])
      players:setDirection(DIRECTION_EAST)
      players:setStorageValue(PlayerStorageKeys.bossfourplayers, 1)
   end
   item:transform(item.itemid == 1946 and 1945 or 1946)
   return true
end
BossLever:aid(5892)
BossLever:register()
but when i try add this check shits start
Lua:
if players and players:getStorageValue(PlayerStorageKeys.bossfourplayers) == 1 then
   player:getPosition():sendMagicEffect(CONST_ME_POFF)
   return true
end
if i add after remove item check it remove item and dont tp players
if i add before remove item check it tp 1 player only not 4
i didnt try to add the check player inside room because this one not working so i try this first.
As far as the script is concerned, you should check everything about the player requirements, before adding the player to the table.
So, check that a player is on the tile, check if that player has the correct storage, check that this player also has the correct item...
If all these checks go through, then add them to the table, and check the next player.
Lua:
    local storePlayers, playerTile = {}
    for i = 1, #config.playerPositions do
        playerTile = Tile(config.playerPositions[i]):getTopCreature()
        if not playerTile or not playerTile:isPlayer() then
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            return true
        end
        -- this is where you should check for the player storage
        storePlayers[#storePlayers + 1] = playerTile -- ie, before the player is added to the table.
    end
Lua:
if playerTile:getStorageValue(PlayerStorageKeys.bossfourplayers) == 1 then
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    return true
end
 
thank you it work now for checking if players enter before like this.
Lua:
local config = {
   playerPositions = {
      Position(989, 1011, 7),
      Position(987, 1011, 7),
      Position(989, 1016, 7),
      Position(987, 1016, 7),
   },
   newPositions = {
      Position(988, 1020, 7),
      Position(987, 1020, 7),
      Position(988, 1021, 7),
      Position(987, 1021, 7),
   },
   items = {
      {position = Position(989, 1010, 7), itemid = 1950},
      {position = Position(987, 1010, 7), itemid = 1950},
      {position = Position(989, 1017, 7), itemid = 1950},
      {position = Position(987, 1017, 7), itemid = 1950},
   },
}

local BossLever = Action()
function BossLever.onUse(player, item, fromPosition, target, toPosition, isHotkey)
   if not player or player:isInGhostMode() then
      player:getPosition():sendMagicEffect(CONST_ME_POFF)
      return true
   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:getPosition():sendMagicEffect(CONST_ME_POFF)
         return true
      end
      if playerTile:getStorageValue(PlayerStorageKeys.bossfourplayers) == 1 then
         player:getPosition():sendMagicEffect(CONST_ME_POFF)
         return true
      end
      storePlayers[#storePlayers + 1] = playerTile
   end
   local requiredItems, foundItem = {}
   for _, requiredItem in ipairs(config.items) do
      foundItem = Tile(requiredItem.position):getItemById(requiredItem.itemid)
      if foundItem == nil then
         player:getPosition():sendMagicEffect(CONST_ME_POFF)
         return true
      end
      requiredItems[#requiredItems + 1] = foundItem
   end
   for _, itemToRemove in ipairs(requiredItems) do
      itemToRemove:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
      itemToRemove:remove(1)
   end
   local players
   for i = 1, #storePlayers do
      players = storePlayers[i]
      players:teleportTo(config.newPositions[i])
      players:setDirection(DIRECTION_EAST)
      players:setStorageValue(PlayerStorageKeys.bossfourplayers, 1)
   end
   item:transform(item.itemid == 1946 and 1945 or 1946)
   return true
end
BossLever:aid(5892)
BossLever:register()
but sometimes when only 1 player didn't enter it check this
Lua:
if not playerTile or not playerTile:isPlayer() then
before this
Lua:
if playerTile:getStorageValue(PlayerStorageKeys.bossfourplayers) == 1 then
i try check players inside rooms too [it is few rooms not 1 only so i try with table] but cant make this work
Lua:
local config = {
   playerPositions = {
      Position(989, 1011, 7),
      Position(987, 1011, 7),
      Position(989, 1016, 7),
      Position(987, 1016, 7),
   },
   newPositions = {
      Position(988, 1020, 7),
      Position(987, 1020, 7),
      Position(988, 1021, 7),
      Position(987, 1021, 7),
   },
   items = {
      {position = Position(989, 1010, 7), itemid = 1950},
      {position = Position(987, 1010, 7), itemid = 1950},
      {position = Position(989, 1017, 7), itemid = 1950},
      {position = Position(987, 1017, 7), itemid = 1950},
   },
   allinsiderooms = {
      {
         fromRoomPositionArea = Position(992, 988, 5), -- fromPosition
         toRoomPositionArea = Position(994, 990, 5), -- toPosition
      },
      {
         fromRoomPositionArea = Position(987, 1020, 7), -- fromPosition
         toRoomPositionArea = Position(988, 1021, 7), -- toPosition
      }
   },
}
for v, k in pairs(config) do
   if player:getPosition():isInRange(k.fromRoomPositionArea, k.toRoomPositionArea) then
      player:getPosition():sendMagicEffect(CONST_ME_POFF)
      end
      return true
   end
 
Last edited by a moderator:
how i check spectators here?
Lua:
allinsiderooms = {
   {
      fromRoomPositionArea = Position(992, 988, 5), -- fromPosition
      toRoomPositionArea = Position(994, 990, 5), -- toPosition
   },
   {
      fromRoomPositionArea = Position(987, 1020, 7), -- fromPosition
      toRoomPositionArea = Position(988, 1021, 7), -- toPosition
   }
},
}
for v, k in pairs(config) do
if spectators:getPosition():isInRange(k.fromRoomPositionArea, k.toRoomPositionArea) then
   player:getPosition():sendMagicEffect(CONST_ME_POFF)
end
return true
end
i know how to check like this but i need to check 10 rooms with changed sizes so from northwest to southeast but idk how
Lua:
local checkinside = Game.getSpectators(Position(config.centerRoom), false, false, 7, 7, 7, 7)
Post automatically merged:

i made it using Game.getSpectators it is not the way i needed but this is how i could make it. only problem is now all rooms i check need to be like same size but all work good.
if someone can revise it or change something to better like check room frompos topos or anything else.
Lua:
local config = {
   playerPositions = {
      Position(989, 1011, 7),
      Position(987, 1011, 7),
      Position(989, 1016, 7),
      Position(987, 1016, 7),
   },
   newPositions = {
      Position(988, 1020, 7),
      Position(987, 1020, 7),
      Position(988, 1021, 7),
      Position(987, 1021, 7),
   },
   items = {
      {position = Position(989, 1010, 7), itemid = 1950},
      {position = Position(987, 1010, 7), itemid = 1950},
      {position = Position(989, 1017, 7), itemid = 1950},
      {position = Position(987, 1017, 7), itemid = 1950},
   },
   centrePositions = {
      Position(975, 1011, 7),
      Position(987, 1012, 9)
   },
}

local BossLever = Action()
function BossLever.onUse(player, item, fromPosition, target, toPosition, isHotkey)
   if not player or player:isInGhostMode() then
      player:getPosition():sendMagicEffect(CONST_ME_POFF)
      return true
   end
   for i = 1, #config.centrePositions do
      local spectators = Game.getSpectators(config.centrePositions[i], false, false, 5, 5, 7, 7)
      for i = 1, #spectators do
         if spectators[i]:isPlayer() then
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            return true
         end
      end
   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:getPosition():sendMagicEffect(CONST_ME_POFF)
         return true
      end
      if playerTile:getStorageValue(PlayerStorageKeys.bossfourplayers) == 1 then
         player:getPosition():sendMagicEffect(CONST_ME_POFF)
         return true
      end
      storePlayers[#storePlayers + 1] = playerTile
   end
   local requiredItems, foundItem = {}
   for _, requiredItem in ipairs(config.items) do
      foundItem = Tile(requiredItem.position):getItemById(requiredItem.itemid)
      if foundItem == nil then
         player:getPosition():sendMagicEffect(CONST_ME_POFF)
         return true
      end
      requiredItems[#requiredItems + 1] = foundItem
   end
   for _, itemToRemove in ipairs(requiredItems) do
      itemToRemove:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
      itemToRemove:remove(1)
   end
   local players
   for i = 1, #storePlayers do
      players = storePlayers[i]
      players:teleportTo(config.newPositions[i])
      players:setDirection(DIRECTION_EAST)
      players:setStorageValue(PlayerStorageKeys.bossfourplayers, 1)
   end
   item:transform(item.itemid == 1946 and 1945 or 1946)
   return true
end
BossLever:aid(5892)
BossLever:register()
 
Last edited by a moderator:
done made it read rooms with diff size too. change like this.
Lua:
centrePositions = {
   {Position(975, 1011, 7), 5},
   {Position(987, 1012, 9), 7}
},
local spectators = Game.getSpectators(config.centrePositions[i][1], false, false, config.centrePositions[i][2], config.centrePositions[i][2], config.centrePositions[i][2], config.centrePositions[i][2])
if i made anything wrong tell me how to correct.
and if some1 can help with this. it is for same script but time checker for all rooms.
 
Back
Top