This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathserver.lua
153 lines (128 loc) · 4.8 KB
/
server.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
152
153
AddEventHandler("onResourceStart", function(resName) -- Initialises the script, sets up voice related convars
if GetCurrentResourceName() ~= resName then
return
end
-- Set voice related convars
SetConvarReplicated("voice_useNativeAudio", mumbleConfig.useNativeAudio and "true" or "false")
SetConvarReplicated("voice_use2dAudio", mumbleConfig.use3dAudio and "false" or "true")
SetConvarReplicated("voice_use3dAudio", mumbleConfig.use3dAudio and "true" or "false")
SetConvarReplicated("voice_useSendingRangeOnly", mumbleConfig.useSendingRangeOnly and "true" or "false")
local maxChannel = GetMaxChunkId() << 1 -- Double the max just in case
for i = 1, maxChannel do
MumbleCreateChannel(i)
end
DebugMsg("Initialised Script, " .. maxChannel .. " channels created")
end)
RegisterNetEvent("mumble:Initialise")
AddEventHandler("mumble:Initialise", function()
DebugMsg("Initialised player: " .. source)
if not voiceData[source] then
voiceData[source] = {
mode = 2,
radio = 0,
radioActive = false,
call = 0,
callSpeaker = false,
speakerTargets = {},
radioName = GetRandomPhoneticLetter() .. "-" .. source,
}
end
TriggerClientEvent("mumble:SyncVoiceData", -1, voiceData, radioData, callData)
end)
RegisterNetEvent("mumble:SetVoiceData")
AddEventHandler("mumble:SetVoiceData", function(key, value, target)
if not voiceData[source] then
voiceData[source] = {
mode = 2,
radio = 0,
radioActive = false,
call = 0,
callSpeaker = false,
speakerTargets = {},
radioName = GetRandomPhoneticLetter() .. "-" .. source,
}
end
local radioChannel = voiceData[source]["radio"]
local callChannel = voiceData[source]["call"]
local radioActive = voiceData[source]["radioActive"]
if key == "radio" and radioChannel ~= value then -- Check if channel has changed
if radioChannel > 0 then -- Check if player was in a radio channel
if radioData[radioChannel] then -- Remove player from radio channel
if radioData[radioChannel][source] then
DebugMsg("Player " .. source .. " was removed from radio channel " .. radioChannel)
radioData[radioChannel][source] = nil
end
end
end
if value > 0 then
if not radioData[value] then -- Create channel if it does not exist
DebugMsg("Player " .. source .. " is creating channel: " .. value)
radioData[value] = {}
end
DebugMsg("Player " .. source .. " was added to channel: " .. value)
radioData[value][source] = true -- Add player to channel
end
elseif key == "call" and callChannel ~= value then
if callChannel > 0 then -- Check if player was in a call channel
if callData[callChannel] then -- Remove player from call channel
if callData[callChannel][source] then
DebugMsg("Player " .. source .. " was removed from call channel " .. callChannel)
callData[callChannel][source] = nil
end
end
end
if value > 0 then
if not callData[value] then -- Create call if it does not exist
DebugMsg("Player " .. source .. " is creating call: " .. value)
callData[value] = {}
end
DebugMsg("Player " .. source .. " was added to call: " .. value)
callData[value][source] = true -- Add player to call
end
end
voiceData[source][key] = value
DebugMsg("Player " .. source .. " changed " .. key .. " to: " .. tostring(value))
if key == "speakerTargets" then
TriggerClientEvent("mumble:SetVoiceData", -1, target, key, value)
else
TriggerClientEvent("mumble:SetVoiceData", -1, source, key, value)
end
end)
RegisterCommand("mumbleRadioChannels", function(src, args, raw)
for id, players in pairs(radioData) do
for player, _ in pairs(players) do
RconPrint("\x1b[32m[" .. resourceName .. "]\x1b[0m Channel " .. id .. "-> id: " .. player .. ", name: " .. GetPlayerName(player) .. "\n")
end
end
end, true)
RegisterCommand("mumbleCallChannels", function(src, args, raw)
for id, players in pairs(callData) do
for player, _ in pairs(players) do
RconPrint("\x1b[32m[" .. resourceName .. "]\x1b[0m Call " .. id .. "-> id: " .. player .. ", name: " .. GetPlayerName(player) .. "\n")
end
end
end, true)
AddEventHandler("playerDropped", function()
if voiceData[source] then
if voiceData[source].radio > 0 then
if radioData[voiceData[source].radio] ~= nil then
radioData[voiceData[source].radio][source] = nil
end
end
if voiceData[source].call > 0 then
if callData[voiceData[source].call] ~= nil then
callData[voiceData[source].call][source] = nil
end
end
voiceData[source] = nil
TriggerClientEvent("mumble:RemoveVoiceData", -1, source)
end
end)
function SetPlayerRadioName(serverId, name)
if voiceData[serverId] then
local value = name or (GetRandomPhoneticLetter() .. "-" .. serverId)
voiceData[serverId].radioName = value
TriggerClientEvent("mumble:SetVoiceData", -1, serverId, "radioName", value)
end
end
exports("SetPlayerRadioName", SetPlayerRadioName)