Module PLATE

License Plates

Module Overview

Hooks

GetCustomPlateRender(vIndex, plates) Called to get the render details for a given set of vehicles / exempt pairs.
CanOpenLicenseMenu(ply, veh) Hook function, called to determine if a player can open the license plate menu.
CanUpdateLicensePlate(ply, veh, plate) Hook function, called to determine if a player can update their license plate.

Functions

GetPlateColourFromPath(path) Get the colour required for a specific plate by its path.
GetBySeason() Get the plate based on the current month/day.
DrawCar(ent, lPlyPos[, traceData]) Draw the plates on a single car.
RedrawEntity(ent, newKey, newValue) Redraw an entity (refresh its plate texture)
DrawPlate(ent, plate, RT[, traceData]) Draw a single plate on a given entity.
OpenMenu(leng, ply) Open the F3 license plate menu.
OnNWVarChanged(ent, name, old, new) Hook function used to capture changes to our NW Vars.
OnEntityCreated(ent) Internal function used to hook into OnEntityCreated.
EntityRemoved(ent) Internal function used to hook into EntityRemoved.
PostDrawTranslucentRenderables(d, s) Internal function, used for hooking into PostDrawTranslucentRenderables.
ResolvePlateData(ent, plate) Resolve an entities license plate data.
IsVehicle(vehicle) Get if the given entity is a valid vehicle.
IsValid() Ensure we're valid.
RegisterPlate(veh, first, ...) Register a plate for use by the vehicle defined by veh.
RegisterModel(model, map) Registers a model -> index mapping pair.
RegisterLegacy(veh, ...) Register a legacy plate position.
RegisterRenderer(veh, renderer) Register a custom renderer
GetPlate(veh) Get registered plates for a given vehicle.
CheckVehicleOwnership(ply, veh) Check if a given vehicle is owned by the current player.
GetModelMatches() Function called to load model matches.
RandomLetter() Generate a random capital letter.
RandomNumber() Generate a random number, in the range 0-9 Whilst it's not quicker, it's nicer to have it being a function in the plate table.
DoReplace(val) Format a string replacement for RandomPlate Takes the string or digit string format pattern, returning a random letter or number.
RandomPlate() Generates a random plate based on PLATE.Config.DefaultFormat.
GetVehicleName(ent) Get the "name" of the vehicle.
GetChosenVehicle(ply, ent) Get the player's chosen vehicle.
OpenMenu(ply, ent) Open the plate menu on a client.
OnShowSpare1(ply) Open the plate menu on the selected vehicle.
PlayerHasCash(ply, amt) Check if the player has the amount of cash required to do a transaction.
PlayerTakeMoney(ply, amt) Take cash from a player.
SetLicensePlate(ply, veh, plate, Callback) Update the license plate in the DB and on the vehicle itself.
SearchPlate(plate, Callback) Get the steamid of the player with matching plate.
PlateFromSteamID(sid[, veh], callback) Fetch a table of all license plates, keyed by vehicle ID or license plate for a specific steam ID / vehicle pair.
GetLicensePlate(ply, veh, Callback) Fetch license plate information for a vehicle and generate if none exists.
GetUpdate(leng, ply, plate, veh_type, veh) Internal function, used to process the plate update net message.
IsEmergency(veh) Check if a given vehicle is an emergency vehicle.
PrepareVehicle(ply, veh) Setup a vehicle's license plates, upon spawn.

Tables

Config Table for storing all information about plates and their configuration.
Positions The stored positions of the license plates.
Models The stored model -> id mappings.
VehicleClasses Table containing valid vehicle classes.

Fields

COLOUR_NONE Base plate standard color.
COLOUR_RESET Base plate reset color.

Hooks

GetCustomPlateRender(vIndex, plates)
Called to get the render details for a given set of vehicles / exempt pairs.

Parameters:

  • vIndex string Vehicle Index.
  • plates tab Plates Table, See PLATE:GetPlates
CanOpenLicenseMenu(ply, veh)
Hook function, called to determine if a player can open the license plate menu.

Parameters:

  • ply Player The player updating their plate.
  • veh Vehicle The vehicle being updated.
CanUpdateLicensePlate(ply, veh, plate)
Hook function, called to determine if a player can update their license plate.

Parameters:

  • ply Player The player updating their plate.
  • veh Vehicle The vehicle being updated.
  • plate string The new license plate.

Functions

GetPlateColourFromPath(path)
Get the colour required for a specific plate by its path.

Parameters:

  • path string The path to grab colour for.

Returns:

    Color The colour for the plate, or the default plate colour if none is defined.
GetBySeason()
Get the plate based on the current month/day.

Returns:

    string Path to the plate, not including base path.
DrawCar(ent, lPlyPos[, traceData])
Draw the plates on a single car.

Internal:

    This function is internal. Whilst you can call it, you probably shouldn't.

