forked from Hellslicer/fivem-radio
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.lua
More file actions
96 lines (88 loc) · 2.8 KB
/
client.lua
File metadata and controls
96 lines (88 loc) · 2.8 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
local customRadios = {}
local isPlaying = false
local index = -1
local volume = GetProfileSetting(306) / 10
local previousVolume = volume
local resourcename = GetCurrentResourceName()
local length = GetNumResourceMetadata(resourcename, "supersede_radio")
for i = 0, length do
local radiodata = GetResourceMetadata(resourcename, "supersede_radio", i)
local data = json.encode(GetResourceMetadata(resourcename, "supersede_radio_extra", i))
if data ~= nil then
table.insert(customRadios, {
isPlaying = false,
name = radiodata,
data = data
})
if data.name then
AddTextEntry(radiodata, data.name);
end
end
end
function PlayCustomRadio(radio)
isPlaying = true
for k, v in pairs(customRadios) do
if v.name == customRadio then
index = v.name
end
end
ToggleCustomRadioBehavior()
SendNuiMessage(json.encode({
type = "play",
radio = radio
}))
end
function StopCustomRadios()
isPlaying = false
ToggleCustomRadioBehavior()
SendNuiMessage(json.encode({
type = "stop"
}))
end
function ToggleCustomRadioBehavior()
SetFrontendRadioActive(not isPlaying)
if isPlaying then
StartAudioScene("DLC_MPHEIST_TRANSITION_TO_APT_FADE_IN_RADIO_SCENE")
else
StopAudioScene("DLC_MPHEIST_TRANSITION_TO_APT_FADE_IN_RADIO_SCENE")
end
end
Citizen.CreateThread(function()
while true do
Wait(50)
if IsPedInAnyVehicle(PlayerPedId()) then
if IsPlayerVehicleRadioEnabled() then
local playerRadioStationName = GetPlayerRadioStationName()
for k, v in pairs(customRadios) do
if v.name == playerRadioStationName then
customRadio = v.name
end
end
if not isPlaying and customRadio then
PlayCustomRadio(customRadio)
elseif isPlaying and customRadio and customRadio ~= index then
StopCustomRadios()
PlayCustomRadio(customRadio)
elseif isPlaying and not customRadio then
StopCustomRadios()
end
elseif isPlaying then
StopCustomRadios()
end
if GetPlayerRadioStationName() == nil then
StopCustomRadios()
end
volume = GetProfileSetting(306) / 10
if previousVolume ~= volume then
SendNuiMessage(json.encode({
type = 'volume',
volume = volume
}))
previousVolume = volume
end
elseif not IsPedInAnyVehicle(PlayerPedId()) then
StopCustomRadios()
Wait(200)
end
end
end)