• 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+ access fromposition toposition only with storage

T

Tibia Demon

Guest
i want to check when player trying to move any sqm fromposition toposition area if they have storage then allow move but if they dont have storage then return true. this is the storages [43040] -- [43342] every storage allow to access it's position range tiles only
Lua:
local AccessStep = MoveEvent()
AccessStep:type("stepin")

local GoAccess = {
    [43040] = {accesstilefromPosition = {x = 2010, y = 789, z = 8}, accesstiletoPosition = {x = 2020, y = 789, z = 8}},
    [43342] = {accesstilefromPosition = {x = 2215, y = 631, z = 7}, accesstiletoPosition = {x = 2230, y = 631, z = 7}},
}

function AccessStep.onStepIn(player, item, position, fromPosition)
    local AccessStep = GoAccess[getStorageValue()]
    if not player or player:isInGhostMode() then
        return true
    end
    if position:isInRange(GoAccess.accesstilefromPosition, GoAccess.accesstiletoPosition) then
    if not player:getStorageValue(AccessStep) == 1 then
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            player:teleportTo(fromPosition)
            player:sendCancelMessage("You cant access this area.")
            return true
        end
    return true
end
end

AccessStep:register()
or i need to add actionid to all tiles fromposition toposition?
it is 10 storage and 10 places i dont need to make 10 scripts so i try tables but idk how to fix it.
 
Last edited by a moderator:
Solution
i want to check when player trying to move any sqm fromposition toposition area if they have storage then allow move but if they dont have storage then return true. this is the storages [43040] -- [43342] every storage allow to access it's position range tiles only
Lua:
local AccessStep = MoveEvent()
AccessStep:type("stepin")

local GoAccess = {
    [43040] = {accesstilefromPosition = {x = 2010, y = 789, z = 8}, accesstiletoPosition = {x = 2020, y = 789, z = 8}},
    [43342] = {accesstilefromPosition = {x = 2215, y = 631, z = 7}, accesstiletoPosition = {x = 2230, y = 631, z = 7}},
}

function AccessStep.onStepIn(player, item, position, fromPosition)
    local AccessStep = GoAccess[getStorageValue()]
    if not player or player:isInGhostMode() then...
i want to check when player trying to move any sqm fromposition toposition area if they have storage then allow move but if they dont have storage then return true. this is the storages [43040] -- [43342] every storage allow to access it's position range tiles only
Lua:
local AccessStep = MoveEvent()
AccessStep:type("stepin")

local GoAccess = {
    [43040] = {accesstilefromPosition = {x = 2010, y = 789, z = 8}, accesstiletoPosition = {x = 2020, y = 789, z = 8}},
    [43342] = {accesstilefromPosition = {x = 2215, y = 631, z = 7}, accesstiletoPosition = {x = 2230, y = 631, z = 7}},
}

function AccessStep.onStepIn(player, item, position, fromPosition)
    local AccessStep = GoAccess[getStorageValue()]
    if not player or player:isInGhostMode() then
        return true
    end
    if position:isInRange(GoAccess.accesstilefromPosition, GoAccess.accesstiletoPosition) then
    if not player:getStorageValue(AccessStep) == 1 then
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            player:teleportTo(fromPosition)
            player:sendCancelMessage("You cant access this area.")
            return true
        end
    return true
end
end

AccessStep:register()
or i need to add actionid to all tiles fromposition toposition?
it is 10 storage and 10 places i dont need to make 10 scripts so i try tables but idk how to fix it.
On every tile you want to trigger this script, you'd want to use an actionId on the tile. (only 1 actionId required for each area) (optionally you could use a single itemId, but that is wasteful.)

With this setup, you'd add to your script above AccessStep:register -> AccessStep:aid(11111111) -- 11's being the actionId you want to use.

Of course, we'd want to loop through the table, and have this done automatically..

so do this
Lua:
for actionId, _ in pairs(GoAccess) do
    AccessStep:aid(actionId)
end

And your table would need to change to reflect this.
Lua:
local GoAccess = {
  --[actionId]
    [45001] = {storage = 43040, accesstilefromPosition = {x = 2010, y = 789, z = 8}, accesstiletoPosition = {x = 2020, y = 789, z = 8}},
    [45002] = {storage = 43342, accesstilefromPosition = {x = 2215, y = 631, z = 7}, accesstiletoPosition = {x = 2230, y = 631, z = 7}},
}

