• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Storage Checker Talkaction Concept

Extrodus

|| Blazera.net ||
Joined
Dec 22, 2008
Messages
2,691
Solutions
7
Reaction score
549
Location
Canada
So hopefully I could get a hand with this, I'm fairly new to doing unique things with LUA and I am trying to figure out how I would go about making a talkaction that checks to see if a player has a certain set of storages and sends the player a message based on the results.

To put it in perspective, I have 6 tiles that give the player a storage (37112-37118) with the value of 1 when they walk on it. What I want them to be able to do is say a talkaction where it will tell them, "You have found ## out of 6 tiles."

Here's what I've started with so far just to get an idea; I've been looking everywhere through the talkaction section just to find another example of someone doing something similar so I can try to base it off that but I haven't had any luck.

Code:
function onSay(player, words, param)
    local config = {
    storages = {37112, 37113, 37114, 37115, 37116, 37117, 37118},
    }
    if player:getStorageValue(config.storages) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found 6/6 shrines")
    end 
    return false
end

If anyone could give me some pointers as to how I would do this I would greatly appreciate it!
Using TFS 1.2

Edit:
Found one non working example of a similar script.
https://otland.net/threads/talkaction-returning-current-task-information.234865/
 
Last edited:
You need to loop over every storage in the list and check if player have that storage set to 1, if its true, add to count and then display the count.


Code:
local storages = {
    37112, 37113, 37114, 37115, 37116, 37117, 37118
}

function onSay(player, words, param)
    local count = 0
    --loop over all storages in the list
    for _, storage in ipairs(storages) do
        --check every storage
        if (player:getStorageValue(storage) == 1) then
            --add one more to the count
            count = count + 1
        end
    end
    --display how much storages we have
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found "..count.."/6 shrines")
   
    return false
end
 
@Yamaken - Thank you so much for detailing what each part does. It makes so much sense now! You have to define something with a number (count = 0) then check all the storages and add + 1 to the count if they have the storage. Geez, that literally explains it to a point I think Ill be able to easily do what I need to from here; thank you again!
 
for = start of loop
_ = name of loop?
storage = they could use anything.. something to store the value of the loop.?
ipairs = number values inside.. storages.
storages = the table above.
do = do/then.. continue.

If Im wrong anywhere, I'm sorry. D:
 
for = start of loop
_ = name of loop?
storage = they could use anything.. something to store the value of the loop.?
ipairs = number values inside.. storages.
storages = the table above.
do = do/then.. continue.

If Im wrong anywhere, I'm sorry. D:

Could you explain and describe exactly what this part does and each piece of this line ? (it's serious question)

ipairs - create pairs index, value from list, similar to pairs
http://lua-users.org/wiki/ForTutorial

_ - index of each element inside list named storages
storage
- each element of list storages

do - start block of code iterating every pair index, value from list
 
Back
Top