Jump to content

[SOLVED] Generate random license plate text on vehicle creation


Recommended Posts

  • Moderators

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 by Patrick2562
  • Thanks 1
Link to comment
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 by Stealthy Serval
Link to comment

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