Now, the problem with this entire scenario, is that the action 'onStepIn', is already checking if the player/creature stepping on the tile is in the area.. So the entire check to see if they are in the area, is pointless.

Typically instead of checking an entire area, you only place this tile at an impassable area, like a bridge / doorway / tunnel, so it's less work. Think of the rookgaard premium bridge.

So instead, your script would turn into this
Lua:
local AccessStep = MoveEvent()
AccessStep:type("stepin")

local GoAccess = {
  --[actionId]
    [45001] = {storage = 43040},
    [45002] = {storage = 43342},
}

function AccessStep.onStepIn(player, item, position, fromPosition)
    if not player or player:isInGhostMode() then
        return true
    end
  
    if player:getStorageValue(GoAccess[item:getActionId()].storage) == 1 then
        return true
    end
  
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    player:teleportTo(fromPosition)
    player:sendCancelMessage("You can't access this area.")
    return true
end

for actionId, _ in pairs(GoAccess) do
    AccessStep:aid(actionId)
end
AccessStep:register()
Post automatically merged:

Or sorry, there is another way, using your positions and a single actionId, but you have to put the actionId on every single tile.
Lua:
local AccessStep = MoveEvent()
AccessStep:type("stepin")

local actionId = 111111
local GoAccess = {
    [43040] = {accesstilefromPosition = {x = 2010, y = 789, z = 8}, accesstiletoPosition = {x = 2020, y = 789, z = 8}},
    [43342] = {accesstilefromPosition = {x = 2215, y = 631, z = 7}, accesstiletoPosition = {x = 2230, y = 631, z = 7}},
}

function AccessStep.onStepIn(player, item, position, fromPosition)
    if not player or player:isInGhostMode() then
        return true
    end
   
    for v, k in pairs(GoAccess) do
        if position:isInRange(k.accesstilefromPosition, k.accesstiletoPosition) then
            if player:getStorageValue(v) ~= 1 then
                player:getPosition():sendMagicEffect(CONST_ME_POFF)
                player:teleportTo(fromPosition)
                player:sendCancelMessage("You cant access this area.")
            end
            return true
        end
    end
    return true
end

AccessStep:aid(actionId)
AccessStep:register()
 
Last edited:
Solution
On every tile you want to trigger this script, you'd want to use an actionId on the tile. (only 1 actionId required for each area) (optionally you could use a single itemId, but that is wasteful.)

With this setup, you'd add to your script above AccessStep:register -> AccessStep:aid(11111111) -- 11's being the actionId you want to use.

Of course, we'd want to loop through the table, and have this done automatically..

so do this
Lua:
for actionId, _ in pairs(GoAccess) do
    AccessStep:aid(actionId)
end

And your table would need to change to reflect this.
Lua:
local GoAccess = {
  --[actionId]
    [45001] = {storage = 43040, accesstilefromPosition = {x = 2010, y = 789, z = 8}, accesstiletoPosition = {x = 2020, y = 789, z = 8}},
    [45002] = {storage = 43342, accesstilefromPosition = {x = 2215, y = 631, z = 7}, accesstiletoPosition = {x = 2230, y = 631, z = 7}},
}

Now, the problem with this entire scenario, is that the action 'onStepIn', is already checking if the player/creature stepping on the tile is in the area.. So the entire check to see if they are in the area, is pointless.

Typically instead of checking an entire area, you only place this tile at an impassable area, like a bridge / doorway / tunnel, so it's less work. Think of the rookgaard premium bridge.

So instead, your script would turn into this
Lua:
local AccessStep = MoveEvent()
AccessStep:type("stepin")

local GoAccess = {
  --[actionId]
    [45001] = {storage = 43040},
    [45002] = {storage = 43342},
}

function AccessStep.onStepIn(player, item, position, fromPosition)
    if not player or player:isInGhostMode() then
        return true
    end
 
    if player:getStorageValue(GoAccess[item:getActionId()].storage) == 1 then
        return true
    end
 
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    player:teleportTo(fromPosition)
    player:sendCancelMessage("You can't access this area.")
    return true
end

for actionId, _ in pairs(GoAccess) do
    AccessStep:aid(actionId)
end
AccessStep:register()
Post automatically merged:

Or sorry, there is another way, using your positions and a single actionId, but you have to put the actionId on every single tile.
Lua:
local AccessStep = MoveEvent()
AccessStep:type("stepin")

