Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita5e320e

Browse files
committed
Update flatbed_script.lua
1 parent81e51de commita5e320e

File tree

1 file changed

+98
-82
lines changed

1 file changed

+98
-82
lines changed

‎flatbed_script.lua‎

Lines changed: 98 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@
33
flatbed_script=gui.get_tab("Flatbed Script")
44
attached_vehicle= {}
55
localdebug=false
6+
-- local validModel = false
7+
localmodelOverride=false
68
flatbed_script:add_imgui(function()
79
localvehicleHandles=entities.get_all_vehicles_as_handles()
810
localflatbedModel=1353720154
911
localcurrent_vehicle=PED.GET_VEHICLE_PED_IS_USING(self.get_ped())
1012
localvehicle_model=ENTITY.GET_ENTITY_MODEL(current_vehicle)
11-
localvalidModel=false
1213
localplayerPosition=ENTITY.GET_ENTITY_COORDS(self.get_ped(),false)
1314
localplayerForwardX=ENTITY.GET_ENTITY_FORWARD_X(self.get_ped())
1415
localplayerForwardY=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-
localclosestVehicle=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_,vehinipairs(vehicleHandles)do
18+
script.run_in_fiber(function(script)
19+
localdetectPos=vec3:new(playerPosition.x- (playerForwardX*10),playerPosition.y- (playerForwardY*10),playerPosition.z)
20+
localvehPos=ENTITY.GET_ENTITY_COORDS(veh,false)
21+
localvDist=SYSTEM.VDIST(detectPos.x,detectPos.y,detectPos.z,vehPos.x,vehPos.y,vehPos.z)
22+
ifvDist<=5then
23+
closestVehicle=veh
24+
else
25+
script:sleep(50)
26+
closestVehicle=nil
27+
return
28+
end
29+
end)
30+
end
3131
localclosestVehicleModel=ENTITY.GET_ENTITY_MODEL(closestVehicle)
3232
localis_car=VEHICLE.IS_THIS_MODEL_A_CAR(closestVehicleModel)
3333
localis_bike=VEHICLE.IS_THIS_MODEL_A_BIKE(closestVehicleModel)
@@ -39,39 +39,52 @@ flatbed_script:add_imgui(function()
3939
end
4040
ifclosestVehicleName==""then
4141
displayText="No nearby vehicles found!"
42+
elseiftostring(closestVehicleName)=="Flatbed"then
43+
displayText="You can not tow another flatbed truck."
4244
else
43-
displayText=tostring(closestVehicleName)
45+
displayText= ("Closest Vehicle:"..tostring(closestVehicleName))
46+
end
47+
ifattached_vehicle[1]~=nilthen
48+
displayText="Towing..."
49+
end
50+
ifmodelOverridethen
51+
validModel=true
52+
else
53+
validModel=false
4454
end
4555
ifis_carthen
4656
validModel=true
4757
end
4858
ifis_bikethen
4959
validModel=true
5060
end
51-
ifclosestVehicleModel==745926877then
61+
ifclosestVehicleModel==745926877then--Buzzard
5262
validModel=true
5363
end
54-
ifclosestVehicleModel==flatbedModelthen
55-
validModel=false
56-
end
5764
ifis_in_flatbedthen
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+
iftowEverythingthen
69+
modelOverride=true
70+
else
71+
modelOverride=false
72+
end
6073
ifImGui.Button(" Tow")then
6174
ifattached_vehicle[1]==nilthen
62-
ifvalidModelthen
63-
--local controlled = entities.take_control_of(closestVehicle, 350)
64-
--if controlled then
75+
ifvalidModelandclosestVehicleModel~=flatbedModelthen
76+
localcontrolled=entities.take_control_of(closestVehicle,350)
77+
ifcontrolledthen
6578
flatbedHeading=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")
6780
ENTITY.SET_ENTITY_HEADING(closestVehicleModel,flatbedHeading)
6881
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)
6982
table.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
7386
end
74-
ifclosestVehicle~=nilandclosestVehicleModel~=flatbedModelandnotis_carandnotis_bikethen
87+
ifclosestVehicle~=nilandclosestVehicleModel~=flatbedModelandnotvalidModelthen
7588
gui.show_message("Flatbed Script","You can only tow cars, trucks and bikes.")
7689
end
7790
ifclosestVehicle~=nilandclosestVehicleModel==flatbedModelthen
@@ -82,22 +95,6 @@ flatbed_script:add_imgui(function()
8295
end
8396
end
8497
ImGui.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
10198
ifImGui.Button(" Detach")then
10299
for_,vinipairs(vehicleHandles)do
103100
script.run_in_fiber(function()
@@ -137,8 +134,8 @@ flatbed_script:add_imgui(function()
137134
try=try+1
138135
end
139136
end
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)
142139
PED.SET_PED_INTO_VEHICLE(self.get_ped(),fltbd,-1)
143140
ENTITY.SET_ENTITY_AS_NO_LONGER_NEEDED(fltbd)
144141
end)
@@ -151,36 +148,53 @@ flatbed_script:add_imgui(function()
151148
ifdebugthen
152149
ImGui.Separator()
153150
ifImGui.Button("debug")then
154-
lastVeh=ENTITY.GET_ENTITY_MODEL(PLAYER.GET_PLAYERS_LAST_VEHICLE())
155-
localclosestVehicle2=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_,vehinipairs(vehicleHandles)do
152+
script.run_in_fiber(function(script)
153+
localdetectPos=vec3:new(playerPosition.x- (playerForwardX*10),playerPosition.y- (playerForwardY*10),playerPosition.z)
154+
localvehPos=ENTITY.GET_ENTITY_COORDS(veh,false)
155+
localvDist=SYSTEM.VDIST(detectPos.x,detectPos.y,detectPos.z,vehPos.x,vehPos.y,vehPos.z)
156+
localvHash=ENTITY.GET_ENTITY_MODEL(veh)
157+
end)
158+
end
159+
-- log.debug(tostring(closestVehicle))
160+
log.debug(tostring(vDist))
160161
end
161162
end
162163
end)
163164
script.register_looped("flatbed script",function(script)
164-
script:yield()
165+
-- script:yield()
166+
localvehicleHandles=entities.get_all_vehicles_as_handles()
165167
localcurrent_vehicle=PED.GET_VEHICLE_PED_IS_USING(self.get_ped())
166168
localvehicle_model=ENTITY.GET_ENTITY_MODEL(current_vehicle)
167169
localflatbedHeading=ENTITY.GET_ENTITY_HEADING(current_vehicle)
168170
localflatbedBone=ENTITY.GET_ENTITY_BONE_INDEX_BY_NAME(current_vehicle,"chassis")
169171
localplayerPosition=ENTITY.GET_ENTITY_COORDS(self.get_ped(),false)
170-
localclosestVehicle=VEHICLE.GET_CLOSEST_VEHICLE(playerPosition.x,playerPosition.y,playerPosition.z,10.0,0,70)
171-
localclosestVehicleModel=ENTITY.GET_ENTITY_MODEL(closestVehicle)
172172
localplayerForwardX=ENTITY.GET_ENTITY_FORWARD_X(self.get_ped())
173173
localplayerForwardY=ENTITY.GET_ENTITY_FORWARD_Y(self.get_ped())
174+
for_,vehinipairs(vehicleHandles)do
175+
localdetectPos=vec3:new(playerPosition.x- (playerForwardX*10),playerPosition.y- (playerForwardY*10),playerPosition.z)
176+
localvehPos=ENTITY.GET_ENTITY_COORDS(veh,false)
177+
localvDist=SYSTEM.VDIST(detectPos.x,detectPos.y,detectPos.z,vehPos.x,vehPos.y,vehPos.z)
178+
ifvDist<=5then
179+
closestVehicle=veh
180+
end
181+
end
182+
localclosestVehicleModel=ENTITY.GET_ENTITY_MODEL(closestVehicle)
174183
localis_car=VEHICLE.IS_THIS_MODEL_A_CAR(closestVehicleModel)
175184
localis_bike=VEHICLE.IS_THIS_MODEL_A_BIKE(closestVehicleModel)
176185
localvalidModel=false
186+
ifmodelOverridethen
187+
validModel=true
188+
else
189+
validModel=false
190+
end
177191
ifis_carthen
178192
validModel=true
179193
end
180194
ifis_bikethen
181195
validModel=true
182196
end
183-
ifclosestVehicleModel==745926877then
197+
ifclosestVehicleModel==745926877then--Buzzard
184198
validModel=true
185199
end
186200
ifclosestVehicleModel==1353720154then
@@ -192,25 +206,26 @@ script.register_looped("flatbed script", function(script)
192206
is_in_flatbed=false
193207
end
194208
ifis_in_flatbedandattached_vehicle[1]==nilthen
195-
ifPAD.IS_CONTROL_PRESSED(0,73)then
196-
ifvalidModelthen
209+
ifPAD.IS_CONTROL_PRESSED(0,73)andvalidModelandclosestVehicleModel~=flatbedModelthen
210+
script:sleep(200)
211+
localcontrolled=entities.take_control_of(closestVehicle,350)
212+
ifcontrolledthen
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)
197216
script: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
207217
else
208-
ifclosestVehicle~=nilthen
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!")
212219
end
213220
end
221+
ifPAD.IS_CONTROL_PRESSED(0,73)andclosestVehicle~=nilandnotvalidModelthen
222+
gui.show_message("Flatbed Script","You can only tow cars, trucks and bikes.")
223+
script:sleep(400)
224+
end
225+
ifPAD.IS_CONTROL_PRESSED(0,73)andclosestVehicleModel==flatbedModelthen
226+
script:sleep(400)
227+
gui.show_message("Flatbed Script","Sorry but you can not tow another flatbed truck.")
228+
end
214229
elseifis_in_flatbedandattached_vehicle[1]~=nilthen
215230
ifPAD.IS_CONTROL_PRESSED(0,73)then
216231
script:sleep(200)
@@ -220,7 +235,7 @@ script.register_looped("flatbed script", function(script)
220235
localattachedVehicle=ENTITY.GET_ENTITY_OF_TYPE_ATTACHED_TO_ENTITY(current_vehicle,modelHash)
221236
ifENTITY.DOES_ENTITY_EXIST(attachedVehicle)then
222237
ENTITY.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)
224239
VEHICLE.SET_VEHICLE_ON_GROUND_PROPERLY(attached_vehicle,5.0)
225240
end
226241
end
@@ -229,22 +244,23 @@ script.register_looped("flatbed script", function(script)
229244
localattachedVehicle=ENTITY.GET_ENTITY_OF_TYPE_ATTACHED_TO_ENTITY(PED.GET_VEHICLE_PED_IS_USING(self.get_ped()),modelHash)
230245
ifENTITY.DOES_ENTITY_EXIST(attachedVehicle)then
231246
ENTITY.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)
233248
VEHICLE.SET_VEHICLE_ON_GROUND_PROPERLY(attached_vehicle,5.0)
234249
end
235250
table.remove(attached_vehicle,key)
236251
end
237252
script:sleep(200)
238253
end
239254
end
255+
end)
256+
script.register_looped("TowPos Marker",function()
240257
iftowPosthen
241258
ifis_in_flatbedandattached_vehicle[1]==nilthen
242259
localplayerPosition=ENTITY.GET_ENTITY_COORDS(self.get_ped(),false)
243-
localclosestVehicle=VEHICLE.GET_CLOSEST_VEHICLE(playerPosition.x,playerPosition.y,playerPosition.z,10.0,0,70)
244-
localclosestVehicleCoords=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+
localplayerForwardX=ENTITY.GET_ENTITY_FORWARD_X(self.get_ped())
261+
localplayerForwardY=ENTITY.GET_ENTITY_FORWARD_Y(self.get_ped())
262+
localdetectPos=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)
248264
end
249265
end
250266
end)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp