[RELEASE][STAND ALONE] CW Tow (for PJ Trailer)

TOW TWO VEHICLES AT ONCE

cw_tow

This is a basic tow script for fivem using chat commands.

This is a simple tow script setup to use PJ Trailer by DeezNutties123 on GTA5-mods. Changing the model on your server might break the script as it attaches the vehicle you want to tow to a specific bone on the trailer.

Please note that if the last vehicle you’ve used is not the PJ Trailer, then you wont be able to load it, and theres no distance built into the script yet, so it wont know if you are loading a vehicle 100ft away or just 10ft away. Either make it yourself or wait for an update :wink:

Installation:

Download from Github.

Add cw_tow to resources folder.

Add “start cw_tow” to server.cfg

Usage:

Get in the PJ Trailer like you would any vehicle - (the script looks for your last driven vehicle, and it needs it to be the PJ Trailer)

Go near a vehicle you want to tow and write:
/ftow (to load the front of the trailer),
/btow (to load the back of the trailer), or
/ctow (to load a single vehicle on the trailer) in the chat-

Drive around

Type the command again to unload the vehicle.

V1.0 - Initial commit

Support:

If you can’t figure out how to use this overly simple script, I can’t help you.

I will not help you create a resource for the PJ Trailer, nor will I supply one. You are a server owner, you should already know how to do this very simple task.

NOTE:
Not all cars have the same bones. Some might sit high, some might sit low. Others will sit nearly perfect. I can’t control that.

Screenshots (for people who never seen a car on a trailer before)

8 Likes

FYI - you can register the commands client-side. Other than that, great job. Thanks for sharing.

2 Likes

Can you help me create a script for the pjtrailer? Lmao JKS but i can imagine there will actually be ppl that will be serious

It’s actually why I tossed it together. Someone of Facebook asked about a tow script for that trailer. So I downloaded the trailer and made it.

2 Likes

Yea it’s nice little script. I may add it to my tow job

1 Like

Very Nice, I added to it and put in commands for the Enclosed Gooseneck that Bagged made. Hardest thing is lining up vehicles around the tool boxes lol. I might even setup this trailer for dealership RPs. https://www.gta5-mods.com/vehicles/car-trailer-hauler
Thanks for making this m8, it’ll definitely get used.

2 Likes

Single vehicle or multi? I was thinking about doing that myself since I use that trailer as well.

1 Like

I did two on the enclosed gooseneck, I haven’t done the big trailer yet.

1 Like

Anyone know if we can add these to the shop for esx so people can buy them?

yes you can i have them in my dealer so civs can buy them

how did you add it in the lua? I’m trying to but it wont work.

just repeat the code with different commands so nothing conflicts… I don’t have the code on hand but if you need help PM me.

EDIT: As far as I can remember this tow script is one of the ones that doesn’t break so I’m going to be using it. I’ll post the edited code when I’m done…

EDIT 2;

to add another command you need to register it in the sv_b_tow.lua (server side) with this;

-- CodeDesignz cotrailer
RegisterCommand('cotow', function(source, args)
TriggerClientEvent("cwc:cotow", source)
end, false)

This one is edited to match the command I’m creating…
Now we move to the client side/cl_b_tow.lua
Here is the actual code that makes the script work. What we need to do is assign the command to the Client Event. Change ‘cotrailer’ to the specific trailer you want. Also change ‘cotow’ to the command you set in the server side. In case you didn’t notice since the cotrailer is a single vehicle hauler I used the center tow code. Copy from the front and rear if you plan on doing so…

------------------------------------
-- CodeDesignz cotrailer 
------------------------------------

local currentlyCenterTowedVehicle = nil

RegisterNetEvent('cwc:cotow')
AddEventHandler('cwc:cotow', function()
	
	local playerped = GetPlayerPed(-1)
	local vehicle = GetVehiclePedIsIn(playerped, true)
	
	local centertowmodel = GetHashKey('cotrailer')
	local isVehicleTow = IsVehicleModel(vehicle, centertowmodel)
			
	if isVehicleTow then
	
		local coordA = GetEntityCoords(playerped, 1)
		local coordB = GetOffsetFromEntityInWorldCoords(playerped, 0.0, 5.0, 0.0)
		local targetVehicle = getVehicleInDirection(coordA, coordB)
		
		if currentlyCenterTowedVehicle == nil then
			if targetVehicle ~= 0 then
				if not IsPedInAnyVehicle(playerped, true) then
					if vehicle ~= targetVehicle then
						AttachEntityToEntity(targetVehicle, vehicle, 0.0, 0.0, -1.0, 0.5, 0.0, 0.0, 0.0, false, false, false, false, 20, true)
						currentlyCenterTowedVehicle = targetVehicle
						TriggerEvent("chatMessage", "[CW Tow]", {255, 255, 0}, "Your vehicle has been loaded onto CoTrailer!")
					else
						TriggerEvent("chatMessage", "[CW Tow]", {255, 255, 0}, "Are you retarded? You cant tow your own trailer with your own trailer?")
					end
				end
			else
				TriggerEvent("chatMessage", "[CW Tow]", {255, 255, 0}, "Theres no vehicle to load?")
			end
		else
			AttachEntityToEntity(currentlyCenterTowedVehicle, vehicle, 0.0, 0.0, -1.0, 0.6, 0.0, 0.0, 0.0, false, false, false, false, 20, true)
			DetachEntity(currentlyCenterTowedVehicle, true, true)
			currentlyCenterTowedVehicle = nil
			TriggerEvent("chatMessage", "[CW Tow]", {255, 255, 0}, "The vehicle has been successfully unloaded!")
		end
	end
end)


function getVehicleInDirection(coordFrom, coordTo)
	local rayHandle = CastRayPointToPoint(coordFrom.x, coordFrom.y, coordFrom.z, coordTo.x, coordTo.y, coordTo.z, 10, GetPlayerPed(-1), 0)
	local a, b, c, d, vehicle = GetRaycastResult(rayHandle)
	return vehicle
end

Thanks!
Daniel (Shooter)

Is there a way to use this script to add multiple trailers? So i can use my custom ones with this?

How do you attach the trailer to the truck?

can someone send me a link for the truck in the pic

the trailer dose not connect to the truck

I am having this issue also

Clearly the script is broke its not loading any cars at all.

Is the script broken for real. Not working for me either.

1 Like

it is not spawn in when i use the spawn code