Stealthy Serval Posted November 28, 2018 Posted November 28, 2018 (edited) Hey all, so I'm struggling trying to understand how I could create a random license plate when a vehicle spawns. I got it down to generate random numbers, but I was hoping to have the license plate be 3 characters followed by 3 numbers. How would I go about getting this done? Edited November 28, 2018 by Stealthy Serval
Moderators Patrick Posted November 28, 2018 Moderators Posted November 28, 2018 (edited) Does it matter to be unique? Can two different vehicles have the same license plate? If don't matter: local characters = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"} function createRandomPlateText() local plate = "" for i = 1, 3 do plate = plate..characters[math.random(1, #characters)] end plate = plate.."-" for i = 1, 3 do plate = plate..math.random(1, 9) end return plate end Edited November 28, 2018 by Patrick2562 1
Stealthy Serval Posted November 28, 2018 Author Posted November 28, 2018 (edited) 9 minutes ago, Patrick2562 said: Does it matter to be unique? Can two different vehicles have the same license plate? If don't matter: local characters = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"} function createRandomPlateText() local plate = "" for i = 1, 3 do plate = plate..characters[math.random(1, #characters)] end plate = plate.."-" for i = 1, 3 do plate = plate..math.random(1, 9) end return plate end It does need to be unique, but I actually have a check in place for that! That works perfectly, thank you so much. I clearly need to learn more Lua because I really don't understand the whole "for do" statements. Edited November 28, 2018 by Stealthy Serval
Captain Cody Posted November 29, 2018 Posted November 29, 2018 Could make it so it's 100% unique by using tables. If there's a conflict simply rerun the function.
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