[STANDALONE] Flatbed Towing Script

gif

towing unhook

FiveM Script (standalone) for towing vehicles

  • Works with ox_target (required)
  • Restrictions for multiple jobs
  • Optional check if the flatbeds engine must be running
  • Optional check if the vehicle to be towed must be unlocked
  • All durations configurable
  • Adjust the placement on the flatbed (configurable controls and sensitivity)
  • Comes with sounds and notification / progress bar (optinal, you can use others)
  • Completely in sync every other tow truck driver can load/unload the vehicles
  • Endless flatbed models can be set in config
  • Works with all vehicle classes (configurable blacklist)
  • Even works if NPCs or players are using the vehicle




Towing with trailers

You can also tow with trailers. This will be enhanced in the next update.
For the time being you can add trailers in the config like this:

{   
    model = 'armytrailer',
    controlPos = vector3(-2.017, 2.502, -1.998),    -- The offset of the vehicle from where the flatbed should be controlled
    attachPos = vector3(0.0, -0.50, -0.25),        -- The inital position of the vehicle on the flatbed
    unloadPos = vector3(0.015, -12.368, -1.235),  -- The position where the car will be placed after unloading it
    initialTilt = 0.0,                          -- The initial tilt when the vehicle ist first brought up on the flatbed
    bone = 'bodyshell',                         -- The vehicle bone from where the offset will be calculated
    },

Be sure to set Config.MotorOn = false if you want to use trailers.

Price: 3+
Find this and more scripts on: fivehead.eu

Config
Config = {}    

Config.qbtarget = false            -- This script uses ox_target by default. If you're running qb-target on your server set this to true.
Config.JobRestriction = true
Config.JobList = {["lscustoms"] = 0, ["bennys"] = 0, ["mechanic"] = 0}          -- Jobs that can use the flatbed the number is equal to the lowest job rank that can use the flatbed

Config.ClassBlacklist = {10, 11, 14, 15, 16, 20, 21}            -- Vehicle classes that should not be loadable onto the flatbed https://docs.fivem.net/natives/?_0x29439776AAA00A62

Config.ControlDistance = 1.0                                        -- From how far away the tow truck should be controlable
Config.FlatbedAnimDict = 'amb@prop_human_atm@male@idle_a'           -- Animation directory for using the flatbed controls 
Config.FlatbedAnimClip = 'idle_b'                                   -- Animation clip for using the flatbed controls
Config.MotorOn = true               -- If the engine of the flatbed truck must be running to use it
Config.CheckSpace = 0.25            -- How much space must be behind the tow truck to unload. Set it to false to not check for space (will delete the colliding entities). 
Config.AdjustmentSteps = 0.05       -- How fast or precisely you want to align the vehicle on the flatbed
Config.AlignmentDivergence = 20     -- How far off the angle of the vehicle to be towed can be (in degrees 0 to 180)
Config.LoadingTime = 5              -- How long it should take to load/unload a vehicle (in seconds)
Config.MaxTilt = 15                 -- The maximum tilt degree the player can set while loading the vehicle onto the flatbed.
Config.MaxOffset = 1.0              -- The maximum Y and Z offset (in GTA units) the player can set while loading the vehicle onto the flatbed.
Config.CarelessUnhook = true        -- If the vehicle that's towed can be unhooked from the drivers seat. (Keep in mind there is no job restriction for this all players can, when on the drivers seat of the tow truck, unhock the vehicle)
Config.HoldTime = 0.7               -- How long you need to hold down the unhook button before it actually unhooks (in seconds)
Config.UnhookWithForce = 12         -- The force that is applied to the vehicle after unhooking it. If you don't want to apply any force set this to false. If you want to have some fun set this to numbers > 100 :D


-- Controls                         -- https://docs.fivem.net/docs/game-references/controls/
Config.up           = 172           -- Arrow up
Config.down         = 173           -- Arrow down
Config.forwards     = 174           -- Arrow left
Config.backwards    = 175           -- Arrow right
Config.tiltfront    = 38            -- Q
Config.tiltback     = 44            -- E
Config.UnhookKey    = 74            -- H (only enabled while Config.CarlessUnhook = true)


