Franky Posted May 7, 2009 Share Posted May 7, 2009 what i want to do is i want to make a mini game. you have to enter the right numbers to win. you get a 5 key combination code and when you enter the five numbers, then the numbers, that are right, turn green and the rest turn red. does anyone know how to do it? if someone could just give me some kind of an example or a link i would appreciate it thanks Franky Link to comment
Lordy Posted May 8, 2009 Share Posted May 8, 2009 What kind of help do you need? Are you totally new to Lua or you have some basic knowledge? But anyway, http://development.mtasa.com/index.php? ... troduction Scripting introduction to MTA, you need this really http://development.mtasa.com/index.php? ... ng_the_GUI If you want to make the red/green thingie with GUI then you need this also http://lua-users.org/wiki/StringLibraryTutorial You probably will need either this and string.sub() function too, but turn here once you've understood basics. If you already have knowledge about these things, I'd recommend just trying out with dx functions to show the colour. I might even make a little example. Link to comment
Franky Posted May 8, 2009 Author Share Posted May 8, 2009 I have the basics. i just don't know how to separate the number like i want to. if you could make an example it would be great because that way i can learn it quicker Link to comment
Lordy Posted May 9, 2009 Share Posted May 9, 2009 You can make user input them with either addCommandHandler or a gui input box.. There you get a string.. To get five numbers out of it you can do this function returnNumbers (stringnumber) if tonumber(stringnumber) and string.len(stringnumber) == 5 then -- we use tonumber to see if all the contents are numbers, string.len is to see how long is the string -- So we have a string which consists of 5 numbers -- Now we extract the numbers from string local one = tonumber(string.sub(stringnumber,1,1))-- string.sub finds a substring at the position we defined, currently starts at first char and ends there local two = tonumber(string.sub(stringnumber,2,2)) local three = tonumber(string.sub(stringnumber,3,3)) local four = tonumber(string.sub(stringnumber,4,4)) local five = tonumber(string.sub(stringnumber,5,5)) -- We also used tonumber to convert the string to an integer -- so we have successfully split the string into separate numbers return one,two,three,four,five -- Return allows the function to be used elsewhere and it also stop the function end return false -- If the first if statement didn't go through, then the previous return didn't end the function and it should return false end ------------------------------------------------------------------------------------------ --stringnumber = "11234" -- This is the number that we got from addCommandHandler or inputbox ------------------------------------------------------------------------------------------- -- Now we use this function like this inside some other func. local one,two,three,four,five = returnNumbers(stringnumber) -- And we got five little variables, if the stringnumber was 5 characters long and consisted only of numbers -- one would be 1, two 1, three 3, four 3, five 4 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