Jump to content

How to find something from table


tigerman

Recommended Posts

  • Moderators
Posted

Hi,

There are no function for that ( except the string.find like you said )

You have to create a loop in which the server get 1 by 1 a word from the table then make a string.find if in a loop it return true, you can break the loop and make your instructions.

Put here your table ( all we need for understand the table )

The rEvolution is coming ...

Posted
function test (thePlayer,commandname,map1) 
local mapTable = {} 
for i, maps in ipairs(exports.mapmanager:getMapsCompatibleWithGamemode(getResourceFromName("race"))) do 
table.insert(mapTable, getResourceInfo(maps, "name")) 
end 
end 
addCommandHandler("test",test) 

and now it has to find map from mapTable with that name what was in command

Posted

You can set the item key as a string, and then call the string later on like 'tableName["item"]', instead of looping the whole table every time.

Retired

  • Moderators
Posted

ok try this but what do you want to do exactly ?

function foundMap( thePlayer, commandName, map ) 
    if map then 
        local mapName = tostring( map ) 
        for k,i in ipairs ( mapTable ) do 
            outputChatBox( "if "..i[1].." == "..mapName, thePlayer ) 
            if ( tostring(i[1]) == tostring(mapName) ) then 
                outputChatBox( "I found ! It's "..tostring(i[1]), thePlayer, 180, 0, 0 ) 
                break 
            end 
        end 
    else 
        outputChatBox("/test2 [mapName]" ) 
    end 
end 
addCommandHandler("test2",foundMap) 

The rEvolution is coming ...

Posted
function table.find(tabl,word) 
if type(tabl) ~= "table" or word == nil then 
return false 
else 
local ret = false 
for k,v in pairs(tabl) do 
    if v == word then 
    return k 
    end 
end 
end 
end 
  

Now you can use: table.find(yourtable,whatfind) :D

Sorry for my bad english(

Posted

"this forum would be useless without you 2"

I don't think that's correct, many others are helping in the forum, not just them.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

  • Moderators
Posted

Haha Yeah tigerman forgot you SolidSnake :lol:

But he can't know every scripters who helping others

The rEvolution is coming ...

Posted

I won't him to name every scripter here, just is unfair to say just two are helping ;)

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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...