Skip to content

Generating the numbers

Telecotxesco edited this page Dec 12, 2020 · 32 revisions

There are multiple ways to generate the numbers:

  • Defining them manually
  • Sequence from starting number to ending number
  • Random secuence from a pattern

Before continue, we should have the model start like:

local kaminari_numbers 

-- Function to check if a module available
function isModuleAvailable(name)
    if package.loaded[name] then return true end
    for _, searcher in ipairs(package.searchers or package.loaders) do
      local loader = searcher(name)
      if type(loader) == 'function' then
        package.preload[name] = loader
        return true
      end
    end
    return false
end

-- Main model's data() function 
function data()
    local platesLeft  = {} -- Here we will place the identification numbers who will be shown on left side
    local platesRight = {} -- Here we will place the identification numbers who will be shown on right side
    local platesFront = {} -- Here we will place the identification numbers who will be shown on front 
    local platesBack  = {} -- Here we will place the identification numbers who will be shown on back 

    -- If "kaminari_numbers" module is available, then we proceed loading the module. This way we prevent breaking any previous save game.
    if isModuleAvailable( "kaminari_numbers" ) then
        -- LOAD THE MOUDLE
        kaminari_numbers = require "kaminari_numbers"
        
        -- HERE WE WILL GENERATE THE NUMBERS
        
    else
        print("Warning: kaminari_numbers is not available/found. Please subscribe it on Steam Workshop, activate and make sure it is loaded before all the rest of mods.")
    end
    
-- HERE BEGINS THE USUAL RETURN DATA OF THE MODEL
return {
    boundingInfo = {
        bbMax = { 6.7790122032166, 1.5564205646515, 4.2407073974609, },
        bbMin = { -7.0255718231201, -1.5564205646515, -0.036832869052887, },
    },

    -- Rest of the model data [...]

    }
end

Simple static number

To add a number, simply call the following function:

kaminari_numbers.getChildrenColorNumber( {"V 100-1035","V 100-1023"} , "white", "Helvetica", 10.0, 2.20, -1.00, 2.05, 180, 0, 0 ),


In this local function *generateNumbers* we will generate dinamically the meshes needed for the number and letters of the model, which function is called and stored on a local variable we call *numberPlates* (you can name as your convenience).


The first lines of the mod now become:

```lua
local kaminari_numbers = require "kaminari_numbers"
function data()
	local function generateNumbers()
		return { 
			children = {
				-- Call Kaminari_Numbers functions here:
			}
		}
	end

	local numberPlates = generateNumbers()
	
	return {
		-- REST OF THE MODEL [...]