Skip to content

Tow Truck with Winch v2 โ€‹

Documentation relating to the v2 of the jo_towtruck.

(Documentation relating to the v1)

1. Installation โ€‹

Tow Truck with Winch v2 is a standalone script. So you don't need a specific framework to use it. It's also mean it works with all framework (Esx, QBCore, VRP, DRP, โ€ฆ).

  • Drag and drop the resource in your resources folder
    • jo_towtruck
  • Add it to your server.cfg
    • ensure jo_towtruck

Congratulation, the Tow Truck with Winch v2 script is ready to be use !

2. Usage โ€‹

By default, the script is configured to work with a custom flatbed : flatbed3 and with the native slamtruck. Use your admin menu (or other scripts) to spawn it. To add your own truck, use the configuration command.

A help message with key will appears at the bottom right of your screen every time action is available. Please read them to know what keys are usable.

  1. Move the bed down from inside the vehicle or near the rear wheels
  2. Go to the top of bed to take the winch.
  3. Go to the front of the car you want to tow to attach the winch.
  4. Go near the rear wheel of tow truck to roll up the winch
  5. If you need to detach the winch, go back to the front of car and take the winch. You can store it by go back to the top of bed.
  6. You can also store the winch directly from prompts near the rear wheels.
  7. Once the car on the bed. You have the possibility to attach the car on it. Go near the rear wheel of the truck to have this option. It will automatically store the winch if you didn't do it before.
  8. Move the bed up from inside the vehicle or near the rear wheels.

The configuration file is config.lua in the resource root. Edit this file to change the settings of the script, then restart the resource.

Keep a copy of your changes before updating the script, as an update replaces this file.

Loading configuration...

4. Add a new vehicle โ€‹

Configuration command

The script configures a new truck for you: /towtruckcalibrate <model> checks if the truck is compatible, finds its bones and measures its bed.

1. Enable Debug Mode โ€‹

  • Edit Config.debug = true into the config.lua file.
  • Restart the script with the server command: ensure jo_towtruck.

2. Run the configuration command โ€‹

  • Stand on a flat ground and use /towtruckcalibrate <model> (example: /towtruckcalibrate flatbed3).
  • The truck spawns on you and its bed moves: the result is shown in notifications and in the F8 console.
  • Copy the configuration printed in the F8 console into the config.lua file. Example for the flatbed3:
lua
Trucks[`flatbed3`] = {
  winchBone = "misc_b",
  attachVehBone = "misc_a",
  minBedPosition = 9.66,
  maxBedPosition = 14.26,
}
  • At the end, the bed movement is played with these values to check them.
My truck has a forklift bed

The command asks you to press SHIFT to lower the bed, then gives the bones only: the bed of these trucks is moved by the driver (see Trucks with a forklift bed).

Set the values manually
  • In-game, you can see the vehicle's bones by aiming at it with right-click while standing outside.
  • winchBone: a bone near the winch reel.
  • attachVehBone: a bone attached to the bed that follows its movement.
  • minBedPosition and maxBedPosition: the current value is printed in the F8 console while the bed moves.

3. Configure winch and Attachment Points โ€‹

  • Restart the script with the server command: ensure jo_towtruck.
  • Exit the truck: debug markers will show up.
  • Use the winchOffset to fine-tune the position of the winch.
  • Use the attachOffset to fine-tune the position of the attachment, it should align with the surface of the bed.

4. Test Your Setup โ€‹

To tow a vehicle:

  • Spawn the truck.
  • Go near the rear wheels.
  • Press โ†“ to lower the bed.
  • Go to the winch reel location.
  • Press E to take the winch.
  • Go near the vehicle you want to tow.
  • Press E to attach the winch.
  • Go near the truck's rear wheels.
  • Press โ† to wind the winch and release when the vehicle is on the truck.
  • Press Alt to attach the vehicle to the bed.
  • Press โ†‘ to raise the bed.
  • Done, the vehicle is towed!

