@@ -3,16 +3,18 @@ local vehicles = {}; RPWorking = true
3
3
Citizen .CreateThread (function ()
4
4
while true do
5
5
Citizen .Wait (0 )
6
- if Config .UseKey and Config .ToggleKey then
6
+ if Config .UseKey and Config .ToggleKey and IsPedInAnyVehicle ( PlayerPedId ()) and ( GetVehiclePedIsIn ( PlayerPedId () == PlayerPedId ())) then
7
7
if IsControlJustReleased (1 , Config .ToggleKey ) then
8
8
TriggerEvent (' EngineToggle:Engine' )
9
9
end
10
10
end
11
+
11
12
if GetSeatPedIsTryingToEnter (PlayerPedId ()) == - 1 and not table .contains (vehicles , GetVehiclePedIsTryingToEnter (PlayerPedId ())) then
12
13
table.insert (vehicles , {GetVehiclePedIsTryingToEnter (PlayerPedId ()), IsVehicleEngineOn (GetVehiclePedIsTryingToEnter (PlayerPedId ()))})
13
14
elseif IsPedInAnyVehicle (PlayerPedId (), false ) and not table .contains (vehicles , GetVehiclePedIsIn (PlayerPedId (), false )) then
14
15
table.insert (vehicles , {GetVehiclePedIsIn (PlayerPedId (), false ), IsVehicleEngineOn (GetVehiclePedIsIn (PlayerPedId (), false ))})
15
16
end
17
+
16
18
for i , vehicle in ipairs (vehicles ) do
17
19
if DoesEntityExist (vehicle [1 ]) then
18
20
if (GetPedInVehicleSeat (vehicle [1 ], - 1 ) == PlayerPedId ()) or IsVehicleSeatFree (vehicle [1 ], - 1 ) then
@@ -39,15 +41,18 @@ RegisterNetEvent('EngineToggle:Engine')
39
41
AddEventHandler (' EngineToggle:Engine' , function ()
40
42
local veh
41
43
local StateIndex
44
+
42
45
for i , vehicle in ipairs (vehicles ) do
43
46
if vehicle [1 ] == GetVehiclePedIsIn (PlayerPedId (), false ) then
44
47
veh = vehicle [1 ]
45
48
StateIndex = i
46
49
end
47
50
end
48
51
Citizen .Wait (0 )
52
+
49
53
if Config .VehicleKeyChain then
50
54
local isVehicleOrKeyOwner = exports [" VehicleKeyChain" ]:IsVehicleOrKeyOwner (veh )
55
+
51
56
if IsPedInAnyVehicle (PlayerPedId (), false ) and isVehicleOrKeyOwner then
52
57
if (GetPedInVehicleSeat (veh , - 1 ) == PlayerPedId ()) then
53
58
vehicles [StateIndex ][2 ] = not GetIsVehicleEngineRunning (veh )
@@ -78,27 +83,29 @@ AddEventHandler('EngineToggle:Engine', function()
78
83
TriggerEvent (' esx:showNotification' , _U (' key_nokey' ))
79
84
end
80
85
end
81
- elseif IsPedInAnyVehicle (PlayerPedId (), false ) then
82
- if (GetPedInVehicleSeat (veh , - 1 ) == PlayerPedId ()) then
83
- vehicles [StateIndex ][2 ] = not GetIsVehicleEngineRunning (veh )
84
- if vehicles [StateIndex ][2 ] then
85
- if Config .Notifications then
86
- TriggerEvent (' notifications' , " #00EE00" , _U (' notification_header' ), _U (' n_engine_start' ))
87
- elseif Config .OkokNotify then
88
- exports [' okokNotify' ]:Alert (_U (' notification_header' ), _U (' okok_engine_start' ), 5000 , ' info' )
89
- else
90
- TriggerEvent (' esx:showNotification' , _U (' engine_start' ))
91
- end
92
- else
93
- if Config .Notifications then
94
- TriggerEvent (' notifications' , " #FF0000" , _U (' notification_header' ), _U (' n_engine_stop' ))
95
- elseif Config .OkokNotify then
96
- exports [' okokNotify' ]:Alert (_U (' notification_header' ), _U (' okok_engine_stop' ), 5000 , ' info' )
86
+ else
87
+ if IsPedInAnyVehicle (PlayerPedId (), false ) then
88
+ if (GetPedInVehicleSeat (veh , - 1 ) == PlayerPedId ()) then
89
+ vehicles [StateIndex ][2 ] = not GetIsVehicleEngineRunning (veh )
90
+ if vehicles [StateIndex ][2 ] then
91
+ if Config .Notifications then
92
+ TriggerEvent (' notifications' , " #00EE00" , _U (' notification_header' ), _U (' n_engine_start' ))
93
+ elseif Config .OkokNotify then
94
+ exports [' okokNotify' ]:Alert (_U (' notification_header' ), _U (' okok_engine_start' ), 5000 , ' info' )
95
+ else
96
+ TriggerEvent (' esx:showNotification' , _U (' engine_start' ))
97
+ end
97
98
else
98
- TriggerEvent (' esx:showNotification' , _U (' engine_stop' ))
99
+ if Config .Notifications then
100
+ TriggerEvent (' notifications' , " #FF0000" , _U (' notification_header' ), _U (' n_engine_stop' ))
101
+ elseif Config .OkokNotify then
102
+ exports [' okokNotify' ]:Alert (_U (' notification_header' ), _U (' okok_engine_stop' ), 5000 , ' info' )
103
+ else
104
+ TriggerEvent (' esx:showNotification' , _U (' engine_stop' ))
105
+ end
99
106
end
100
107
end
101
- end
108
+ end
102
109
end
103
110
end )
104
111
@@ -131,10 +138,10 @@ if Config.OnAtEnter then
131
138
end
132
139
133
140
function table .contains (table , element )
134
- for _ , value in pairs (table ) do
135
- if value [1 ] == element then
136
- return true
137
- end
138
- end
139
- return false
141
+ for _ , value in pairs (table ) do
142
+ if value [1 ] == element then
143
+ return true
144
+ end
145
+ end
146
+ return false
140
147
end
0 commit comments