Does anyone know how to modify the script

sorry, you don’t know how to remake the creaking under pressing, and not under command in the chat?

AddEventHandler('chatMessage', function(source, n, message)
    command = stringsplit(message, " ")

    if(command[1] == "/tow") then
		CancelEvent()
		TriggerClientEvent("pv:tow", source)
	end
end)

function stringsplit(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t={} ; i=1
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        t[i] = str
        i = i + 1
    end
    return t
end

In this example i use the INPUT_SELECT_CHARACTER_MICHAEL (F5).
If you want to change this, check this page.

Citizen.CreateThread(function()
	while true do
		Wait(0)
		if IsControlJustPressed(0, 166) then
			TriggerEvent("pv:tow")
		end
	end
end)

Error resuming coroutine: sv_tow.lua:4: attempt to call a nil value (global ‘IsControlJustPressed’)
stack traceback:
sv_tow.lua:4: in function <sv_tow.lua:1>

gives me this error

You need to add that to your client script, not sv_tow.lua

local currentlyTowedVehicle = nil
Citizen.CreateThread(function()
while true do
Wait(0)
if IsControlJustPressed(0, 166) then
TriggerEvent(“pv:tow”)
end
end
end)
RegisterNetEvent(‘pv:tow’)
AddEventHandler(‘pv:tow’, function()

local playerped = GetPlayerPed(-1)
local vehicle = GetVehiclePedIsIn(playerped, true)

local towmodel = GetHashKey('flatbed')
local isVehicleTow = IsVehicleModel(vehicle, towmodel)
		
if isVehicleTow then

	local coordA = GetEntityCoords(playerped, 1)
	local coordB = GetOffsetFromEntityInWorldCoords(playerped, 0.0, 5.0, 0.0)
	local targetVehicle = getVehicleInDirection(coordA, coordB)
	
	if currentlyTowedVehicle == nil then
		if targetVehicle ~= 0 then
			if not IsPedInAnyVehicle(playerped, true) then
				if vehicle ~= targetVehicle then
					AttachEntityToEntity(targetVehicle, vehicle, 20, -0.5, -5.0, 1.0, 0.0, 0.0, 0.0, false, false, false, false, 20, true)
					currentlyTowedVehicle = targetVehicle
					TriggerEvent("chatMessage", "[TOWFuckers]", {255, 255, 0}, "Vehicle successfully attached to towtruck!")
				else
					TriggerEvent("chatMessage", "[TOWFuckers]", {255, 255, 0}, "Are you retarded? You cant tow your own towtruck with your own towtruck?")
				end
			end
		else
			TriggerEvent("chatMessage", "[TOWFuckers]", {255, 255, 0}, "Theres no vehicle to tow?")
		end
	else
		AttachEntityToEntity(currentlyTowedVehicle, vehicle, 20, -0.5, -12.0, 1.0, 0.0, 0.0, 0.0, false, false, false, false, 20, true)
		DetachEntity(currentlyTowedVehicle, true, true)
		currentlyTowedVehicle = nil
		TriggerEvent("chatMessage", "[TOWFuckers]", {255, 255, 0}, "The vehicle has been successfully detached!")
	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

so it is necessary to note?

Yes you need to add it to that file, not sv_tow.lua

1 Like

thank you very much.You are super