To untow a vehicle:

  • Go near the rear wheels.
  • Press โ†“ to lower the bed.
  • Press E to attach the winch to the vehicle.
  • Press โ†’ to unwind the winch and release โ†’ when the vehicle is fully off.
  • Go near the vehicle.
  • Press E to take the winch.
  • Go to the winch reel location.
  • Press E to store the winch.
  • Go near the rear wheels or inside the truck.
  • Press โ†‘ to raise the bed.
  • Done, the vehicle is untowed!

5. Optional parameters โ€‹

minBedPosition and maxBedPosition are distances in meters between the front of the truck and the attachVehBone, measured by the configuration command.

The bed movement is too slow or too fast.

You can increase/decrease the bed movement by adding the bedSpeed value into your truck configuration.

lua
Trucks[`flatbed3`].bedSpeed = 2.0
The bed doesn't lower enough, or lowers too much and lifts the truck.

You can edit the maximum of bed movement by adding the maxBedPosition value into your truck configuration.

lua
Trucks[`flatbed3`].maxBedPosition = 13.5
The bed moves in the cab or doesn't raise enough.

You can edit the minimum of bed position by adding the minBedPosition value into your truck configuration.

lua
Trucks[`flatbed3`].minBedPosition = 10.0
The winch doesn't wind enough or wind too much.

You can edit the minimum of winch length by adding the minWinchLength value into your truck configuration.

lua
Trucks[`flatbed3`].minWinchLength = 0.65
My truck has a wheel lift that I have to move down

You can use the wheelLift key to move the wheel lift up/down when the bed move.

lua
Trucks[`flatbed3`].wheelLift = { 5 } -- list of doors index

6. Finalize โ€‹

  • Once everything is working think to Disable the debug mode by setting Config.debug = false.

5. For developer โ€‹

Restrict the tow truck script to a specific job โ€‹

You can turn off the script for a specific player by using this client event

lua
TriggerClientEvent('jo_towtruck:canUseTheScript', source, false)

You can turn on the script again with the same client event

lua
TriggerClientEvent('jo_towtruck:canUseTheScript', source, true)
Job lock on Esx

Inside the config.lua:

lua
if not IsDuplicityVersion() then
  -- Set the valid jobs
  local validJobs = {"police", "mechanical"}
  
  -- Disable the script for everyone
  TriggerEvent('jo_towtruck:canUseTheScript', false)
  
  -- Listening of the job changer
  RegisterNetEvent('esx:setJob', function(job,lastJob)
    for i = 1, #validJobs do
      if job.name == validJobs[i] then
        --Enable the script
        TriggerEvent('jo_towtruck:canUseTheScript', true)
        return
      end
    end
    TriggerEvent('jo_towtruck:canUseTheScript', false)
  end)
end
Job lock on QBCore

Inside the config.lua:

lua
if not IsDuplicityVersion() then
  -- Set the valid jobs
  local validJobs = {"police", "mechanical"}
  
  -- Disable the script for everyone
  TriggerEvent('jo_towtruck:canUseTheScript', false)
  
  -- Listening of the job changer
  RegisterNetEvent('QBCore:Client:OnJobUpdate', function(job)
    for i = 1, #validJobs do
      if job.name == validJobs[i] then
        --Enable the script
        TriggerEvent('jo_towtruck:canUseTheScript', true)
        return
      end
    end
    TriggerEvent('jo_towtruck:canUseTheScript', false)
  end)
end

Integration with other resources โ€‹

The state of every tow truck is stored in state bags on the truck entity. They are readable from any resource (client and server) with Entity(truck).state and you can listen to their changes with AddStateBagChangeHandler. You don't need to edit the script to integrate it.

