papam77 Posted April 29, 2013 Share Posted April 29, 2013 Hey guys, i was reading lua.org with function string.find I was reading it again, again and again but i still don't know how to use it... Link to comment
PaiN^ Posted April 29, 2013 Share Posted April 29, 2013 It's used to find a string in a string, Ex : string.find( getPlayerName ( getLocalPlayer ( ) ), 'papam77' ) This will return true if the local player name included papam77 in it Link to comment
papam77 Posted April 29, 2013 Author Share Posted April 29, 2013 It's used to find a string in a string, Ex : string.find( getPlayerName ( getLocalPlayer ( ) ), 'papam77' ) This will return true if the local player name included papam77 in it so i can use it for finding gamemode, script and something like this ? Link to comment
PaiN^ Posted April 29, 2013 Share Posted April 29, 2013 Not like that, It finds a strings in a string, Like when you search in a book for a page, It do the same for strings, Ex : BadWords = { 'word1', 'word2' } addEventHandler ( 'onPlayerChat', root, function( msg, msgtype ) if msgtype == 0 then for k,v in ipairs( BadWords ) do if string.find( msg, v ) then cancelEvent ( ) end end end end ) This will cancel a chat message if that message included any word in the BadWords table . If you could tell me what are you trying to do it would be easier for me to help : ) Link to comment
Castillo Posted April 29, 2013 Share Posted April 29, 2013 It's used to find a string in a string, Ex : string.find( getPlayerName ( getLocalPlayer ( ) ), 'papam77' ) This will return true if the local player name included papam77 in it Wrong, it doesn't return true if it found a match. lua.org quote: If it finds a match, then find returns the indices of s where this occurrence starts and ends; otherwise, it returns nil. Link to comment
papam77 Posted April 29, 2013 Author Share Posted April 29, 2013 It's used to find a string in a string, Ex : string.find( getPlayerName ( getLocalPlayer ( ) ), 'papam77' ) This will return true if the local player name included papam77 in it Wrong, it doesn't return true if it found a match. lua.org quote: If it finds a match, then find returns the indices of s where this occurrence starts and ends; otherwise, it returns nil. I really don't know now How can add it for any gamemode or script ? Link to comment
50p Posted April 29, 2013 Share Posted April 29, 2013 You can use it to find substring (string inside) of the string. start, end = string.find( "Hello world", "wor" ) -- would return 7 and 9 (7 is where it was found, and 9 is where it ends) start, end = string.find( "Hello world", "hel" ) -- would return nil because "hel" is not found in the string start, end = string.find( "Hello world", "Hel" ) -- would return 1 and 3 (found "Hel" at 1 and ended at 3) You have to remember that the second string (the string you are searching) is a "pattern" and that means you can do special searches like in Regular Expression to find for example date in a string start, end = string.find( "Today is 29/04/2013", "%d%d/%d%d/%d%d%d%d" ) -- it would return 10 and 19 (date starts at character 10 and ends at character 19) There are more special (or magic) characters you can use, eg: start, end, day, month, year = string.find( "Today is 29/04/2013", "(%d+)/(%d+)/(%d+)" ) -- it would return 5 values: 10, 19 (like example above -^-) and also 3 more values captured between ( and ) => 29 04 2013 You can tell the function to ignore any special characters in the pattern and search for simple string: start, end = string.find( "Your clan is [clan]", "[clan]", 1, true ) -- the 3rd parameter 1 tell the function where to start searching for the substring, the last parameter tell the func to ignore any special characters (in this case: [ and ] are special chars) -- the result would be 14 and 19 (found at 14 and ends at 19) The string.find function is powerful but you can use the this example to find any simple substring you want ignoring any "magic" characters If you want to get string in between [ and ] (for example to get player's clan) then you can use the pattern as follows: start, end, clan = string.find( "[MYCLAN]PlayerName", "%[(%w+)%]" ) -- it would return 1, 8 and "MYCLAN" (found at 1, ends at 8 and the capture (%w+) => MYCLAN) "%[(%w+)%]" => %[ this means you want to find [ in your string, then (%w+) means you want to capture all the letters after [, and then %] means you want to finish looking for pattern at ] Like I said it's a powerful function but you need to know how the function works and what is Regular Expression because these 2 share the same logic. You said you read over and over again but can't understand, if you still don't understand then I'm not sure how to help you. 1 Link to comment
papam77 Posted April 29, 2013 Author Share Posted April 29, 2013 You can use it to find substring (string inside) of the string. start, end = string.find( "Hello world", "wor" ) -- would return 7 and 9 (7 is where it was found, and 9 is where it ends) start, end = string.find( "Hello world", "hel" ) -- would return nil because "hel" is not found in the string start, end = string.find( "Hello world", "Hel" ) -- would return 1 and 3 (found "Hel" at 1 and ended at 3) You have to remember that the second string (the string you are searching) is a "pattern" and that means you can do special searches like in Regular Expression to find for example date in a string start, end = string.find( "Today is 29/04/2013", "%d%d/%d%d/%d%d%d%d" ) -- it would return 10 and 19 (date starts at character 10 and ends at character 19) There are more special (or magic) characters you can use, eg: start, end, day, month, year = string.find( "Today is 29/04/2013", "(%d+)/(%d+)/(%d+)" ) -- it would return 5 values: 10, 19 (like example above -^-) and also 3 more values captured between ( and ) => 29 04 2013 You can tell the function to ignore any special characters in the pattern and search for simple string: start, end = string.find( "Your clan is [clan]", "[clan]", 1, true ) -- the 3rd parameter 1 tell the function where to start searching for the substring, the last parameter tell the func to ignore any special characters (in this case: [ and ] are special chars) -- the result would be 14 and 19 (found at 14 and ends at 19) The string.find function is powerful but you can use the this example to find any simple substring you want ignoring any "magic" characters If you want to get string in between [ and ] (for example to get player's clan) then you can use the pattern as follows: start, end, clan = string.find( "[MYCLAN]PlayerName", "%[(%w+)%]" ) -- it would return 1, 8 and "MYCLAN" (found at 1, ends at 8 and the capture (%w+) => MYCLAN) "%[(%w+)%]" => %[ this means you want to find [ in your string, then (%w+) means you want to capture all the letters after [, and then %] means you want to finish looking for pattern at ] Like I said it's a powerful function but you need to know how the function works and what is Regular Expression because these 2 share the same logic. You said you read over and over again but can't understand, if you still don't understand then I'm not sure how to help you. Thank you ^^ Link to comment
papam77 Posted April 30, 2013 Author Share Posted April 30, 2013 You can use it to find substring (string inside) of the string. start, end = string.find( "Hello world", "wor" ) -- would return 7 and 9 (7 is where it was found, and 9 is where it ends) start, end = string.find( "Hello world", "hel" ) -- would return nil because "hel" is not found in the string start, end = string.find( "Hello world", "Hel" ) -- would return 1 and 3 (found "Hel" at 1 and ended at 3) You have to remember that the second string (the string you are searching) is a "pattern" and that means you can do special searches like in Regular Expression to find for example date in a string start, end = string.find( "Today is 29/04/2013", "%d%d/%d%d/%d%d%d%d" ) -- it would return 10 and 19 (date starts at character 10 and ends at character 19) There are more special (or magic) characters you can use, eg: start, end, day, month, year = string.find( "Today is 29/04/2013", "(%d+)/(%d+)/(%d+)" ) -- it would return 5 values: 10, 19 (like example above -^-) and also 3 more values captured between ( and ) => 29 04 2013 You can tell the function to ignore any special characters in the pattern and search for simple string: start, end = string.find( "Your clan is [clan]", "[clan]", 1, true ) -- the 3rd parameter 1 tell the function where to start searching for the substring, the last parameter tell the func to ignore any special characters (in this case: [ and ] are special chars) -- the result would be 14 and 19 (found at 14 and ends at 19) The string.find function is powerful but you can use the this example to find any simple substring you want ignoring any "magic" characters If you want to get string in between [ and ] (for example to get player's clan) then you can use the pattern as follows: start, end, clan = string.find( "[MYCLAN]PlayerName", "%[(%w+)%]" ) -- it would return 1, 8 and "MYCLAN" (found at 1, ends at 8 and the capture (%w+) => MYCLAN) "%[(%w+)%]" => %[ this means you want to find [ in your string, then (%w+) means you want to capture all the letters after [, and then %] means you want to finish looking for pattern at ] Like I said it's a powerful function but you need to know how the function works and what is Regular Expression because these 2 share the same logic. You said you read over and over again but can't understand, if you still don't understand then I'm not sure how to help you. As you told me in PM: Write to thread. So okay. I need with string.find, find gamemode race for lobby. How can do that ? Link to comment
50p Posted April 30, 2013 Share Posted April 30, 2013 What do you mean "gamemode race for lobby"? Link to comment
iPrestege Posted April 30, 2013 Share Posted April 30, 2013 What do you mean "gamemode race for lobby"? He is trying to make something like "FFS Gaming" "Twisted Gaming" .. etc As what i understand . Link to comment
50p Posted April 30, 2013 Share Posted April 30, 2013 What do you mean "gamemode race for lobby"? He is trying to make something like "FFS Gaming" "Twisted Gaming" .. etc As what i understand . It doesn't explain anything. I still don't understand. Link to comment
PaiN^ Posted April 30, 2013 Share Posted April 30, 2013 I think he want to have more than one gammode in one server ( DM, DD, .. ) . Link to comment
papam77 Posted April 30, 2013 Author Share Posted April 30, 2013 I think he want to have more than one gammode in one server ( DM, DD, .. ) . Yes ! +1 I mean Arenas in one gamemode. This : Link to comment
50p Posted April 30, 2013 Share Posted April 30, 2013 In that case you first need to make gamemodes that work together. You can't simply run all the gamemodes you have on your server and make a selection window for this. You have to modify all the gamemodes to work as 1. That is a lot of work and string.find on its own will not make it all possible. 1 Link to comment
papam77 Posted April 30, 2013 Author Share Posted April 30, 2013 In that case you first need to make gamemodes that work together. You can't simply run all the gamemodes you have on your server and make a selection window for this. You have to modify all the gamemodes to work as 1. That is a lot of work and string.find on its own will not make it all possible. And how can make gamemodes which work together ? Link to comment
50p Posted April 30, 2013 Share Posted April 30, 2013 First, you need to know how to script. Then you need to research the gamemodes and find out how they interact with players so that the gamemodes will not interrupt themselves. Then start modifying the gamemodes. Link to comment
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