WM Docs
Documentation / wm_vehiclecontroll / Vehicle Lua

WM_VEHICLECONTROLL / VEHICLE LUA

Build your own wm_vehiclecontroll file!

Build the moving parts and controls for your vehicle. Recovery trucks, fire engines, rotators, cranes and other custom rigs can all use this system. The examples below show where each feature goes in a vehicle Lua file.

Setup

Files and registration

Give each vehicle its own Lua file in the vehicles folder. The script loads files in that folder when the resource starts. The example below uses one moving boom; replace it with the parts on your own model. If several versions share the same equipment, see Vehicle variants.

vehicles/my_rig.lua
RegisterRecoveryVehicleConfig('my_rig', {
    model = 'my_rig',
    name = 'My Rig',
    speed = 1.0,
    control = {
        radius = 20.0,
        menu = { enabled = false }
    },
    props = {
        {
            name = 'boom',
            prop = 'my_rig_boom',
            attach = 'vehicle',
            offSet = { 0.0, -2.0, 0.5 },
            rotation = { 0.0, 0.0, 0.0 },
            rotation_min = { 0.0, 0.0, 0.0 },
            rotation_max = { 15.0, 0.0, 0.0 },
            offset_min = { 0.0, 0.0, 0.0 },
            offset_max = { 0.0, 0.0, 0.0 },
            controlls = {
                { button = 173, movementType = 'rotate', axis = 1, movementAmount = 0.1 },
                { button = 172, movementType = 'rotate', axis = 1, movementAmount = -0.1 }
            }
        }
    }
})

Change my_rig to your vehicle's spawn name, then replace the boom model and positions with your own. Restart the resource to load your changes.

Reference

Vehicle settings

Start with the vehicle model and the parts you want to move. The settings below go inside its vehicle definition, next to props. Attachment and operator options have their own sections further down this page.

FieldPurpose
modelThe vehicle's spawn name. This is how the script recognises it.
nameThe label shown for the vehicle.
propsThe bed, lift, boom and other moving parts. Give each part its own name.
speedHow quickly the moving parts respond. Start at 1.0 and adjust from there.
rootAttachChanges where the whole setup sits on the vehicle. Normally you can leave it out.
controlWhere the operator stands and how the control menu works.
travelDirectAttach / spectatorDirectAttachKeep carried vehicles attached while driving and for nearby players watching. Both are on by default.
Reference

Props and positions

Think of props as the vehicle's working parts: bed, boom, ladder, lift, hook and so on. Each part needs a name, a model and something to attach to. Attach the first part to 'vehicle'; attach later parts to the name of another part if they should move together. Positions use three numbers in X, Y, Z order.

FieldPurpose
name, prop, attachInternal part name, prop model and parent. All three are required for a normal prop.
offSet, rotationStarting local position and rotation.
offset_min, offset_maxTravel limits for move controls.
rotation_min, rotation_maxTravel limits for rotate controls.
controllsList of button-driven actions. The spelling is intentional.
visible, keepCollisionInitial visibility and collision behaviour. visible defaults to true.
boneOptional vehicle bone for a root prop; vehicleBone and boneIndex are also accepted.
virtualA non-visual prop node; a prop model is not required.
winchAttachPointsNamed points on a real prop for the standalone winch.
dynamicpropattachOpt this prop into automatic object attachment.
variantPropPrefix = falseKeep a shared accessory's model name unchanged across variants.
Reference

Controls and supported types

Each part can respond to one or more buttons. Add those actions to its controlls list. The button number chooses the FiveM input; movementType says what the button does. The script supports these ten actions. Placing a person on a part uses a separate setting called pedplace.

movementTypeUseSection
moveTranslate a prop along X, Y or Z.Movement
rotateRotate a prop around X, Y or Z.Movement
toggleShow or hide a prop.Movement
ropeExtend or retract a rig rope/hoist.Rope
waterparticleEmit a particle effect from a prop.Water
attachvehicleFix a whole vehicle to a prop.Vehicle
attachvehiclebywheelCouple by the front wheel bones.Wheels
attachvehiclebybodyCouple by two body points.Body
attachtrailerConnect a trailer at its hitch.Trailer
attachcontainerAttach a container when the roof state permits it.Container
Controls

Button Conditions

Button Conditions decide when a button may be used. Add them to a button inside a prop's controlls. They work with Toggle, Attach Vehicle by Wheel, Attach Vehicle by Body and Attach Trailer. For Toggle, the conditions are checked when showing a hidden part; the same button can still hide it again.

SettingWhat it does
requiresVisiblePropThe named part must be visible.
requiresHiddenPropThe named part must be hidden.
requiresHiddenPropsEvery part in the list must be hidden.
requiresNoWheelAttachmentNo vehicle may be held by the wheel or body pickup.
requiresNoTrailerAttachmentNo trailer may be attached to the rig.
visible = falseStarts this prop hidden. Add it to the prop itself, outside controlls.