State bagValueDescription
jo_towtruck_vehicleAttachednetId | nilNetwork ID of the vehicle secured on the bed
jo_towtruck_bedPositionnumber | nilPosition of the bulldozer arm moving the bed, from 0.0 to 1.0
jo_towtruck_rollingnumber | nilSpeed of the bed while it's moving (> 0 lowering, < 0 raising). nil when the bed doesn't move
jo_towtruck_fullDownboolean | niltrue when the bed is fully lowered (maxBedPosition reached)
jo_towtruck_fullUpboolean | niltrue when the bed is fully raised (minBedPosition reached), false when it's lowered. nil if the bed never moved
jo_towtruck_winchAttachedTotable | nilWhere the winch hook is: { player = serverId } (in hand), { hook = netId } (on the ground), { vehicle = netId, bone = boneName } (hooked to a vehicle). nil when the winch is stored
jo_towtruck_windWinchtable | nil{ player = serverId, speed = number } while the winch is winding (speed > 0) or unwinding (speed < 0)

Get the configuration of a truck โ€‹

Available on client and server side. Returns the Trucks entry of the model from the config.lua, or nil if the model isn't a configured tow truck. Optional values not set in the configuration are nil (defaults: minBedPosition = 0.0, minWinchLength = 1.0, bedSpeed = 1.0).

lua
local truckConfig = exports.jo_towtruck:GetTruckConfig(GetEntityModel(truck))
-- or with the model name
local truckConfig = exports.jo_towtruck:GetTruckConfig("flatbed3")
Detect when a vehicle is attached/detached from the bed
lua
-- Server side
AddStateBagChangeHandler("jo_towtruck_vehicleAttached", nil, function(bagName, _, vehNetId)
  local truck = GetEntityFromStateBagName(bagName)
  if truck == 0 then return end
  if vehNetId then
    print("Vehicle attached", NetworkGetNetworkIdFromEntity(truck), vehNetId)
  else
    -- The state bag is not updated yet when the handler is called: it still contains the previous vehicle
    local oldVehNetId = Entity(truck).state.jo_towtruck_vehicleAttached
    print("Vehicle detached", NetworkGetNetworkIdFromEntity(truck), oldVehNetId)
  end
end)
Check the bed and the winch state
lua
local function isBedLowered(truck)
  local state = Entity(truck).state
  return not state.jo_towtruck_rolling and state.jo_towtruck_fullUp == false
end

local function isVehicleSecured(truck, vehicle)
  return Entity(truck).state.jo_towtruck_vehicleAttached == NetworkGetNetworkIdFromEntity(vehicle)
end

local function isVehicleBeingWinched(truck, vehicle)
  local state = Entity(truck).state
  local winch = state.jo_towtruck_winchAttachedTo
  return winch and winch.vehicle == NetworkGetNetworkIdFromEntity(vehicle) and state.jo_towtruck_windWinch ~= nil
end
Detach or delete a transported vehicle

To detach the vehicle from the bed, clear the state bag from the server side:

lua
Entity(truck).state.jo_towtruck_vehicleAttached = nil

If a resource deletes the transported vehicle (scrapyard, impound, โ€ฆ), the truck is automatically released.

6. Some Tow trucks configuration โ€‹

WARNING

This list is not exhaustive. In most of case, if the bed is animated = the truck is compatible with this script

Make a bed movable by the script

The bed must be the scoop bone of the model (GTA bulldozer arm) with a limited rotation, like the flatbed3: its pivot is placed far below the truck, so the rotation looks like a slide. The attachVehBone (and the winchBone if the winch is on the bed) must be children of scoop to follow the bed.

Trucks with a forklift bed

A bed using the forklift forks (forks bone) can't be moved by any script: this is a limitation of FiveM and GTA, not of this script. The driver moves it with SHIFT/CTRL, the winch and the attachment still work.

independent389 โ€‹

lua
Trucks[`independent389`] = {
  winchBone = "attach_male",
  attachVehBone = "misc_z",
  maxBedPosition = 16.0,
  wheelLift = { 5 },
}

Maoam Fahrzeug Design โ€‹

lua
Trucks[`106towmfd1`] = {
  winchBone = "attach_male",
  attachVehBone = "misc_z",
  maxBedPosition = 11.25,
  wheelLift = { 5 }
}
Trucks[`106towmfd2`] = {
  winchBone = "attach_male",
  attachVehBone = "misc_z",
  maxBedPosition = 11.,
  wheelLift = { 5 }
}
Trucks[`106towmfd3`] = {
  winchBone = "attach_male",
  attachVehBone = "misc_z",
  maxBedPosition = 11.5,
  wheelLift = { 5 }
}
Trucks[`112towmfd2`] = {
  winchBone = "attach_male",
  attachVehBone = "misc_z",
  maxBedPosition = 11.25,
  wheelLift = { 5 }
}
Trucks[`112towmfd3`] = {
  winchBone = "attach_male",
  attachVehBone = "misc_z",
  maxBedPosition = 12.25,
  wheelLift = { 5 }
}
Trucks[`112towmfd4`] = {
  winchBone = "attach_male",
  attachVehBone = "misc_z",
  maxBedPosition = 12.5,
  wheelLift = { 5 }
}
Trucks[`112towmfd5`] = {
  winchBone = "attach_male",
  attachVehBone = "misc_z",
  maxBedPosition = 12.5,
  wheelLift = { 5 }
}
Trucks[`112towmfd6`] = {
  winchBone = "attach_male",
  attachVehBone = "misc_z",
  maxBedPosition = 12.25,
  wheelLift = { 5 }
}
Trucks[`389towmfd2`] = {
  winchBone = "attach_male",
  attachVehBone = "misc_z",
  maxBedPosition = 11.75,
  wheelLift = { 5 }
}
Trucks[`389towmfd3`] = {
  winchBone = "attach_male",
  attachVehBone = "misc_z",
  maxBedPosition = 12.5,
  wheelLift = { 5 },
}
Trucks[`389towmfd6`] = {
  winchBone = "attach_male",
  attachVehBone = "misc_z",
  maxBedPosition = 11.75,
  wheelLift = { 5 }
}
Trucks[`440towmfd2`] = {
  winchBone = "attach_male",
  attachVehBone = "misc_z",
  maxBedPosition = 15.0,
  wheelLift = { 5 }
}
Trucks[`440towmfd4`] = {
  winchBone = "attach_male",
  attachVehBone = "misc_z",
  maxBedPosition = 15.5,
  wheelLift = { 5 }
}
Trucks[`cortowmfd4`] = {
  winchBone = "attach_male",
  attachVehBone = "misc_z",
  maxBedPosition = 11.5,
  wheelLift = { 5 }
}
Trucks[`biftowmfd2`] = {
  winchBone = "attach_male",
  attachVehBone = "misc_z",
  maxBedPosition = 11.75,
  wheelLift = { 5 }
}

20ramrbc โ€‹

lua
Trucks[`20ramrbc`] = {
  winchBone = "attach_male",
  winchOffset = vector3(0.0, 0.0, 0.0),
  attachVehBone = "misc_z",
  attachOffset = vector4(0.0, 0.75, 0.0, 0.0),
  maxBedPosition = 13.0,
  minWinchLength = 1.0
}

Lenand's shop โ€‹

lua
Trucks[`actschlepu1`] = {
  winchBone = "attach_male",
  attachVehBone = "misc_z",
  attachOffset = vector4(0.0, 0.0, -0.5, 0.0),
  maxBedPosition = 10.0
}
Trucks[`actschlepu2`] = {
  winchBone = "attach_male",
  attachVehBone = "misc_z",
  attachOffset = vector4(0.0, 0.0, -0.5, 0.0),
  maxBedPosition = 10.0
}
Trucks[`actschlepp`] = {
  winchBone = "attach_male",
  attachVehBone = "misc_z",
  attachOffset = vector4(0.0, 0.0, -0.5, 0.0),
  maxBedPosition = 10.0
}

Last updated: