-
Notifications
You must be signed in to change notification settings - Fork 7
/
client.lua
151 lines (124 loc) · 3.85 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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
-- globals
local hudForceHide = false
local hudPresence
local activated = false
----------------------------------------------------------
-------------------- Commands
----------------------------------------------------------
-- HUD
RegisterCommand('axonhide', function()
hudForceHide = true
ShowNotification("~y~Axon Body 3~s~ overlay now ~r~hidden~s~.")
end)
RegisterCommand('axonshow', function()
hudForceHide = false
ShowNotification("~y~Axon Body 3~s~ overlay now ~g~visible~s~.")
end)
-- Activation and deactivation
if Config.CommandBinding then
RegisterKeyMapping('axon', 'Toggle Axon Body 3', 'keyboard', Config.CommandBinding)
end
RegisterCommand('axon', function ()
if activated then
DeactivateAB3()
ShowNotification("~y~Axon Body 3~s~ has ~r~stopped recording~s~.")
else
if not Config:CommandAccessHandling() then
ShowNotification("You have to be ~r~on duty~s~ to enable ~y~Axon Body 3~s~.")
else
ActivateAB3()
ShowNotification("~y~Axon Body 3~s~ has ~g~started recording~s~.")
end
end
end)
RegisterCommand('axonon', function ()
if not Config:CommandAccessHandling() then
ShowNotification("You have to be ~r~on duty~s~ to use ~y~Axon Body 3~s~.")
else
if activated then
ShowNotification("~y~Axon Body 3~s~ is already ~g~recording~s~.")
else
ActivateAB3()
ShowNotification("~y~Axon Body 3~s~ has ~g~started recording~s~.")
end
end
end)
RegisterCommand('axonoff', function ()
if not activated then
ShowNotification("~y~Axon Body 3~s~ has already ~r~stopped recording~s~.")
else
DeactivateAB3()
ShowNotification("~y~Axon Body 3~s~ has ~r~stopped recording~s~.")
end
end)
----------------------------------------------------------
----------------------------------------------------------
----------------------------------------------------------
-- Events
RegisterNetEvent("AB3:SetState", function(state)
if state == true then
ActivateAB3()
elseif state == false then
DeactivateAB3()
end
end)
RegisterNetEvent("AB3:ServerBeep", function(netId)
local otherPed = GetPlayerPed(GetPlayerFromServerId(netId))
local ped = PlayerPedId()
if DoesEntityExist(ped) and (IsPedInAnyVehicle(ped) == IsPedInAnyVehicle(otherPed)) or not IsPedInAnyVehicle(ped) then
local volume = 0.05
local radius = 10
local playerCoords = GetEntityCoords(ped)
local targetCoords = GetEntityCoords(otherPed)
local distance = Vdist(playerCoords.x, playerCoords.y, playerCoords.z, targetCoords.x, targetCoords.y, targetCoords.z)
local distanceVolumeMultiplier = volume / radius
local distanceVolume = volume - (distance * distanceVolumeMultiplier)
if (distance <= radius) then
SendNUIMessage({ AxonBeep = { volume = distanceVolume } })
end
end
end)
-- Utils
function ActivateAB3()
if activated then
return error("AB3 attempted to activate when already active.")
end
activated = true
-- beeper
Citizen.CreateThread(function()
Citizen.Wait(12e4)
while activated do
TriggerServerEvent("AB3:ClientBeep")
Citizen.Wait(12e4)
end
end)
-- HUD
Citizen.CreateThread(function()
while activated do
Citizen.Wait(0)
if (GetFollowPedCamViewMode() == 4 or Config.ThirdPersonMode) and not hudForceHide then
if not hudPresence then
SetHudPresence(true)
end
elseif hudPresence then
SetHudPresence(false)
end
end
SetHudPresence(false)
end)
end
function DeactivateAB3()
if not activated then
return error("AB3 attempted to deactivate when already deactivated.")
end
activated = false
end
function SetHudPresence(state)
SendNUIMessage({AxonUIPresence = state})
hudPresence = state
end
function ShowNotification(message)
BeginTextCommandThefeedPost("STRING")
AddTextComponentSubstringPlayerName(message)
EndTextCommandThefeedPostTicker(true, false)
end