-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathClient.lua
More file actions
123 lines (102 loc) · 3.67 KB
/
Client.lua
File metadata and controls
123 lines (102 loc) · 3.67 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
local QBCore = exports['qb-core']:GetCoreObject()
local interactions = {}
-- opens the ui
RegisterNetEvent('nyx-elevator:showmenu', function(playerId)
SendNUIMessage({action = 'showlift'})
SetNuiFocus(true, true)
end)
-- hides the ui
RegisterNetEvent('nyx-elevator:hidemenu', function(playerId)
SendNUIMessage({action = 'hidelift'})
SetNuiFocus(false, false)
end)
-- handles changing floors
local function UseElevator(data)
local ped = PlayerPedId()
QBCore.Functions.Progressbar("Call_Lift", Config.Locals[Config.UseLanguage].Waiting, Config.WaitTime, false, false, {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
animDict = "anim@apt_trans@elevator",
anim = "elev_1",
flags = 16,
}, {}, {}, function() -- Done
StopAnimTask(ped, "anim@apt_trans@elevator", "elev_1", 1.0)
DoScreenFadeOut(500)
Wait(1000)
if Config.UseSoundEffect then
TriggerServerEvent("InteractSound_SV:PlayOnSource", Config.Elevators[data.lift].Sound, 0.05)
end
SetEntityCoords(ped, data.floor.Coords.x, data.floor.Coords.y, data.floor.Coords.z, 0, 0, 0, false)
SetEntityHeading(ped, data.floor.Coords.w)
Wait(1000)
DoScreenFadeIn(600)
end)
end
function AddInteraction(index, coords)
interactions[index] = {
id = 'elevator'..index,
name = 'elevator',
coords = coords,
distance = 5.0,
interactDst = 2.5,
options = {
{
label = 'Elevator',
action = function(entity, coords, args)
TriggerEvent('nyx-elevator:showmenu')
end,
},
}
}
exports.interact:AddInteraction(interactions[index])
end
-- creats eye targets from config
CreateThread(function()
for k, v in pairs(Config.Elevator) do
for _, location in ipairs(v.locations) do
AddInteraction(v.name, location)
end
end
end)
function NearestElevator()
local player = PlayerPedId()
local playerCoords = GetEntityCoords(player)
local nearestElevator = nil
local nearestDistance = math.huge
for _, elevator in pairs(Config.Elevator) do
for _, location in ipairs(elevator.locations) do
local distance = Vdist(playerCoords, location)
if distance < nearestDistance then
nearestElevator = elevator
nearestDistance = distance
end
end
end
return nearestElevator, nearestDistance
end
RegisterNUICallback('selectfloor', function(data, cb)
local floorNumber = tonumber(data.number)
-- Get the nearest elevator and its floors
local nearestElevator, nearestDistance = NearestElevator()
if nearestElevator then
local selectedFloor = nearestElevator.Floors[floorNumber]
if selectedFloor then
-- Call the UseElevator function with the elevator and floor data
UseElevator({ lift = nearestElevator, floor = selectedFloor })
cb({ success = true, message = "Floor selected successfully" })
TriggerEvent("nyx-elevator:hidemenu")
else
cb({ success = false, message = "Invalid floor selection" })
TriggerEvent("nyx-elevator:hidemenu")
end
else
cb({ success = false, message = "No elevator found" })
end
end)
RegisterNUICallback('escape', function(_, cb)
TriggerEvent("nyx-elevator:hidemenu")
cb("ok")
end)