Parameters:

  • ent Entity Entity to draw on.
  • lPlyPos Vector The player's position.
  • traceData tab The trace data to use as a base for trace based plate hiding. (optional)
RedrawEntity(ent, newKey, newValue)
Redraw an entity (refresh its plate texture)

Internal:

    This function is internal. Whilst you can call it, you probably shouldn't.

Parameters:

  • ent Entity Entity to redraw.
  • newKey optional string The NWVar being updated.
  • newValue optional string The new NWVar values.
DrawPlate(ent, plate, RT[, traceData])
Draw a single plate on a given entity.

Internal:

    This function is internal. Whilst you can call it, you probably shouldn't.

Parameters:

  • ent Entity The entity to draw on.
  • plate tab Plate data.
  • RT IMaterial Material to draw.
  • traceData tab Tracedata to use. (optional)
OpenMenu(leng, ply)
Open the F3 license plate menu.

Parameters:

  • leng int int Net Message Length
  • ply Confirmation that the net message was sent from the server. (Should be nil)
OnNWVarChanged(ent, name, old, new)
Hook function used to capture changes to our NW Vars.

Internal:

    This function is internal. Whilst you can call it, you probably shouldn't.

Parameters:

  • ent
  • name
  • old
  • new
OnEntityCreated(ent)
Internal function used to hook into OnEntityCreated.

Internal:

    This function is internal. Whilst you can call it, you probably shouldn't.

Parameters:

  • ent Entity Entity being created.
EntityRemoved(ent)
Internal function used to hook into EntityRemoved.

Internal:

    This function is internal. Whilst you can call it, you probably shouldn't.

Parameters:

  • ent Entity Entity being removed.
PostDrawTranslucentRenderables(d, s)
Internal function, used for hooking into PostDrawTranslucentRenderables. Yes, I know BadCoderz fires on this. The only other way of doing this is setting a RenderOverride function. That breaks refract materials, so I'm not doing that. I know I'm doing ents.GetAll in here. I need to test against multiple classes. propvehiclejeep, propvehiclejeepold, propvehicle_airboat, whatever the fuck the ID is for SCars. That has a higher performance hit than ents.GetAll.

Internal:

    This function is internal. Whilst you can call it, you probably shouldn't.

Parameters:

  • d bool If the hook is currently drawing depth.
  • s bool If the hook is currently drawing sky.
ResolvePlateData(ent, plate)
Resolve an entities license plate data. Handles conditional functions, bodygroup conditionals and position globalization.

Parameters:

  • ent Entity Entity to resolve against.
  • plate tab License Plate data to resolve for.

Returns:

    bool False, if the plate should be hidden.
IsVehicle(vehicle)
Get if the given entity is a valid vehicle.

Parameters:

  • vehicle Vehicle

Returns:

    bool
IsValid()
Ensure we're valid. (Used for the hook lib).

Internal:

    This function is internal. Whilst you can call it, you probably shouldn't.
RegisterPlate(veh, first, ...)
Register a plate for use by the vehicle defined by veh.

Warnings:

    Must be ran in a shared context, otherwise plate positions will not show.

Parameters:

  • veh string Vehicle name to register.
  • first string or table Vehicle name to copy or first license plate table.
  • ... vararg

Usage:

    PLATE:RegisterPlate("test1", {
    	pos = Vector(1, 1, 1),
    	ang = Angle(0, 0, 90),
    	scale = 1.01,
    	condition = function(ent)
    		return {Vector(1, 1, 1), Angle(0, 0, 90), scale = 1.01}
    })
    PLATE:RegisterPlate("test1copy", "test1")
RegisterModel(model, map)
Registers a model -> index mapping pair.

Warnings:

    Must be ran in a shared context, otherwise stuff breaks.

Parameters:

  • model string The model path to register.
  • map string The index to register.
RegisterLegacy(veh, ...)
Register a legacy plate position. Functionally the same as RegisterPlate, but sets a few flags on the data.

Warnings:

    Must be ran in a shared context, otherwise plate positions will not show.

Internal:

    This function is internal. Whilst you can call it, you probably shouldn't.

Parameters:

  • veh string Vehicle name.
  • ... vararg

See also:

RegisterRenderer(veh, renderer)
Register a custom renderer

Parameters:

  • veh string Vehicle name.
  • renderer tab Render data.
GetPlate(veh)
Get registered plates for a given vehicle.

Parameters:

  • veh string Vehicle name to get plates for

Returns:

    table Table of license plate positions, angles, scales and overrides.
CheckVehicleOwnership(ply, veh)
Check if a given vehicle is owned by the current player.

Parameters:

  • ply Player The player to check ownership from.
  • veh Vehicle The entity to check ownership of.

Returns:

    bool Is the vehicle owned by the player.
GetModelMatches()
Function called to load model matches.

Internal:

    This function is internal. Whilst you can call it, you probably shouldn't.
RandomLetter()
Generate a random capital letter.

Returns:

    string Random uppercase letter.
RandomNumber()
Generate a random number, in the range 0-9 Whilst it's not quicker, it's nicer to have it being a function in the plate table.

Returns:

    int Random number, range 0-9.
DoReplace(val)
Format a string replacement for RandomPlate Takes the string or digit string format pattern, returning a random letter or number.

Internal:

    This function is internal. Whilst you can call it, you probably shouldn't.

Parameters:

  • val string Input value for testing.

Returns:

    str Random letter, number or empty string.
RandomPlate()
Generates a random plate based on PLATE.Config.DefaultFormat.

Returns:

    string Randomly generated plate. 333,135,504 plates using default format.
GetVehicleName(ent)
Get the "name" of the vehicle.

Parameters:

  • ent Entity The entity to get the name for.

Returns:

    optional string Returns nil on failure, vehicle name as string on success.
GetChosenVehicle(ply, ent)
Get the player's chosen vehicle.

Parameters:

  • ply Player Player to get the vehicle from.
  • ent boolean or Entity If false, get closest owned vehicle. If true, get eye trace vehicle. If ent, use specific ent.

Returns:

  1. optional Vehicle Chosen vehicle.
  2. integer Squared Distance to chosen vehicle, or 0 if chosen vehicle isn't valid.
OpenMenu(ply, ent)
Open the plate menu on a client.

Parameters:

  • ply Player Player to open the menu on.
  • ent boolean or Entity If false, get closest owned vehicle. If true, get eye trace vehicle. If ent, use specific ent.

Returns:

    optional boolean True if the net message sends, nil otherwise.
OnShowSpare1(ply)
Open the plate menu on the selected vehicle.

Parameters:

  • ply Player The player who called ShowSpare1.
PlayerHasCash(ply, amt)
Check if the player has the amount of cash required to do a transaction.

Parameters:

  • ply Player The player to check cash on.
  • amt int The minimum cash the player must have.

Returns:

    bool If the player can afford the transaction.
PlayerTakeMoney(ply, amt)
Take cash from a player.

Parameters:

  • ply Player Player to take money from.
  • amt int The amount of money to take.
SetLicensePlate(ply, veh, plate, Callback)
Update the license plate in the DB and on the vehicle itself.

Parameters:

  • ply string or Player Player who's requesting the change, or their SteamID.
  • veh string or Vehicle The vehicle entity the change is being requested for, or the vehicle name if setting without an entity.
  • plate string The plate that's having the change requested.
  • Callback function , takes err.
SearchPlate(plate, Callback)
Get the steamid of the player with matching plate.

Parameters:

  • plate string License plate to find.
  • Callback function , takes (err, steamid)
PlateFromSteamID(sid[, veh], callback)
Fetch a table of all license plates, keyed by vehicle ID or license plate for a specific steam ID / vehicle pair.

Parameters:

  • sid string SteamID to query.
  • veh string Vehicle ID (optional)
  • callback function Callback, takes (err, table|string)
GetLicensePlate(ply, veh, Callback)
Fetch license plate information for a vehicle and generate if none exists.

Parameters:

  • ply string or Player Player or SteamID to get information for.
  • veh string or Vehicle Vehicle (name) to get information for.
  • Callback function , takes (err, plate)
GetUpdate(leng, ply, plate, veh_type, veh)
Internal function, used to process the plate update net message.

Internal:

    This function is internal. Whilst you can call it, you probably shouldn't.

Parameters:

  • leng int Length of incoming net message.
  • ply Player The player sending the message.
  • plate string The new plate.
  • veh_type int The vehicle picker type.
  • veh Vehicle The vehicle entity.
IsEmergency(veh)
Check if a given vehicle is an emergency vehicle.

Parameters:

  • veh Vehicle Vehicle to check.

Returns:

    boolean If the vehicle is an emergency vehicle.
PrepareVehicle(ply, veh)
Setup a vehicle's license plates, upon spawn. If, for whatever reason, you need to call this on a non-registered-vehicle? Dev or something idk. SCars maybe? Should work.

Parameters:

  • ply Player The player that spawned the vehicle.
  • veh Vehicle The vehicle spawned.

Tables

Config
Table for storing all information about plates and their configuration.
Positions
The stored positions of the license plates.
Models
The stored model -> id mappings.
VehicleClasses
Table containing valid vehicle classes. Done as [str | class] = [bool | valid]. Reduces O(N) lookup to O(1)

Fields:

  • [prop_vehicle_jeep]
  • [prop_vehicle_jeep_old] ["propvehicleprisoner_pod"] = true,
  • [prop_vehicle_airboat]
  • [gmod_sent_vehicle_fphysics_base]

Fields

COLOUR_NONE
Base plate standard color. White but darkened by ${PLATE.Config.PlateDarken}
COLOUR_RESET
Base plate reset color. Pure white.