-- Door options
Config.VehicleOpen = true           -- If the vehicle must be unlocked to be towed
Config.DoorOpening = true           -- If you want to give wrecker driver the ability to unlock cars
Config.DoorOpeningTime = 15         -- How long the opening of a locked vehicle takes (in seconds)
Config.UnlockDistance = 0.7         -- How close you need to be to the vehicle to unlock it
Config.UnlockAnimDict = 'anim@amb@clubhouse@tutorial@bkr_tut_ig3@'  -- Animation directory for opening vehicle doors
Config.UnlockAnimClip = 'machinic_loop_mechandplayer'               -- Animation clip for opening vehicle doors

-- Sounds | Progess Bar
Config.Volume = 0.8                 -- The volume of the sounds done by this script
Config.SoundRange = 7.0             -- How far the sounds should be heard
Config.ProgressBar = true           -- Wether you want to use the progress bar
Config.HideBarAfter = 5             -- After how many seconds without interaction the progressbar should be hidden.
Config.ProgressColor = '#4eb3de'    -- Here you can edit the progress color to your likings. https://g.co/kgs/qpnR1M
Config.FinishedColor = '#4ede83'    -- Here you can edit the finished color to your likings. https://g.co/kgs/qpnR1M
Config.InfoColor = '#ede174'        -- Here you can edit the color for the wax notification to your likings. https://g.co/kgs/qpnR1M
Config.WrongColor = '#eb584d'       -- Here you can edit the color for the wrong action to your likings. https://g.co/kgs/qpnR1M


--// For your convenience I have made an "offset" command. It will print you the offset to the vehicle you are looking at. 
-- Usage /offset
-- Example result: "The offset to the SLAMTRUCK is vec3(-1.59, -1.62, -0.14)""

Config.TruckList = {
    {   
    model = 'flatbed',                          -- The model of the towtruck or trailer
    trailer = false,                            -- If true overrides Config.MotorOn because trailers dont have engines
    controlPos = vector3(-1.59, -1.62, -0.14),  -- The offset of the vehicle from where the flatbed should be controlled
    attachPos = vector3(0.0, -2.5, 0.8),        -- The inital position of the vehicle on the flatbed
    unloadPos = vector3(0.015, -9.368, -0.235), -- The position where the car will be placed after unloading it
    initialTilt = 0.0,                          -- The initial tilt when the vehicle ist first brought up on the flatbed
    bone = 'chassis_dummy',                         -- The vehicle bone from where the offset will be calculated
    },

    {   
    model = 'slamtruck',                        -- The model of the towtruck or trailer
    trailer = false,                            -- If true overrides Config.MotorOn because trailers dont have engines
    controlPos = vector3(-1.59, 0.0, -0.14),    -- The offset of the vehicle from where the flatbed should be controlled
    attachPos = vector3(0.0, -2.0, 1.0),        -- The inital position of the vehicle on the flatbed
    unloadPos = vector3(0.015, -7.368, 0.235),  -- The position where the car will be placed after unloading it
    initialTilt = 7.0,                          -- The initial tilt when the vehicle ist first brought up on the flatbed
    bone = 'chassis_dummy',                         -- The vehicle bone from where the offset will be calculated
    },

    {   
    model = 'armytrailer',                          -- The model of the towtruck or trailer
    trailer = true,                                 -- If true overrides Config.MotorOn because trailers dont have engines
    controlPos = vector3(-2.017, 2.502, -1.998),    -- The offset of the vehicle from where the flatbed should be controlled
    attachPos = vector3(0.0, -0.50, -0.25),         -- The inital position of the vehicle on the flatbed
    unloadPos = vector3(0.015, -12.368, -1.657),    -- The position where the car will be placed after unloading it
    initialTilt = 0.0,                              -- The initial tilt when the vehicle ist first brought up on the flatbed
    bone = 'bodyshell',                             -- The vehicle bone from where the offset will be calculated
    },
    --[[ {
    model = 'flatbedm2',                            --Config for the Flatbed M2 Crew Cab Addon Vehicle (https://de.gta5-mods.com/vehicles/freightliner-m2-crew-cab-flatbed-add-on-script-beta)
    trailer = false,
    controlPos = vector3(-1.93, 1.12, 0.24), 
    attachPos = vector3(-0.004, -2.37, 0.775),
    unloadPos = vector3(0.15, -11.21, 0.24),
    initialTilt = 0.0,
    bone = 'chassis_dummy', 
    }, ]]
}


-- // English Locales

Config.use_controls = "Use flatbed controls"
Config.unload_vehicle = "Unload a vehicle"
Config.load_vehicle = "Load a vehicle"
Config.vehicle_locked = "You can't tow a locked vehicle"
Config.steep_angle = "Vehicle needs to be somewhat aligned."
Config.no_vehicle_found = "There is no vehicle in reach"
Config.vehicle_blacklist = "You can't tow this vehicle"
Config.space_occupied = "Theres something in the way. You can't unload here."
Config.unloading_vehicle = "The vehicle is being unloaded"
Config.vehicle_unloaded = "The vehicle has been unloaded"
Config.loading_vehicle = "The vehicle is being loaded"
Config.loading_canceled = "You have canceled the process"
Config.vehicle_loaded = "The vehicle has been loaded"
Config.truck_occupied = "This truck is currently used by someone else"
Config.open_vehicle = "Force open the vehicle"
Config.opening_vehicle = "Force opening the vehicle"
Config.opened_vehicle = "You opened the vehicle"
Config.opening_canceled = "You stopped opening the vehicle"
Config.not_further = "Can't move this any further in this direction"
Config.unhooked = "You unhooked the vehicle!"


-- // German Locales

--[[ 
Config.use_controls = "Steuerung des Abschleppers"
Config.unload_vehicle = "Ein Fahrzeug abladen"
Config.load_vehicle = "Ein Fahrzeug aufladen"
Config.vehicle_locked = "Du kannst kein verschlossenes Fahrzeug abschleppen"
Config.steep_angle = "Fahrzeug muss einigermaßen ausgerichtet sein"
Config.no_vehicle_found = "Es ist kein Fahrzeug in Reichweite"
Config.vehicle_blacklist = "Dieses Fahrzeug kannst du nicht abschleppen"
Config.space_occupied = "Es ist etwas im weg. Du kannst hier nicht abladen"
Config.unloading_vehicle = "Das Fahrzeug wird abgeladen"
Config.vehicle_unloaded = "Das Fahrzeug wurde abgeladen"
Config.loading_vehicle = "Das Fahrzeug wird aufgeladen"
Config.loading_canceled = "Du hast den Prozess abgebrochen"
Config.vehicle_loaded = "Das Fahrzeug wurde aufgeladen"
Config.truck_occupied = "Die Steuerung wird bereits genutzt"
Config.open_vehicle = "Fahrzeug aufknacken"
Config.opening_vehicle = "Knacke das Fahrzeug"
Config.opened_vehicle = "Fahrzeug wurde entriegelt"
Config.opening_canceled = "Öffnen wurde abgebrochen"
Config.not_further = "Weiter kannst du das Fahrzeug nicht bewegen"
Config.unhooked = "Du hast das Fahrzeug ausgeklinkt!" 
Config.capacity_reached = "Für dieses Fahrzeug ist auf der Ladefläche kein Platz mehr"
]]
Changelog

Version 1.1.7:
Fixes:

  • Added some CSS rules for widescreen resolutions thanks to @Stoned.DEV
  • Changed the Job.Restriction format to work with qb-target from the get go

Additions:

  • Opened up a vehicle check if the vehicle is allowed to be towed (to prohibit powergaming e.g. towing boosting cars) My apologies to @GrizzyVV for taking so long to put this in.

Version 1.1.6:
Additions:

  • New /offset command that could be handy when setting up new flatbeds/trailers
  • Added qb-target compatibility

Fixes:

  • Fixed a bug that prevented the vehicle to have collision and full alpha after unloading. (Could only be reproduced with multiple players. Thanks to Xcaliber and Darbit for pointing it out)
  • Fixed warning messages that only occur on OneSync Infinity

Version 1.1.0:
Additions:

  • You can now (optionally) unhook the vehicle on the flatbed while driving by pressing ‘H’ (default) for 0.7 Seconds (default)
  • It will apply some force to the vehicle unhooked and shove it off the flatbed (optional)
  • Added QoL improvement where inital tilt is set to the car being loaded (good for slamtruck)
  • Added MaxOffset and MaxTilt values to prevent your players going for ultra strange positions on the flatbed

Fixes:

  • Fixed NPC cars sometimes despawning while loaded onto the flatbed
  • Fixed collision issue that sometimes happened while loading vehicle onto the flatbed
  • Fixed an issue where the roation looked odd at first when loading vehicle onto the flatbed
  • Changed the attachPos values of the SLAMTRUCK. Now most vehicles should be in the right position initially

Version 1.0.4:

  • Added the option to disable the job restriction
FAQ

Q: **I have ox_target (or qb_core) set up but it does not show me the control actions of the flatbed.
A: *This can have multiple causes.

  • Do you have the right job or set Config.JobRestriction to false?
  • Are you standing at the right offset to the vehicle?
  • Is the engine running or do you have set Config.MotorOn to false?

Q: Why is such a small script escrowed?
A: I experienced if the code is open people do their changes themselves and they are for a single server only. If people must ask me to implement some changes every customer profits from it. Often there are great ideas that I didn’t even think of and the script highly benefits from it.

Q: Why should I buy this when there are free scripts?
A: You shouldn’t.

Code is accessible No
Subscription-based No
Lines (approximately) 800
Requirements ox_target or qb-target
Support Yes
4 Likes

if it’s standalone why does it check for a job? I suggest you add a config option for job check and unlock the function to check the player’s job so users can adapt to their framework.

Hi, thank you for your message.
The job check is actually handled through the dependency [ox_target] (Options - Ox Target) and you would need to do edit your custom framework needs there.

* groups?: `string` or `string[]` or `table<string, number>`
  * A group, array of groups, or pairs of groups-grades required to show the option.
  * Groups are framework dependent, and may refer to jobs, gangs, etc.

Nontheless I added an option to disable it alltogether.

Have a nice day :+1:

1 Like

Very good new feature:

Spoiler

Of course the video is just a joke and this only happens if you go nuts in the config.
But heres a pretty cool update nonetheless:

Version 1.1.0:
Additions:

  • You can now (optionally) unhook the vehicle on the flatbed while driving by pressing ‘H’ (default) for 0.7 Seconds (default)
  • It will apply some force to the vehicle unhooked and shove it off the flatbed (optional)
  • Added QoL improvement where inital tilt is set to the car being loaded (good for slamtruck)
  • Added MaxOffset and MaxTilt values to prevent your players going for ultra strange positions on the flatbed

Fixes:

  • Fixed NPC cars sometimes despawning while loaded onto the flatbed
  • Fixed collision issue that sometimes happened while loading vehicle onto the flatbed
  • Fixed an issue where the roation looked odd at first when loading vehicle onto the flatbed
  • Changed the attachPos values of the SLAMTRUCK. Now most vehicles should be in the right position initially

anyway you can make it standalone? meaning doesn’t depend on esx/qb

Yes, it’s just the locales that I need to do differently. Honestly I never worked with another framework than esx and didn’t even know I can’t do them like this. I’ll catch some sleep and then I’ll think of a solution.

Okay, it should be real standalone now. Please try and give me feedback.

1 Like

I’m from ESX, and my profession is also a mechanic, but I just don’t know how to use him

Hi. Please check your config. Maybe the engine of the truck must be on.

You can also use trailers to tow vehicles. This will be enhanced further in the next update.

Any possibility of qb target

Well maybe that a possibility. But are you sure you don’t want to try out ox_target? From what I read it’s faster and mostly compatible to scripts with qb_target.

ox_target is the successor to qtarget, which was a mostly-compatible fork of bt-target. To improve many design flaws, ox_target has been written from scratch and drops support for bt-target/qtarget standards, though partial compatibility is being implemented where possible.

  • Performance increased ~4x compared to qtarget.
  • Improved error handling protects against soft-locking.
  • Improved entity and world collision detection.
  • Options now stack, rather than overriding.

God I really want to but man what a journey it would be to convert all my scripts to it lol

It’s compatible with qb_target. They should work right of the box. Give it a try. :+1:

I tried this. I used ox_target but can’t see its options.

Hi, if your ox_target does work and you have put this script in the right folder it should work without problems.

If it does not show you the ox_target options it can be one of these problems:

  • You have the wrong job or did not set Config.JobRestriction = false (if you are on a framework diffrent ot QB and ESX you need to set this to false or edit your ox_target to your framework)
  • The engine of the truck is not running or you did not set Config.MotorOn = false
  • You are not standing at the right position or are not facing the (middle of the) truck
  • You changed something in the config and made a mistake (like forgetting a bracket or a comma). Thus the script is not starting. (check your client and server console for errors)

Position of the controls for the flatbed :

Position of the controls for the slamtruck :

@fivehead.eu We want to prevent powergamers from towing cars involved in boosting missions. Could you offer a way to allow us to insert logic to check if a vehicle is allowed to be towed?

The boosting script we use is rahe_boosting and they provide logic to check if car is involved in a mission or not, just need a place to put it.

I’ll think of a way to add your request and push it in the next update. :+1:

1 Like

Thank you. I’ve purchased the scripting and I will await your update, cheers.

if i bought the script when it was free, do I still get updates or do I need to pay to get the new one?