• 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!

Error fetching Storage from a table

.Smile

Member
Joined
Jan 27, 2019
Messages
29
Reaction score
11
Hello anyone could help me to solve the problem in this code?

It was to perform an action depending on the Storage that the player has but is not working
Lua:
function onStepIn(creature, item, position, fromPosition)
local config = {
--[[Islands]]] --
    [47001] = {townid = 7, storageid = 47001, msg = "Welcome to the Fire Island", pos = {x=29997, y=28758, z=7}},
    [47002] = {townid = 7, storageid = 47002, msg = "Welcome to the Water Island", pos = {x=29846, y=28645, z=7}},
}
local exhaustiontime = 2 -- Exhaustion Time
local exhaustionstorage = 40001 -- Exhaustion Storage
local position = creature:getPosition()
local player = creature:getPlayer()
local cfg = config[player:getStorageValue()]

    if not creature:isPlayer() then
        return false
    end

    if player:getExhaustion(exhaustionstorage) > 0 then
        player:teleportTo(fromPosition, false)
        return true
    end   

    if cfg == 1 then
        player:teleportTo(cfg.pos)
        player:setTown(Town(cfg.townid))
        player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "".. cfg.msg ..".")
        player:setStorageValue(cfg.storageid, -1)
        player:setExhaustion(exhaustionstorage, exhaustiontime)
        Position({x = position.x + 1, y = position.y + 1, z = position.z}):sendMagicEffect(21)
    end
    return true
end


Apparently the problem is in these lines I do not know if I declared it right
Lua:
local cfg = config[player:getStorageValue()]

if cfg == 1 then
 
Hello anyone could help me to solve the problem in this code?

It was to perform an action depending on the Storage that the player has but is not working
Lua:
function onStepIn(creature, item, position, fromPosition)
local config = {
--[[Islands]]] --
    [47001] = {townid = 7, storageid = 47001, msg = "Welcome to the Fire Island", pos = {x=29997, y=28758, z=7}},
    [47002] = {townid = 7, storageid = 47002, msg = "Welcome to the Water Island", pos = {x=29846, y=28645, z=7}},
}
local exhaustiontime = 2 -- Exhaustion Time
local exhaustionstorage = 40001 -- Exhaustion Storage
local position = creature:getPosition()
local player = creature:getPlayer()
local cfg = config[player:getStorageValue()]

    if not creature:isPlayer() then
        return false
    end

    if player:getExhaustion(exhaustionstorage) > 0 then
        player:teleportTo(fromPosition, false)
        return true
    end   

    if cfg == 1 then
        player:teleportTo(cfg.pos)
        player:setTown(Town(cfg.townid))
        player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "".. cfg.msg ..".")
        player:setStorageValue(cfg.storageid, -1)
        player:setExhaustion(exhaustionstorage, exhaustiontime)
        Position({x = position.x + 1, y = position.y + 1, z = position.z}):sendMagicEffect(21)
    end
    return true
end


Apparently the problem is in these lines I do not know if I declared it right
Lua:
local cfg = config[player:getStorageValue()]

if cfg == 1 then
You're not accessing the table correctly.
I'm going to assume that the index is the actionid of the tile?

If that is correct, you'll want to do this..
Lua:
local cfg = player:getStorageValue(config[item.actionid].storageid)
 
You're not accessing the table correctly.
I'm going to assume that the index is the actionid of the tile?

If that is correct, you'll want to do this..
Lua:
local cfg = player:getStorageValue(config[item.actionid].storageid)

Thanks for replying but it did not work.

Actionid's tile is '47000' in code I just want to get the player's storage []
36523
 
Thanks for replying but it did not work.

Actionid's tile is '47000' in code I just want to get the player's storage []
View attachment 36523
Well to get the players storage value you need to use the storage number you are wanting to access.
To do that, we need to access the table you've created.

Currently your index in the table is 47001 and 47002.

When you step on a tile in-game, this triggers this script, right?
What is differentiating different tiles apart?

Is all tiles with actionid 47000, and uniqueid is what differentiates them?
actionid 47000 and uniqueid 4700X?

If that is the case..
Then you want to make the script search for the uniqueid on the tile instead of the actionid.

If that isn't the case.. then we need to know how stepping on one tile is going to teleport you to different locations.

In my experience you either need to use
multiple actionid's
or
multiple uniqueids and 1 actionid.

You could also use storage values in a unique way.. depending on how you set it up.. but it's usually just easier to use aid or uid.

-- wait wait edit..

There's a few other things wrong.
Okay so you want to setup cfg to show the point in the table.
And then use that point as a reference for the rest of the script.

So
Lua:
local cfg = config[item:getUniqueId()] -- if using multiple uniqueid's and 1 actionid
or..
local cfg = config[item:getActionId()] -- if using multiple actionid's

if player:getStorageValue(cfg.storageid) == 1 then
 
Last edited:
Well to get the players storage value you need to use the storage number you are wanting to access.
To do that, we need to access the table you've created.

Currently your index in the table is 47001 and 47002.

When you step on a tile in-game, this triggers this script, right?
What is differentiating different tiles apart?

Is all tiles with actionid 47000, and uniqueid is what differentiates them?
actionid 47000 and uniqueid 4700X?

If that is the case..
Then you want to make the script search for the uniqueid on the tile instead of the actionid.

If that isn't the case.. then we need to know how stepping on one tile is going to teleport you to different locations.

In my experience you either need to use
multiple actionid's
or
multiple uniqueids and 1 actionid.

You could also use storage values in a unique way.. depending on how you set it up.. but it's usually just easier to use aid or uid.

-- wait wait edit..

There's a few other things wrong.
Okay so you want to setup cfg to show the point in the table.
And then use that point as a reference for the rest of the script.

So
Lua:
local cfg = config[item:getUniqueId()] -- if using multiple uniqueid's and 1 actionid
or..
local cfg = config[item:getActionId()] -- if using multiple actionid's

if player:getStorageValue(cfg.storageid) == 1 then

There is no such option to use multiple actionid or uniqueid, it's just one tile, where the player will need to be based on the storage he has.
 
Last edited:
There is no such option to use multiple actionid or uniqueid, it's just one tile, where the player will need to be based on the storage he has.
You're going to need to explain what your doing then.

The way the script is currently, it looks like you're trying to setup multiple 'tiles' to use as a teleport system.

A tile can have the property 'actionid' and 'uniqueid' set to a number value.. and then use that number as the pointer in movements.xml to point it to the script.

If you use multiple actionid's as pointers, you don't need to use uniqueid. caveat is that you'll need to add a new line in movements.xml every time you want to add a new tile.
If you use the same actionid, and a different uniqueid on each tile, then you only need 1 line in movements.xml.

In both of the above cases, you can then use the actionid or uniqueid in order to index a table, which you can then find the storage value you want to check.

If you don't want to use actionid's or uniqueid's.. then you need to create a system that uses your storage value to access the table.
If you're using a storage value, or multiple storage values.. you'll need a way to differentiate the tiles anyway.. which would again require you to use multiple actionid's which correspond to a specific storage value..

Or you'd need to create some sort of complex system for your storage values to not interfere with each other.. because otherwise they'll keep teleporting to the first location on your list of locations, because they already have that storage value.

--

But again, maybe I'm wrong.
If I'm wrong in my assumption, please tell us how your script is supposed to work.
 
You're going to need to explain what your doing then.

The way the script is currently, it looks like you're trying to setup multiple 'tiles' to use as a teleport system.

A tile can have the property 'actionid' and 'uniqueid' set to a number value.. and then use that number as the pointer in movements.xml to point it to the script.

If you use multiple actionid's as pointers, you don't need to use uniqueid. caveat is that you'll need to add a new line in movements.xml every time you want to add a new tile.
If you use the same actionid, and a different uniqueid on each tile, then you only need 1 line in movements.xml.

In both of the above cases, you can then use the actionid or uniqueid in order to index a table, which you can then find the storage value you want to check.

If you don't want to use actionid's or uniqueid's.. then you need to create a system that uses your storage value to access the table.
If you're using a storage value, or multiple storage values.. you'll need a way to differentiate the tiles anyway.. which would again require you to use multiple actionid's which correspond to a specific storage value..

Or you'd need to create some sort of complex system for your storage values to not interfere with each other.. because otherwise they'll keep teleporting to the first location on your list of locations, because they already have that storage value.

--

But again, maybe I'm wrong.
If I'm wrong in my assumption, please tell us how your script is supposed to work.

Thanks again for helping, in my movements.xml is like this
36525

on the map there is a single tile with the actionid 47000
36524

when the player stepping on that floor with actionid 47000, I wanted it based on the storageid it has inside the [brackets] teleport the player to a certain location, if it step on the floor with actionid 47000 and have the storageid 47001 it goes to Fire Island, if step on the floor with actionid 47000 and have the storageid 47002 going to Water Island and so on.

it would only be teleported if the storageid was = 1, and after being teleported the storageid would be placed in -1
 
Thanks again for helping, in my movements.xml is like this
View attachment 36525

on the map there is a single tile with the actionid 47000
View attachment 36524

when the player stepping on that floor with actionid 47000, I wanted it based on the storageid it has inside the [brackets] teleport the player to a certain location, if it step on the floor with actionid 47000 and have the storageid 47001 it goes to Fire Island, if step on the floor with actionid 47000 and have the storageid 47002 going to Water Island and so on.

it would only be teleported if the storageid was = 1, and after being teleported the storageid would be placed in -1

Right.
So you'll want to use 'uniqueid's to separate the tiles from each other.
If we don't do that, then there's no way to know what tile you're stepping on.

So add uniqueid 47001 to that tile. (also keep the actionid 47000)
add uniqueid 47002 to the other tile. (also keeping the actionid 47000)

Then adjust the script to use uniqueid's as the table index.
Lua:
local config = {
--[[Islands]]] --
    [47001] = {townid = 7, msg = "Welcome to the Fire Island", pos = {x=29997, y=28758, z=7}},
    [47002] = {townid = 7, msg = "Welcome to the Water Island", pos = {x=29846, y=28645, z=7}},
}

function onStepIn(creature, item, position, fromPosition)
    if not creature:isPlayer() then
        return false
    end
    
    local exhaustiontime = 2 -- Exhaustion Time
    local exhaustionstorage = 40001 -- Exhaustion Storage
    local position = creature:getPosition()
    local player = creature:getPlayer()
    local unique_id = item:getUniqueId()
    local cfg = config[unique_id]
    
    if player:getExhaustion(exhaustionstorage) > 0 then
        player:teleportTo(fromPosition, false)
        return true
    end   
    
    if cfg then -- confirming that this index of the table exists
        if player:getStorageValue(unique_id) == 1 then
            player:teleportTo(cfg.pos)
            player:setTown(Town(cfg.townid))
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "".. cfg.msg ..".")
            player:setStorageValue(unique_id, -1)
            player:setExhaustion(exhaustionstorage, exhaustiontime)
            Position({x = position.x + 1, y = position.y + 1, z = position.z}):sendMagicEffect(21)
        else
            -- teleport them off the tile? send cancel message?
        end
    end
    return true
end


-- edit..

Wait I think I made a mistake.
There is only one tile.

So I'm just being stupid.

use this, and don't change anything on your tile(s)
Lua:
local config = {
--[[Islands]]] --
    {townid = 7, storageid = 47001, msg = "Welcome to the Fire Island", pos = {x=29997, y=28758, z=7}},
    {townid = 7, storageid = 47002, msg = "Welcome to the Water Island", pos = {x=29846, y=28645, z=7}},
}

function onStepIn(creature, item, position, fromPosition)
    if not creature:isPlayer() then
        return false
    end
   
    local player = creature:getPlayer()
    local exhaustiontime = 2 -- Exhaustion Time
    local exhaustionstorage = 40001 -- Exhaustion Storage
   
   
    if player:getExhaustion(exhaustionstorage) > 0 then
        player:teleportTo(fromPosition, false)
        return true
    end
   
    for i = 1, #config do -- loop through all of the config's until a storage is found
        if player:getStorageValue(config.storageid) == 1 then
            player:teleportTo(config.pos)
            player:setTown(Town(config.townid))
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "".. config.msg ..".")
            player:setStorageValue(config.storageid, -1)
            player:setExhaustion(exhaustionstorage, exhaustiontime)
            local position = creature:getPosition()
            Position({x = position.x + 1, y = position.y + 1, z = position.z}):sendMagicEffect(21)
            return true
        end
    end
   
    print("no storages found for this player")
    -- probably want to teleport the player off the tile?
    return true
end
 
Last edited:

Right.
So you'll want to use 'uniqueid's to separate the tiles from each other.
If we don't do that, then there's no way to know what tile you're stepping on.

So add uniqueid 47001 to that tile. (also keep the actionid 47000)
add uniqueid 47002 to the other tile. (also keeping the actionid 47000)

Then adjust the script to use uniqueid's as the table index.
Lua:
local config = {
--[[Islands]]] --
    [47001] = {townid = 7, msg = "Welcome to the Fire Island", pos = {x=29997, y=28758, z=7}},
    [47002] = {townid = 7, msg = "Welcome to the Water Island", pos = {x=29846, y=28645, z=7}},
}

function onStepIn(creature, item, position, fromPosition)
    if not creature:isPlayer() then
        return false
    end
   
    local exhaustiontime = 2 -- Exhaustion Time
    local exhaustionstorage = 40001 -- Exhaustion Storage
    local position = creature:getPosition()
    local player = creature:getPlayer()
    local unique_id = item:getUniqueId()
    local cfg = config[unique_id]
   
    if player:getExhaustion(exhaustionstorage) > 0 then
        player:teleportTo(fromPosition, false)
        return true
    end  
   
    if cfg then -- confirming that this index of the table exists
        if player:getStorageValue(unique_id) == 1 then
            player:teleportTo(cfg.pos)
            player:setTown(Town(cfg.townid))
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "".. cfg.msg ..".")
            player:setStorageValue(unique_id, -1)
            player:setExhaustion(exhaustionstorage, exhaustiontime)
            Position({x = position.x + 1, y = position.y + 1, z = position.z}):sendMagicEffect(21)
        else
            -- teleport them off the tile? send cancel message?
        end
    end
    return true
end


-- edit..

Wait I think I made a mistake.
There is only one tile.

So I'm just being stupid.

use this, and don't change anything on your tile(s)
Lua:
local config = {
--[[Islands]]] --
    {townid = 7, storageid = 47001, msg = "Welcome to the Fire Island", pos = {x=29997, y=28758, z=7}},
    {townid = 7, storageid = 47002, msg = "Welcome to the Water Island", pos = {x=29846, y=28645, z=7}},
}

function onStepIn(creature, item, position, fromPosition)
    if not creature:isPlayer() then
        return false
    end
  
    local player = creature:getPlayer()
    local exhaustiontime = 2 -- Exhaustion Time
    local exhaustionstorage = 40001 -- Exhaustion Storage
  
  
    if player:getExhaustion(exhaustionstorage) > 0 then
        player:teleportTo(fromPosition, false)
        return true
    end
  
    for i = 1, #config do -- loop through all of the config's until a storage is found
        if player:getStorageValue(config.storageid) == 1 then
            player:teleportTo(config.pos)
            player:setTown(Town(config.townid))
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "".. config.msg ..".")
            player:setStorageValue(config.storageid, -1)
            player:setExhaustion(exhaustionstorage, exhaustiontime)
            local position = creature:getPosition()
            Position({x = position.x + 1, y = position.y + 1, z = position.z}):sendMagicEffect(21)
            return true
        end
    end
  
    print("no storages found for this player")
    -- probably want to teleport the player off the tile?
    return true
end

Unfortunately it does not work, I have already tried in many other ways, thanks for the help.

the solution that I found was to make 2 towns with the positions and in the script to send the player to the town.
 
Unfortunately it does not work, I have already tried in many other ways, thanks for the help.

the solution that I found was to make 2 towns with the positions and in the script to send the player to the town.
Yeah sorry.
If I knew more information about what you were trying to accomplish, as well as knowing more about tfs 1.0+, I probably could have helped more.
I just didn't know how you obtain these storages or why the storages were required, and more importantly if multiple storages could be on a person at once.

I still think actionid + uniqueid on the tiles is the correct approach based on my assumption of what you were wanting to do, as well as using only 1 storage for all of the tiles, but changing that storage depending on where you wanted the player to go. (Location 1 = (storage = 1), location 2 = (storage = 2)) et cetera, and since it was a 1-time trip, just set the storage to 0 after they used that tile.

But this is in hindsight.
Continuing to use what you understand and what is currently working is probably best.
 
The reason your original script did not work is because you did not set a storage to be checked here:
deJKmiU.jpg


It should be player:getStorageValue(item.actionid) assuming that the tiles actionid is 47001 and the table index is 47001, all should be good.
 
Back
Top