Jump to content

[HELP] Checking if a word is in the JSON table


..:D&G:..

Recommended Posts

So I store player's account names into a JSON table like this: "[[user1, User2]]" and I want to check if the player's account name is in the table, something like...

local theTable = fromJSON(owners) 
if isPlayerAccountInTable(thePlayer, theTable) then 

Thanks

Link to comment
  
local theTable = fromJSON(owners) 
function isPlayerAccountInTable(thePlayer, theTable) 
    local account = getPlayerAccount ( thePlayer ) 
    if account then 
        local accountName = getAccountName ( account ) 
        if accountName then 
            for i, k in ipairs(theTable) do 
                if k == accountName then 
                    return true 
                end 
            end 
        else 
            outputChatBox("Cannot get account name") 
        end 
    else 
        outputChatBox("Cannot get player's account") 
    end 
    return false 
end 
  
if isPlayerAccountInTable(getPlayerFromName("Arsilex"), theTable) then 
    outputChatBox("Account found") 
end 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...