Wagons
Vehicle spawn/delete/repair helpers and wheel-bone lookup. Framework-agnostic — pure native wrappers.
SpawnWagon(modelName, x, y, z, heading, opts) → number|nilclient
Spawns a wagon model at the given coordinates. Returns the vehicle handle, or nil on failure.
| Param | Type | Description |
|---|---|---|
| modelName | string | number | Model name or hash. |
| x, y, z | number | Spawn coordinates. |
| heading | number | Spawn heading in degrees. |
| opts.broken | boolean | Damage, freeze, and break the front-left wheel. |
| opts.isMission | boolean | Mark as a mission entity. |
| opts.frozen | boolean | Freeze position without applying damage. |
| opts.timeoutMs | number | Model load timeout in ms. Defaults to 10000. |
DeleteWagon(wagon)client
Safely deletes a wagon entity.
| Param | Type | Description |
|---|---|---|
| wagon | number | Vehicle entity handle. |
RepairWagon(wagon)client
Fixes damage, restores all health values, and makes the wagon driveable.
| Param | Type | Description |
|---|---|---|
| wagon | number | Vehicle entity handle. |
FreezeWagon(wagon, freeze)client
Freezes or unfreezes the wagon's position.
| Param | Type | Description |
|---|---|---|
| wagon | number | Vehicle entity handle. |
| freeze | boolean | True to freeze, false to unfreeze. |
GetWheelPos(wagon, which) → vector3|nilclient
Returns the world position of the specified wheel bone. Falls back to calculated offsets if the model has no matching bone.
| Param | Type | Description |
|---|---|---|
| wagon | number | Vehicle entity handle. |
| which | string | 'lf' (front-left), 'lr' (rear-left), 'rr' (rear-right), 'rf' (front-right). |
example
-- Spawn a broken-down wagon as a scene prop
local wagon = wc:SpawnWagon('WAGON02X', 1234.0, -567.0, 89.0, 45.0, {
broken = true,
isMission = true,
})
-- Later, reveal it's been fixed
wc:RepairWagon(wagon)
-- Clean up
wc:DeleteWagon(wagon)
Real Wild County example — stagecoach breakdown encounter
wc_stagecoach/client/main.lua
local wagon = wc:SpawnWagon('WAGON03X', pos.x, pos.y, pos.z, heading, { broken = true })
local wheelPos = wc:GetWheelPos(wagon, 'lf') -- where the player kneels to fix it
-- after the repair minigame:
wc:RepairWagon(wagon)
wc:FreezeWagon(wagon, false)
Common mistakes
- Calling
WCLib.SpawnWagon(...)from another resource — usewc:SpawnWagon(...). - Forgetting
opts.brokenalready freezes the wagon — callingFreezeWagon(wagon, true)again afterward is redundant, and forgetting to unfreeze afterRepairWagonleaves it undriveable. - Not marking scene-dressing wagons with
isMission = trueand having the engine clean them up unexpectedly. - Assuming
GetWheelPosis pixel-perfect on every wagon model — it falls back to a calculated offset when a model has no matching bone name, which is an approximation.
Troubleshooting
- If
SpawnWagonreturnsnil: the model failed to load withinopts.timeoutMs— check the model name/hash is correct. - If a wagon still won't drive after
RepairWagon: confirm you also calledFreezeWagon(wagon, false)if you froze it separately from thebrokenflag. - If
GetWheelPosreturns an odd position: the model uses non-standard bone names — this falls back to a fixed offset guess, which may not match every custom wagon model exactly.