local actionId = 111111
local GoAccess = {
    [43040] = {accesstilefromPosition = {x = 2010, y = 789, z = 8}, accesstiletoPosition = {x = 2020, y = 789, z = 8}},
    [43342] = {accesstilefromPosition = {x = 2215, y = 631, z = 7}, accesstiletoPosition = {x = 2230, y = 631, z = 7}},
}

function AccessStep.onStepIn(player, item, position, fromPosition)
    if not player or player:isInGhostMode() then
        return true
    end
 
    for v, k in pairs(GoAccess) do
        if position:isInRange(k.accesstilefromPosition, k.accesstiletoPosition) then
            if player:getStorageValue(AccessStep) ~= 1 then
                player:getPosition():sendMagicEffect(CONST_ME_POFF)
                player:teleportTo(fromPosition)
                player:sendCancelMessage("You cant access this area.")
            end
            return true
        end
    end
    return true
end

AccessStep:aid(actionId)
AccessStep:register()
replace this part:
Lua:
 if player:getStorageValue(AccessStep) ~= 1 then
to:
Lua:
 if player:getStorageValue(v) ~= 1 then
Small mistake @Xikini or im drunk xd
 
On every tile you want to trigger this script, you'd want to use an actionId on the tile. (only 1 actionId required for each area) (optionally you could use a single itemId, but that is wasteful.)

With this setup, you'd add to your script above AccessStep:register -> AccessStep:aid(11111111) -- 11's being the actionId you want to use.

Of course, we'd want to loop through the table, and have this done automatically..

so do this
Lua:
for actionId, _ in pairs(GoAccess) do
    AccessStep:aid(actionId)
end

And your table would need to change to reflect this.
Lua:
local GoAccess = {
  --[actionId]
    [45001] = {storage = 43040, accesstilefromPosition = {x = 2010, y = 789, z = 8}, accesstiletoPosition = {x = 2020, y = 789, z = 8}},
    [45002] = {storage = 43342, accesstilefromPosition = {x = 2215, y = 631, z = 7}, accesstiletoPosition = {x = 2230, y = 631, z = 7}},
}

Now, the problem with this entire scenario, is that the action 'onStepIn', is already checking if the player/creature stepping on the tile is in the area.. So the entire check to see if they are in the area, is pointless.

Typically instead of checking an entire area, you only place this tile at an impassable area, like a bridge / doorway / tunnel, so it's less work. Think of the rookgaard premium bridge.

So instead, your script would turn into this
Lua:
local AccessStep = MoveEvent()
AccessStep:type("stepin")

local GoAccess = {
  --[actionId]
    [45001] = {storage = 43040},
    [45002] = {storage = 43342},
}

function AccessStep.onStepIn(player, item, position, fromPosition)
    if not player or player:isInGhostMode() then
        return true
    end
 
    if player:getStorageValue(GoAccess[item:getActionId()].storage) == 1 then
        return true
    end
 
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    player:teleportTo(fromPosition)
    player:sendCancelMessage("You can't access this area.")
    return true
end

for actionId, _ in pairs(GoAccess) do
    AccessStep:aid(actionId)
end
AccessStep:register()
Post automatically merged:

Or sorry, there is another way, using your positions and a single actionId, but you have to put the actionId on every single tile.
Lua:
local AccessStep = MoveEvent()
AccessStep:type("stepin")

local actionId = 111111
local GoAccess = {
    [43040] = {accesstilefromPosition = {x = 2010, y = 789, z = 8}, accesstiletoPosition = {x = 2020, y = 789, z = 8}},
    [43342] = {accesstilefromPosition = {x = 2215, y = 631, z = 7}, accesstiletoPosition = {x = 2230, y = 631, z = 7}},
}

function AccessStep.onStepIn(player, item, position, fromPosition)
    if not player or player:isInGhostMode() then
        return true
    end
  
    for v, k in pairs(GoAccess) do
        if position:isInRange(k.accesstilefromPosition, k.accesstiletoPosition) then
            if player:getStorageValue(v) ~= 1 then
                player:getPosition():sendMagicEffect(CONST_ME_POFF)
                player:teleportTo(fromPosition)
                player:sendCancelMessage("You cant access this area.")
            end
            return true
        end
    end
    return true
end

AccessStep:aid(actionId)
AccessStep:register()
thank you very much. the 2 work 100% perfect.
 
Back
Top