tigerman Posted March 20, 2011 Posted March 20, 2011 Hello dear community members, i need some help here i have table but i need to find from there single word, for example "car-infernus" could someone tell me function for that ? like to find from string i need string.find but what about tables ? -- Thanks VIEW MY RESOURCES -> https://forum.mtasa.com/viewtopic.php?f=108&t=70956
Moderators Citizen Posted March 20, 2011 Moderators Posted March 20, 2011 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 ...
tigerman Posted March 20, 2011 Author Posted March 20, 2011 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 VIEW MY RESOURCES -> https://forum.mtasa.com/viewtopic.php?f=108&t=70956
Callum Posted March 20, 2011 Posted March 20, 2011 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 Citizen Posted March 20, 2011 Moderators Posted March 20, 2011 You want to get the resource to start ? whith his name ? The rEvolution is coming ...
tigerman Posted March 20, 2011 Author Posted March 20, 2011 just name to outputChatBox would be nice.. then i can continue by myself VIEW MY RESOURCES -> https://forum.mtasa.com/viewtopic.php?f=108&t=70956
Moderators Citizen Posted March 20, 2011 Moderators Posted March 20, 2011 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 ...
tigerman Posted March 21, 2011 Author Posted March 21, 2011 line 5 says error "attempt to concatenate field '?' (a nil value)" VIEW MY RESOURCES -> https://forum.mtasa.com/viewtopic.php?f=108&t=70956
Dre-+- Posted March 21, 2011 Posted March 21, 2011 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) Sorry for my bad english(
tigerman Posted March 21, 2011 Author Posted March 21, 2011 Thanks Dre, works perfect also thanks to Citizen for trying to help me this forum would be useless without you 2 VIEW MY RESOURCES -> https://forum.mtasa.com/viewtopic.php?f=108&t=70956
Castillo Posted March 22, 2011 Posted March 22, 2011 "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. Education is the most powerful weapon which you can use to change the world.
Moderators Citizen Posted March 22, 2011 Moderators Posted March 22, 2011 Haha Yeah tigerman forgot you SolidSnake But he can't know every scripters who helping others The rEvolution is coming ...
Castillo Posted March 22, 2011 Posted March 22, 2011 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. Education is the most powerful weapon which you can use to change the world.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now