cityrp.vehicleparams
Runtime vehicle script / VehicleParams helpers. Shared foundation for the vehiclescript editor and future item-meta vehicle mods.
- Sharedcityrp.vehicleparams.ApplyEditorValues(params, values) → tableSource ☍
-
Apply a flat map of path-keyed string values onto a params table. Used by the editor net payload:
{["engine.horsepower"] = "200", ...}.Parameters
- paramstableMutable editable params.
- valuestable<string, string>Path-key → text value.
Returns
- table
- Sharedcityrp.vehicleparams.ApplyFromItemMeta(veh, item, meta) → booleanSource ☍
-
Capture baseline (if needed) and apply modifiers derived from item meta. Intended call site: immediately after a CityRP vehicle
Spawn/Activate.Parameters
- vehVehicleThe spawned vehicle.
- itemstring|table|nilSource item.
- metastring|table|nilItem metadata.
Returns
- booleanWhether modifiers were applied (false when none / not tunable).
- Sharedcityrp.vehicleparams.ApplyModifiers(veh, modifiers, context) → booleanSource ☍
-
Apply resolved modifiers to a vehicle's live params. Starts from baseline when available so stacking is deterministic across re-apply.
Parameters
- vehVehicleThe vehicle entity.
- modifierstableOrdered modifier list from ResolveModifiers.
- contexttable?Extra context (
item,meta,source, ...).
Returns
- booleanWhether params were written back.
- Sharedcityrp.vehicleparams.BuildEditorSections(params) → table[]Source ☍
-
Build the full list of editor sections for a params table (including one tab per axle).
Parameters
- paramstableEditable params.
Returns
- table[]
- Sharedcityrp.vehicleparams.CaptureBaseline(veh, params) → table|nilSource ☍
-
Store a baseline snapshot so later edits / mods can reset. Captures the params currently loaded from the vehicle script (before item mods).
Parameters
- vehVehicleThe vehicle entity.
- paramstable?Optional pre-fetched editable params.
Returns
- table|nilThe stored baseline.
- Sharedcityrp.vehicleparams.CollectModifiersFromMeta(item, meta, veh) → { id: string, data: any, priority: number }[]Source ☍
-
Collect modifier entries from vehicle item metadata. Built-in fields (
springs,turbo) are resolved here; other plugins append via the hook.Parameters
- itemstring|table|nilItem table or unique id.
- metastring|table|nilRaw meta string or decoded table.
- vehVehicle?Optional vehicle (passed through to the collect hook).
Returns
- { id: string, data: any, priority: number }[]
- Sharedcityrp.vehicleparams.GetEditableParams(veh) → table|nilSource ☍
-
Read a vehicle's params already converted to MPH for editing and script export.
Parameters
- vehVehicleThe vehicle entity.
Returns
- table|nilEditable params, or nil if the entity is not tunable.
- Sharedcityrp.vehicleparams.GetPath(params, path) → anySource ☍
-
Read a value from a params table using a path array.
Parameters
- paramstable
- pathstring[]
Returns
- any
- Sharedcityrp.vehicleparams.IsTunableVehicle(ent) → booleanSource ☍
-
Whether an entity is a jeep-class vehicle we can tune.
Parameters
- entEntity?Entity to check.
Returns
- boolean
- Sharedcityrp.vehicleparams.ParseKeyValues(text) → table[]|nilSource ☍
-
Parse a Valve KeyValues document into an ordered node tree. Nodes are
{key = string, value = string}or{key = string, children = node[]}. Order, duplicate keys and blocks the schema knows nothing about are all preserved, so a parse/serialize round trip only reformats — it never drops content.Parameters
- textstring?Raw script contents.
Returns
- table[]|nilOrdered root nodes, or nil when the document is malformed.
- Sharedcityrp.vehicleparams.RegisterModifier(id, apply, priority)Source ☍
-
Register a named runtime modifier used by item meta / future mod plugins. Re-registering the same id replaces the previous definition (hot-reload safe).
Parameters
- idstringStable modifier id (e.g.
"springs","turbo","engine_upgrade"). - applyfun(params: table, context: table)Mutates
paramsin place. - prioritynumber?Lower runs first. Defaults to 100.
- idstringStable modifier id (e.g.
- Sharedcityrp.vehicleparams.ResolveModifiers(entries) → { id: string, priority: number, data: any, apply: function }[]Source ☍
-
Build an ordered modifier list from registered ids with optional per-instance data.
Parameters
- entries{ id: string, data: any, priority: number }[]Modifier requests.
Returns
- { id: string, priority: number, data: any, apply: function }[]
- Sharedcityrp.vehicleparams.RestoreBaseline(veh) → booleanSource ☍
-
Restore params from a previously captured baseline.
Parameters
- vehVehicleThe vehicle entity.
Returns
- booleanWhether the baseline was restored.
- Sharedcityrp.vehicleparams.SerializeKeyValues(params, header, sourceScript) → string, booleanSource ☍
-
Serialize editable (MPH) params into a Valve KeyValues vehicle script. With
sourceScript, the original document is reformatted and only schema-owned keys are rewritten:"Vehicle_Sounds", wheel materials,DustCloudand any other key the editor does not model keep their original values. Without it (or when the source will not parse) only the"Vehicle"physics block can be emitted.Parameters
- paramstableEditable params.
- headerstring?Optional comment header line.
- sourceScriptstring?Contents of the vehicle's original script file.
Returns
- 1string
- 2booleanWhether
sourceScriptwas parsed and carried through.
- Sharedcityrp.vehicleparams.SetEditableParams(veh, params) → booleanSource ☍
-
Apply an editable (MPH) params table to a live vehicle. Converts engine speeds back to HU/s; SetVehicleParams matches GetVehicleParams units. Does not mutate the caller's table.
Parameters
- vehVehicleThe vehicle entity.
- paramstableEditable VehicleParams table (speeds in MPH).
Returns
- booleanWhether params were applied.
- Sharedcityrp.vehicleparams.SetPath(params, path, value)Source ☍
-
Write a value into a params table using a path array, creating tables as needed.
Parameters
- paramstable
- pathstring[]
- valueany
- Sharedcityrp.vehicleparams.SpeedsToHu(params) → tableSource ☍
-
Convert editable MPH speed fields back to HU/s for SetVehicleParams. Mutates and returns the same table for convenience.
Parameters
- paramstableEditable VehicleParams table (speeds in MPH).
Returns
- tableThe same table, with speed fields in HU/s.
- Sharedcityrp.vehicleparams.SpeedsToMph(params) → tableSource ☍
-
Convert GetVehicleParams speed fields (HU/s) into MPH for editing / script export. Mutates and returns the same table for convenience.
Parameters
- paramstableVehicleParams table from GetVehicleParams.
Returns
- tableThe same table, with speed fields in MPH.
- Sharedcityrp.vehicleparams.TextToValue(field, text, previous) → anySource ☍
-
Parse editor text back into a typed value.
Parameters
- fieldtableField schema entry.
- textstring
- previousanyExisting value (used as vector fallback).
Returns
- anyParsed value, or nil if empty/invalid for optional clears.
- Sharedcityrp.vehicleparams.ValueToText(field, value) → stringSource ☍
-
Convert a field value into a short editor string.
Parameters
- fieldtableField schema entry.
- valueany
Returns
- string
- Sharedcityrp.vehicleparams.AxleFieldSchemaSource ☍
-
Per-axle field template (script Wheel / Suspension nested blocks). Axle 1 is usually the front, axle 2 the rear.
- Sharedcityrp.vehicleparams.FieldSchemaSource ☍
-
Schema describing editor sections and KeyValues export mapping. Axle sections are generated per axle at runtime from this template.
helpis shown in the editor.impactis 1–10 (how much a change usually feels).
- Sharedcityrp.vehicleparamsSource ☍
- Sharedcityrp.vehicleparams.modifiersSource ☍
-
Registered runtime modifiers keyed by id. Future plugins call RegisterModifier; item meta collectors resolve by id.
- Sharedcityrp.vehicleparams.MPH_TO_HUSource ☍
-
Hammer units per second per mile-per-hour. Inverse of Entity:LLSpeed / Photon_AdjustedSpeed: HU/s * (3600 / 63360) = MPH. GetVehicleParams returns engine speeds in HU/s. Since 2021, SetVehicleParams uses the same units (not MPH). Vehicle .txt scripts still store MPH.