Use the exact names of other parts from your props list. This example shows every condition on one Toggle button; keep only the ones your vehicle needs.

Inside the prop that uses the button
visible = false,
controlls = {
    {
        button = 201,
        movementType = 'toggle',
        requiresVisibleProp = 'cover',
        requiresHiddenProp = 'boom',
        requiresHiddenProps = { 'left_foot', 'right_foot' },
        requiresNoWheelAttachment = true,
        requiresNoTrailerAttachment = true
    }
},
Controls

Move / Rotate / Toggle

Move slides a prop, Rotate turns it, and Toggle shows or hides it. Give each movement direction its own button. The axis chooses X, Y or Z; a positive or negative amount chooses which way it moves. Set the prop's minimum and maximum positions so it stops at the right point.

Inside a prop's controlls
controlls = {
    { button = 173, movementType = 'rotate', axis = 1, movementAmount = 0.1 },
    { button = 172, movementType = 'rotate', axis = 1, movementAmount = -0.1 },
    { button = 174, movementType = 'move', axis = 2, movementAmount = 0.01 },
    { button = 175, movementType = 'move', axis = 2, movementAmount = -0.01 },
    { button = 201, movementType = 'toggle' }
}

Set visible to false on a prop that should start hidden. Add only the buttons that make sense for that part of your rig.

Controls

Rope

Rope connects a prop, such as a boom, to a second prop, such as a hook block. One button lets rope out and another reels it in. Give both buttons the same rope name and set attachto to the prop at the other end.

Inside the boom prop's controlls
controlls = {
    {
        button = 173,
        movementType = 'rope',
        name = 'mainHoist',
        attachto = 'hookblock',
        direction = 1,
        speed = 0.5,
        initialLength = 0.5,
        maxLength = 30.0,
        points = {
            { from = { 0.0, 1.0, 0.0 }, to = { 0.0, 0.0, 0.0 } }
        }
    },
    {
        button = 172,
        movementType = 'rope',
        name = 'mainHoist',
        attachto = 'hookblock',
        direction = -1,
        speed = 0.5,
        initialLength = 0.5,
        maxLength = 30.0
    }
},
Controls

Water Particle

Water Particle makes a nozzle or other prop spray a chosen effect when its button is pressed. Set asset and name to the effect you want, then move the spray to the right place with offSet and rotation. The example can be switched on and cycles through three spray sizes.

Inside a nozzle prop's controlls
controlls = {
    {
        button = 157,
        movementType = 'waterparticle',
        asset = 'core',
        name = 'water_cannon_jet',
        toggle = true,
        scales = { 1.0, 1.5, 2.0 },
        offSet = { 0.0, 0.0, 0.0 },
        rotation = { 0.0, 0.0, 0.0 }
    }
},
Attachments · attachvehicle

Attach Vehicle

Attach Vehicle fixes a nearby vehicle to the chosen prop of your rig, such as a flatbed. The offSet and rotation in the button action decide where the vehicle sits. Press the button again to release it.

Where it goes: inside the controlls of the prop that carries the vehicle, such as your bed. Put controlls next to that prop's offSet and rotation.

Inside the bed prop in vehicles/your_vehicle.lua
controlls = {
    {
        button = 47,
        movementType = 'attachvehicle',
        offSet = { 0.0, 0.0, 0.35 },
        rotation = { 0.0, 0.0, 0.0 },
        radius = 8.0
    }
},
Attachments · attachvehiclebywheel

Attach Vehicle by Wheel

Attach Vehicle by Wheel holds a vehicle by its two front wheels on your wheel-lift prop. Put one pickup point under the left wheel and one under the right. The button couples or releases the vehicle.

Where it goes: inside the controlls of your wheel-lift prop.

Inside the wheel-lift prop in vehicles/your_vehicle.lua
controlls = {
    {
        button = 29,
        movementType = 'attachvehiclebywheel',
        axis = 1,
        rotationFollowAxis = 3,
        points = {
            { name = 'left', offSet = { -0.83, -0.65, 0.26 }, bone = 'wheel_lf', radius = 5.0 },
            { name = 'right', offSet = { 0.83, -0.65, 0.26 }, bone = 'wheel_rf', radius = 5.0 }
        }
    }
},
Attachments · attachvehiclebybody

Attach Vehicle by Body

Attach Vehicle by Body holds a vehicle at two points on its body. Use it for a cradle or rotator that lifts the vehicle without gripping the wheels. Put left and right pickup points on the carrying prop, then use the button to couple or release the vehicle.

Where it goes: inside the controlls of the cradle or rotator prop that touches the recovered vehicle.

