@@ -3,16 +3,18 @@ local vehicles = {}; RPWorking = true
33Citizen .CreateThread (function ()
44 while true do
55 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
77 if IsControlJustReleased (1 , Config .ToggleKey ) then
88 TriggerEvent (' EngineToggle:Engine' )
99 end
1010 end
11+
1112 if GetSeatPedIsTryingToEnter (PlayerPedId ()) == - 1 and not table .contains (vehicles , GetVehiclePedIsTryingToEnter (PlayerPedId ())) then
1213 table.insert (vehicles , {GetVehiclePedIsTryingToEnter (PlayerPedId ()), IsVehicleEngineOn (GetVehiclePedIsTryingToEnter (PlayerPedId ()))})
1314 elseif IsPedInAnyVehicle (PlayerPedId (), false ) and not table .contains (vehicles , GetVehiclePedIsIn (PlayerPedId (), false )) then
1415 table.insert (vehicles , {GetVehiclePedIsIn (PlayerPedId (), false ), IsVehicleEngineOn (GetVehiclePedIsIn (PlayerPedId (), false ))})
1516 end
17+
1618 for i , vehicle in ipairs (vehicles ) do
1719 if DoesEntityExist (vehicle [1 ]) then
1820 if (GetPedInVehicleSeat (vehicle [1 ], - 1 ) == PlayerPedId ()) or IsVehicleSeatFree (vehicle [1 ], - 1 ) then
@@ -39,15 +41,18 @@ RegisterNetEvent('EngineToggle:Engine')
3941AddEventHandler (' EngineToggle:Engine' , function ()
4042 local veh
4143 local StateIndex
44+
4245 for i , vehicle in ipairs (vehicles ) do
4346 if vehicle [1 ] == GetVehiclePedIsIn (PlayerPedId (), false ) then
4447 veh = vehicle [1 ]
4548 StateIndex = i
4649 end
4750 end
4851 Citizen .Wait (0 )
52+
4953 if Config .VehicleKeyChain then
5054 local isVehicleOrKeyOwner = exports [" VehicleKeyChain" ]:IsVehicleOrKeyOwner (veh )
55+
5156 if IsPedInAnyVehicle (PlayerPedId (), false ) and isVehicleOrKeyOwner then
5257 if (GetPedInVehicleSeat (veh , - 1 ) == PlayerPedId ()) then
5358 vehicles [StateIndex ][2 ] = not GetIsVehicleEngineRunning (veh )
@@ -78,27 +83,29 @@ AddEventHandler('EngineToggle:Engine', function()
7883 TriggerEvent (' esx:showNotification' , _U (' key_nokey' ))
7984 end
8085 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
9798 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
99106 end
100107 end
101- end
108+ end
102109 end
103110end )
104111
@@ -131,10 +138,10 @@ if Config.OnAtEnter then
131138end
132139
133140function 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
140147end
0 commit comments