-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.lua
75 lines (64 loc) · 2.33 KB
/
client.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
-- optimizations
local tonumber = tonumber
local CreateThread = Citizen.CreateThread
local Wait = Citizen.Wait
local TriggerEvent = TriggerEvent
local RegisterCommand = RegisterCommand
local PlayerPedId = PlayerPedId
local IsPedInAnyVehicle = IsPedInAnyVehicle
local GetPedInVehicleSeat = GetPedInVehicleSeat
local GetVehiclePedIsIn = GetVehiclePedIsIn
local SetPedIntoVehicle = SetPedIntoVehicle
-- end optimizations
local disabled = false
CreateThread(function()
while true do
local ped = PlayerPedId()
local restrictSwitching = false
if IsPedInAnyVehicle(ped, false) and not disabled then
if GetPedInVehicleSeat(GetVehiclePedIsIn(ped, false), 0) == ped then
restrictSwitching = true
end
end
SetPedConfigFlag(ped, 184, restrictSwitching)
Wait(150)
end
end)
local function switchSeat(_, args)
local seatIndex = tonumber(args[1]) - 1
if seatIndex < -1 or seatIndex >= 4 then
SetNotificationTextEntry('STRING')
AddTextComponentString("~r~Seat ~b~" .. (seatIndex + 1) .. "~r~ is not recognized")
DrawNotification(true, true)
else
local ped = PlayerPedId()
local veh = GetVehiclePedIsIn(ped, false)
if veh ~= nil and veh > 0 then
CreateThread(function()
disabled = true
SetPedIntoVehicle(PlayerPedId(), veh, seatIndex)
Wait(50)
disabled = false
end)
end
end
end
local function shuffleSeat()
CreateThread(function()
disabled = true
Wait(3000)
disabled = false
end)
end
RegisterCommand("seat", switchSeat)
RegisterCommand("shuff", shuffleSeat)
RegisterCommand("shuffle", shuffleSeat)
TriggerEvent('chat:addSuggestion', '/shuff', "Switch to the driver's seat")
TriggerEvent('chat:addSuggestion', '/shuffle', "Switch to the driver's seat")
TriggerEvent('chat:addSuggestion', '/seat', 'Switch seats in the current vehicle',
{ { name = 'seat', help = "Switch seats in the current vehicle. 0 = driver, 1 = passenger, 2-3 = back seats" } })
AddEventHandler('onClientResourceStop', function(name)
if name == 'seat-switcher' then
SetPedConfigFlag(PlayerPedId(), 184, false)
end
end)