33flatbed_script = gui .get_tab (" Flatbed Script" )
44attached_vehicle = {}
55local debug = false
6+ -- local validModel = false
7+ local modelOverride = false
68flatbed_script :add_imgui (function ()
79local vehicleHandles = entities .get_all_vehicles_as_handles ()
810local flatbedModel = 1353720154
911local current_vehicle = PED .GET_VEHICLE_PED_IS_USING (self .get_ped ())
1012local vehicle_model = ENTITY .GET_ENTITY_MODEL (current_vehicle )
11- local validModel = false
1213local playerPosition = ENTITY .GET_ENTITY_COORDS (self .get_ped (),false )
1314local playerForwardX = ENTITY .GET_ENTITY_FORWARD_X (self .get_ped ())
1415local playerForwardY = ENTITY .GET_ENTITY_FORWARD_Y (self .get_ped ())
15- -- for _, veh in ipairs(vehicleHandles) do
16- -- script.run_in_fiber(function()
17- -- vehicleHash = ENTITY.GET_ENTITY_MODEL(veh)
18- -- vehicleCoords = ENTITY.GET_ENTITY_COORDS(veh, false)
19- -- myPos = ENTITY.GET_ENTITY_COORDS(self.get_ped(), false)
20- -- local function vectorEquals(a, b)
21- -- return a.x <= (b.x + 2) and a.y <= (b.y + 2) and a.z <= (b.z + 2)
22- -- end
23- -- if vectorEquals(vehicleCoords, myPos) then
24- -- if ENTITY.IS_ENTITY_AT_COORD(veh, vehicleCoords.x,vehicleCoords.y, vehicleCoords.z, 5.0, 5.0, 5.0, false, true, 0) then
25- -- closestVehicle = veh
26- -- end
27- -- end
28- -- end)
29- -- end
30- local closestVehicle = VEHICLE .GET_CLOSEST_VEHICLE (playerPosition .x ,playerPosition .y ,playerPosition .z ,10.0 ,0 ,70 )-- doesn't return cop cars or occupied pvs.
16+ -- local closestVehicle = VEHICLE.GET_CLOSEST_VEHICLE(playerPosition.x, playerPosition.y, playerPosition.z, 10.0, 0, 70) --doesn't return cop cars or occupied pvs.
17+ for _ ,veh in ipairs (vehicleHandles )do
18+ script .run_in_fiber (function (script )
19+ local detectPos = vec3 :new (playerPosition .x - (playerForwardX * 10 ),playerPosition .y - (playerForwardY * 10 ),playerPosition .z )
20+ local vehPos = ENTITY .GET_ENTITY_COORDS (veh ,false )
21+ local vDist = SYSTEM .VDIST (detectPos .x ,detectPos .y ,detectPos .z ,vehPos .x ,vehPos .y ,vehPos .z )
22+ if vDist <= 5 then
23+ closestVehicle = veh
24+ else
25+ script :sleep (50 )
26+ closestVehicle = nil
27+ return
28+ end
29+ end )
30+ end
3131local closestVehicleModel = ENTITY .GET_ENTITY_MODEL (closestVehicle )
3232local is_car = VEHICLE .IS_THIS_MODEL_A_CAR (closestVehicleModel )
3333local is_bike = VEHICLE .IS_THIS_MODEL_A_BIKE (closestVehicleModel )
@@ -39,39 +39,52 @@ flatbed_script:add_imgui(function()
3939end
4040if closestVehicleName == " " then
4141displayText = " No nearby vehicles found!"
42+ elseif tostring (closestVehicleName )== " Flatbed" then
43+ displayText = " You can not tow another flatbed truck."
4244else
43- displayText = tostring (closestVehicleName )
45+ displayText = (" Closest Vehicle:" .. tostring (closestVehicleName ))
46+ end
47+ if attached_vehicle [1 ]~= nil then
48+ displayText = " Towing..."
49+ end
50+ if modelOverride then
51+ validModel = true
52+ else
53+ validModel = false
4454end
4555if is_car then
4656validModel = true
4757end
4858if is_bike then
4959validModel = true
5060end
51- if closestVehicleModel == 745926877 then
61+ if closestVehicleModel == 745926877 then -- Buzzard
5262validModel = true
5363end
54- if closestVehicleModel == flatbedModel then
55- validModel = false
56- end
5764if is_in_flatbed then
58- ImGui .Text (" Closest Vehicle:" .. displayText )
59- towPos ,used = ImGui .Checkbox (" Show Closest Vehicle" ,towPos ,true )
65+ ImGui .Text (displayText )
66+ towPos ,used = ImGui .Checkbox (" Show Towing Position" ,towPos ,true )
67+ towEverything ,used = ImGui .Checkbox (" Tow Everything" ,towEverything ,true )
68+ if towEverything then
69+ modelOverride = true
70+ else
71+ modelOverride = false
72+ end
6073if ImGui .Button (" Tow" )then
6174if attached_vehicle [1 ]== nil then
62- if validModel then
63- -- local controlled = entities.take_control_of(closestVehicle, 350)
64- -- if controlled then
75+ if validModel and closestVehicleModel ~= flatbedModel then
76+ local controlled = entities .take_control_of (closestVehicle ,350 )
77+ if controlled then
6578flatbedHeading = ENTITY .GET_ENTITY_HEADING (current_vehicle )
66- flatbedBone = ENTITY .GET_ENTITY_BONE_INDEX_BY_NAME (current_vehicle ," chassis " )
79+ flatbedBone = ENTITY .GET_ENTITY_BONE_INDEX_BY_NAME (current_vehicle ," chassis_dummy " )
6780ENTITY .SET_ENTITY_HEADING (closestVehicleModel ,flatbedHeading )
6881ENTITY .ATTACH_ENTITY_TO_ENTITY (closestVehicle ,current_vehicle ,flatbedBone ,0.0 ,- 2.0 ,1.069 ,0.0 ,0.0 ,0.0 ,false ,true ,true ,false ,1 ,true ,1 )
6982table.insert (attached_vehicle ,closestVehicle )
70- -- else
71- -- gui.show_error("Flatbed Script", "Failed to take control of the vehicle!")
72- -- end
83+ else
84+ gui .show_error (" Flatbed Script" ," Failed to take control of the vehicle!" )
85+ end
7386end
74- if closestVehicle ~= nil and closestVehicleModel ~= flatbedModel and not is_car and not is_bike then
87+ if closestVehicle ~= nil and closestVehicleModel ~= flatbedModel and not validModel then
7588gui .show_message (" Flatbed Script" ," You can only tow cars, trucks and bikes." )
7689end
7790if closestVehicle ~= nil and closestVehicleModel == flatbedModel then
@@ -82,22 +95,6 @@ flatbed_script:add_imgui(function()
8295end
8396end
8497ImGui .SameLine ()
85- -- if ImGui.Button("Tow Player Vehicle") then
86- -- script.run_in_fiber(function()
87- -- local selected_player = PLAYER.GET_PLAYER_PED(network.get_selected_player())
88- -- local towVeh = PED.GET_VEHICLE_PED_IS_USING(selected_player)
89- -- local towVehModel = ENTITY.GET_ENTITY_MODEL(towVeh)
90- -- local vehControlled = entities.take_control_of(towVeh, 350)
91- -- local playerControlled = entities.take_control_of(selected_player, 350)
92- -- if vehControlled and playerControlled then
93- -- local flatbedHeading = ENTITY.GET_ENTITY_HEADING(current_vehicle)
94- -- local flatbedBone = ENTITY.GET_ENTITY_BONE_INDEX_BY_NAME(current_vehicle, "chassis")
95- -- ENTITY.SET_ENTITY_HEADING(towVehModel, flatbedHeading)
96- -- ENTITY.ATTACH_ENTITY_TO_ENTITY(towVeh, current_vehicle, flatbedBone, 0.0, -2.0, 1.069, 0.0, 0.0, 0.0, false, true, true, false, 1, true, 1)
97- -- table.insert(attached_vehicle, towVeh)
98- -- end
99- -- end)
100- -- end
10198if ImGui .Button (" Detach" )then
10299for _ ,v in ipairs (vehicleHandles )do
103100script .run_in_fiber (function ()
@@ -137,8 +134,8 @@ flatbed_script:add_imgui(function()
137134try = try + 1
138135end
139136end
140- fltbd = VEHICLE .CREATE_VEHICLE (flatbedModel ,playerPosition .x + ( playerForwardX * 2 ) ,playerPosition .y + ( playerForwardX * 2 ) ,playerPosition .z ,ENTITY .GET_ENTITY_HEADING (self .get_ped ()),true ,false ,false )
141- script :sleep (200 )
137+ fltbd = VEHICLE .CREATE_VEHICLE (flatbedModel ,playerPosition .x ,playerPosition .y ,playerPosition .z ,ENTITY .GET_ENTITY_HEADING (self .get_ped ()),true ,false ,false )
138+ -- script:sleep(200)
142139PED .SET_PED_INTO_VEHICLE (self .get_ped (),fltbd ,- 1 )
143140ENTITY .SET_ENTITY_AS_NO_LONGER_NEEDED (fltbd )
144141end )
@@ -151,36 +148,53 @@ flatbed_script:add_imgui(function()
151148if debug then
152149ImGui .Separator ()
153150if ImGui .Button (" debug" )then
154- lastVeh = ENTITY .GET_ENTITY_MODEL (PLAYER .GET_PLAYERS_LAST_VEHICLE ())
155- local closestVehicle2 = VEHICLE .GET_CLOSEST_VEHICLE (playerPosition .x ,playerPosition .y ,playerPosition .z ,10.0 ,0 ,70 )
156- -- log.debug("Last Vehicle: "..tostring(lastVeh).." | Attached Vehicle: "..tostring(attached_vehicle[1]))
157- -- log.debug("My Coords: "..tostring(playerPosition).." | Vehicle Coords: "..tostring(vehicleCoords))
158- log .debug (tostring (closestVehicle ))
159- log .debug (tostring (closestVehicle2 ))
151+ for _ ,veh in ipairs (vehicleHandles )do
152+ script .run_in_fiber (function (script )
153+ local detectPos = vec3 :new (playerPosition .x - (playerForwardX * 10 ),playerPosition .y - (playerForwardY * 10 ),playerPosition .z )
154+ local vehPos = ENTITY .GET_ENTITY_COORDS (veh ,false )
155+ local vDist = SYSTEM .VDIST (detectPos .x ,detectPos .y ,detectPos .z ,vehPos .x ,vehPos .y ,vehPos .z )
156+ local vHash = ENTITY .GET_ENTITY_MODEL (veh )
157+ end )
158+ end
159+ -- log.debug(tostring(closestVehicle))
160+ log .debug (tostring (vDist ))
160161end
161162end
162163end )
163164script .register_looped (" flatbed script" ,function (script )
164- script :yield ()
165+ -- script:yield()
166+ local vehicleHandles = entities .get_all_vehicles_as_handles ()
165167local current_vehicle = PED .GET_VEHICLE_PED_IS_USING (self .get_ped ())
166168local vehicle_model = ENTITY .GET_ENTITY_MODEL (current_vehicle )
167169local flatbedHeading = ENTITY .GET_ENTITY_HEADING (current_vehicle )
168170local flatbedBone = ENTITY .GET_ENTITY_BONE_INDEX_BY_NAME (current_vehicle ," chassis" )
169171local playerPosition = ENTITY .GET_ENTITY_COORDS (self .get_ped (),false )
170- local closestVehicle = VEHICLE .GET_CLOSEST_VEHICLE (playerPosition .x ,playerPosition .y ,playerPosition .z ,10.0 ,0 ,70 )
171- local closestVehicleModel = ENTITY .GET_ENTITY_MODEL (closestVehicle )
172172local playerForwardX = ENTITY .GET_ENTITY_FORWARD_X (self .get_ped ())
173173local playerForwardY = ENTITY .GET_ENTITY_FORWARD_Y (self .get_ped ())
174+ for _ ,veh in ipairs (vehicleHandles )do
175+ local detectPos = vec3 :new (playerPosition .x - (playerForwardX * 10 ),playerPosition .y - (playerForwardY * 10 ),playerPosition .z )
176+ local vehPos = ENTITY .GET_ENTITY_COORDS (veh ,false )
177+ local vDist = SYSTEM .VDIST (detectPos .x ,detectPos .y ,detectPos .z ,vehPos .x ,vehPos .y ,vehPos .z )
178+ if vDist <= 5 then
179+ closestVehicle = veh
180+ end
181+ end
182+ local closestVehicleModel = ENTITY .GET_ENTITY_MODEL (closestVehicle )
174183local is_car = VEHICLE .IS_THIS_MODEL_A_CAR (closestVehicleModel )
175184local is_bike = VEHICLE .IS_THIS_MODEL_A_BIKE (closestVehicleModel )
176185local validModel = false
186+ if modelOverride then
187+ validModel = true
188+ else
189+ validModel = false
190+ end
177191if is_car then
178192validModel = true
179193end
180194if is_bike then
181195validModel = true
182196end
183- if closestVehicleModel == 745926877 then
197+ if closestVehicleModel == 745926877 then -- Buzzard
184198validModel = true
185199end
186200if closestVehicleModel == 1353720154 then
@@ -192,25 +206,26 @@ script.register_looped("flatbed script", function(script)
192206is_in_flatbed = false
193207end
194208if is_in_flatbed and attached_vehicle [1 ]== nil then
195- if PAD .IS_CONTROL_PRESSED (0 ,73 )then
196- if validModel then
209+ if PAD .IS_CONTROL_PRESSED (0 ,73 )and validModel and closestVehicleModel ~= flatbedModel then
210+ script :sleep (200 )
211+ local controlled = entities .take_control_of (closestVehicle ,350 )
212+ if controlled then
213+ ENTITY .SET_ENTITY_HEADING (closestVehicleModel ,flatbedHeading )
214+ ENTITY .ATTACH_ENTITY_TO_ENTITY (closestVehicle ,current_vehicle ,flatbedBone ,0.0 ,- 2.0 ,1.069 ,0.0 ,0.0 ,0.0 ,false ,true ,true ,false ,1 ,true ,1 )
215+ table.insert (attached_vehicle ,closestVehicle )
197216script :sleep (200 )
198- -- local controlled = entities.take_control_of(closestVehicle, 350)
199- -- if controlled then
200- ENTITY .SET_ENTITY_HEADING (closestVehicleModel ,flatbedHeading )
201- ENTITY .ATTACH_ENTITY_TO_ENTITY (closestVehicle ,current_vehicle ,flatbedBone ,0.0 ,- 2.0 ,1.069 ,0.0 ,0.0 ,0.0 ,false ,true ,true ,false ,1 ,true ,1 )
202- table.insert (attached_vehicle ,closestVehicle )
203- script :sleep (200 )
204- -- else
205- -- gui.show_error("Flatbed Script", "Failed to take control of the vehicle!")
206- -- end
207217else
208- if closestVehicle ~= nil then
209- script :sleep (400 )
210- gui .show_message (" Flatbed Script" ," You can only tow cars, trucks and bikes." )
211- end
218+ gui .show_error (" Flatbed Script" ," Failed to take control of the vehicle!" )
212219end
213220end
221+ if PAD .IS_CONTROL_PRESSED (0 ,73 )and closestVehicle ~= nil and not validModel then
222+ gui .show_message (" Flatbed Script" ," You can only tow cars, trucks and bikes." )
223+ script :sleep (400 )
224+ end
225+ if PAD .IS_CONTROL_PRESSED (0 ,73 )and closestVehicleModel == flatbedModel then
226+ script :sleep (400 )
227+ gui .show_message (" Flatbed Script" ," Sorry but you can not tow another flatbed truck." )
228+ end
214229elseif is_in_flatbed and attached_vehicle [1 ]~= nil then
215230if PAD .IS_CONTROL_PRESSED (0 ,73 )then
216231script :sleep (200 )
@@ -220,7 +235,7 @@ script.register_looped("flatbed script", function(script)
220235local attachedVehicle = ENTITY .GET_ENTITY_OF_TYPE_ATTACHED_TO_ENTITY (current_vehicle ,modelHash )
221236if ENTITY .DOES_ENTITY_EXIST (attachedVehicle )then
222237ENTITY .DETACH_ENTITY (attachedVehicle )
223- ENTITY .SET_ENTITY_COORDS (attachedVehicle ,playerPosition .x - (playerForwardX * 10 ),playerPosition .y - (playerForwardY * 10 ),playerPosition .z ,false , false , false , false )
238+ ENTITY .SET_ENTITY_COORDS (attachedVehicle ,playerPosition .x - (playerForwardX * 10 ),playerPosition .y - (playerForwardY * 10 ),playerPosition .z ,0 , 0 , 0 , 0 )
224239VEHICLE .SET_VEHICLE_ON_GROUND_PROPERLY (attached_vehicle ,5.0 )
225240end
226241end
@@ -229,22 +244,23 @@ script.register_looped("flatbed script", function(script)
229244local attachedVehicle = ENTITY .GET_ENTITY_OF_TYPE_ATTACHED_TO_ENTITY (PED .GET_VEHICLE_PED_IS_USING (self .get_ped ()),modelHash )
230245if ENTITY .DOES_ENTITY_EXIST (attachedVehicle )then
231246ENTITY .DETACH_ENTITY (attachedVehicle )
232- ENTITY .SET_ENTITY_COORDS (attachedVehicle ,playerPosition .x - (playerForwardX * 10 ),playerPosition .y - (playerForwardY * 10 ),playerPosition .z ,false , false , false , false )
247+ ENTITY .SET_ENTITY_COORDS (attachedVehicle ,playerPosition .x - (playerForwardX * 10 ),playerPosition .y - (playerForwardY * 10 ),playerPosition .z ,0 , 0 , 0 , 0 )
233248VEHICLE .SET_VEHICLE_ON_GROUND_PROPERLY (attached_vehicle ,5.0 )
234249end
235250table.remove (attached_vehicle ,key )
236251end
237252script :sleep (200 )
238253end
239254end
255+ end )
256+ script .register_looped (" TowPos Marker" ,function ()
240257if towPos then
241258if is_in_flatbed and attached_vehicle [1 ]== nil then
242259local playerPosition = ENTITY .GET_ENTITY_COORDS (self .get_ped (),false )
243- local closestVehicle = VEHICLE .GET_CLOSEST_VEHICLE (playerPosition .x ,playerPosition .y ,playerPosition .z ,10.0 ,0 ,70 )
244- local closestVehicleCoords = ENTITY .GET_ENTITY_COORDS (closestVehicle ,false )
245- -- GRAPHICS.DRAW_BOX(closestVehicleCoords.x, closestVehicleCoords.x, closestVehicleCoords.x, closestVehicleCoords.x + 1, closestVehicleCoords.y + 1, closestVehicleCoords.z + 2, 255, 128, 0, 50)
246- -- GRAPHICS.DRAW_MARKER(6,closestVehicleCoords.x, closestVehicleCoords.y, closestVehicleCoords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1, 1, 1, 255, 128, 0, 50, true, true, 2, false, "mpmissmarkers128", "corona_marker", false)
247- GRAPHICS .DRAW_MARKER_SPHERE (closestVehicleCoords .x ,closestVehicleCoords .y ,closestVehicleCoords .z ,2.5 ,180 ,128 ,0 ,0.115 )
260+ local playerForwardX = ENTITY .GET_ENTITY_FORWARD_X (self .get_ped ())
261+ local playerForwardY = ENTITY .GET_ENTITY_FORWARD_Y (self .get_ped ())
262+ local detectPos = vec3 :new (playerPosition .x - (playerForwardX * 10 ),playerPosition .y - (playerForwardY * 10 ),playerPosition .z )
263+ GRAPHICS .DRAW_MARKER_SPHERE (detectPos .x ,detectPos .y ,detectPos .z ,2.5 ,180 ,128 ,0 ,0.115 )
248264end
249265end
250266end )