Inside the cradle prop in vehicles/your_vehicle.lua
controlls = {
    {
        button = 29,
        movementType = 'attachvehiclebybody',
        axis = 1,
        rotationFollowAxis = 3,
        points = {
            { name = 'left', offSet = { -0.68, -0.42, 0.0 }, radius = 5.0 },
            { name = 'right', offSet = { 0.68, -0.42, 0.0 }, radius = 5.0 }
        }
    }
},
Attachments · attachtrailer

Attach Trailer

Attach Trailer lets you place an attach_female hitch point at an offset on one of your rig's props. Press the chosen button to attach a trailer to that prop. The trailer connects through its attach_male bone.

Where it goes: add this button to the prop that holds the trailer hitch. The three position numbers in the example place the hitch on that prop: left or right, forward or back, and up or down.

Inside the hitch prop in vehicles/your_vehicle.lua
controlls = {
    {
        button = 29,
        movementType = 'attachtrailer',
        bone = 'attach_male',
        point = { offSet = { 0.0, -0.21, 0.19 }, radius = 5.0 }
    }
},

The radius sets how close the trailer needs to be to connect; use a value above 0 and no higher than 5.

Attachments · attachcontainer

Attach Container

Attach Container fixes a nearby container to a prop at the position set by offSet and rotation. Its button works only when the vehicle's animConvRoof is at state 2. Press the button again to release the container.

Where it goes: inside the controlls of the prop that holds the container. In this example, that prop is the bed.

Inside the bed prop in vehicles/your_vehicle.lua
controlls = {
    {
        button = 47,
        movementType = 'attachcontainer',
        attachcontainer = 'container_mount',
        anchorProp = 'bed',
        offSet = { 0.0, 0.0, 0.0 },
        rotation = { 0.0, 0.0, 0.0 },
        radius = 8.0
    }
},
Attachments · dynamicAttach

Dynamic Vehicle Attach

Dynamic Vehicle Attach secures another vehicle to any rig prop listed in allowedProps. You can list several props. Set vehicle to true to allow attachment to the rig's vehicle body as well, or false to use only the listed props.

Where it goes: next to props in the vehicle Lua file. This feature has no controlls action.

Next to props in the vehicle file
dynamicAttach = {
    allowedProps = { 'bed' },
    vehicle = true,
    automatic = true
},

Add more prop names after bed, separated by commas. With automatic set to true, a vehicle can be secured after it comes to rest on an allowed surface. Set it to false when the operator should attach it manually.

Attachments · dynamicpropattach

Dynamic Prop Attach

Dynamic Prop Attach secures loose objects on a rig prop, such as equipment on a bed. When the vehicle travels, those objects stay with the prop. Add this setting to the prop that carries them; there is no button action for it.

Inside the bed prop in vehicles/your_vehicle.lua
dynamicpropattach = {
    radius = 3.0,
    surfaceTolerance = 0.35,
    maxHeight = 2.5,
    maxObjects = 8
},

Radius sets the area around the prop. Surface tolerance and maximum height decide which objects count as cargo; maxObjects limits how many are secured. For the standard values, set dynamicpropattach to true on the prop. This works with networked objects.

Driver option · disableoutsidecontroll

Disable Outside Control

Disable Outside Control keeps operation inside the cab. Set it to true to block the outside control mode and let the driver select rig parts from their seat. Add this line beside props in the vehicle Lua.

Next to props in the vehicle file
disableoutsidecontroll = true,
Driver option · cancontrollselectedpropsfrominside

Control Selected Props from Inside

Control Selected Props from Inside lets the driver operate chosen parts from the seat while outside operation remains available. Set the vehicle option to true, then add allowseatmoving to each prop the driver may select. Unmarked props stay out of the inside selection.

Next to props in the vehicle file
cancontrollselectedpropsfrominside = true,
Inside each permitted prop
allowseatmoving = true,

The vehicle option goes beside props; allowseatmoving goes inside each permitted prop. That prop still needs its usual movement buttons.

Driver option · raisetrailerleg

Raise Trailer Leg

Raise Trailer Leg gives the operator a button to raise the support legs on an attached trailer. Set the number to the FiveM button you want. If no trailer is connected, the operator gets a message. Add this beside props in the vehicle Lua.

Next to props in the vehicle file
raisetrailerleg = 47,
Rig option · indicatorsonmoving

Indicators on Moving

Indicators on Moving switches on the rig's hazard lights while someone operates its equipment. When operation ends, the previous indicator state returns. Set it to true beside props in the vehicle Lua.

Next to props in the vehicle file
indicatorsonmoving = true,
Rig option · animroofblock

Anim Roof Block

Anim Roof Block stops the operator from toggling the animated roof while they control the rig. Set it to true beside props in the vehicle Lua. Return to Default can still close the roof if that feature is enabled.

Next to props in the vehicle file
animroofblock = true,
Rig option · closeanimroofatreturnlast

Close Anim Roof at Return

Close Anim Roof at Return closes the animated roof after Return to Default has put the rig's moving parts away. Set it to true beside props in the vehicle Lua.

Next to props in the vehicle file
closeanimroofatreturnlast = true,
People · pedplace

Ped Place

Ped Place gives a player a position on a prop, such as a cage or basket. Add it inside that prop's controlls and choose the command they use to get on or off. One command can do both; you can also give entering and leaving separate commands.

Inside a cage prop's controlls
controlls = {
    {
        pedplace = true,
        command = 'cage',
        pedplacecontroll = true,
        offSet = { -0.2, 1.0, 0.95 },
        rotation = { 0.0, 0.0, 0.0 }
    }
},

For a stretcher, setplayerinit = true lets the operator choose a nearby player to place on it. This mode needs pedplacecontroll = false. To play an animation while that player is on the prop, set animation = true. thisdict names the animation set; thisname names the animation within it. Both must be filled in when animation is enabled.

Inside a stretcher prop's controlls
controlls = {
    {
        pedplace = true,
        command = 'stretcher',
        pedplacecontroll = false,
        setplayerinit = true,
        offSet = { 0.0, 0.0, 1.255 },
        rotation = { 0.0, 0.0, -90.0 },
        animation = true,
        thisdict = 'anim@gangops@morgue@table@',
        thisname = 'body_search'
    }
},

Add pedPlaceHideGuard = true to the prop if it should stay visible while someone is on it.

People · control

Operator Control

Operator Control sets where a person can operate the rig and what happens when they start. Radius decides how close they must be; attach chooses the vehicle body or a moving prop as their operating point. You can open a menu and play a remote-control animation. Add this table beside props in the vehicle Lua.

Set secondaryremotecontrol = true to offer a second handheld remote option. The player can start control near the vehicle without standing at the usual operator point. The radius still decides how close they need to be.

Top level control table
control = {
    radius = 20.0,
    attach = 'vehicle',
    secondaryremotecontrol = true,
    menu = {
        enabled = true,
        resourceName = 'my_vehicle_menu',
        automaticOpen = true,
        key = 311,
        ownsFocus = true,
        returnControl = 56
    },
    animation = {
        enabled = true,
        idle = { dict = 'wm_wv_pedanim', name = 'idle', flag = 49 },
        prop = {
            enabled = true,
            model = 'wm_wv_remotecontroll',
            attachToPed = {
                boneIndex = 57005,
                offSet = { 0.19, 0.05, -0.22 },
                rotation = { -60.0, -114.0, 12.0 }
            }
        }
    }
},
Winch · winchAttachPoints

Winch Attach Points

Winch Attach Points adds places where a winch can connect on a rig prop. The player chooses one of these fixed points, then chooses what to pull. Add the points to the prop; offSet places each one on the model and radius sets how close the player must stand.

Inside a prop definition
winchAttachPoints = {
    { name = 'left', offSet = { -1.15, 0.0, -0.56 }, radius = 1.5 },
    { name = 'right', offSet = { 1.15, 0.0, -0.56 }, radius = 1.5 }
},
Models

Vehicle Variants

Vehicle Variants lets several versions of the same rig share one prop layout, such as ELS and non-ELS models. In each row, the first name is the vehicle's spawn name. The second is the prefix used by that version's prop models. The third is the menu resource for that version. Add these rows to extravehiclenames in the vehicle Lua.

The third name is optional. Leave it out to use the menu resource from control.menu, or use an empty string to disable the menu for one variant.

Variant registration pattern
local baseConfig = {
    model = 'my_rig_els',
    extravehiclenames = {
        { 'my_rig_els', 'wm_my_rig_els', 'my_rig_els_menu' },
        { 'my_rig_non', 'wm_my_rig_non', 'my_rig_non_menu' }
    },
    control = { radius = 20.0, menu = { enabled = true, resourceName = 'my_rig_els_menu' } },
    props = {
        {
            name = 'bed',
            prop = 'wm_my_rig_els_bed',
            attach = 'vehicle',
            offSet = { 0.0, -2.0, 0.5 },
            rotation = { 0.0, 0.0, 0.0 },
            rotation_min = { 0.0, 0.0, 0.0 },
            rotation_max = { 0.0, 0.0, 0.0 },
            offset_min = { 0.0, 0.0, 0.0 },
            offset_max = { 0.0, 0.0, 0.0 },
            controlls = {}
        }
    }
}

RegisterRecoveryVehicleVariants(baseConfig)

The first prefix must match the base prop names in your file. An accessory can use the same model on every version.