This repository was archived by the owner on Dec 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathvVoice.lua
More file actions
151 lines (124 loc) · 4.96 KB
/
vVoice.lua
File metadata and controls
151 lines (124 loc) · 4.96 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
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
local voiceChatProximity = "veryclose" -- default: veryclose
-- valid options are: veryclose, close, nearby, distant, far, veryfar, global.
local voiceEnabled = true
local allowProximityChange = true -- Allow people to change the chat proximity using /voice distance <proximity>
local allowVoiceToggle = true -- Allow people to disable voice chat for themseleves using /voice toggle
----------------- CODE DON'T TOUCH!!!! ---------------------
RegisterCommand("voice", function(source, args, rawCommand)
if args[1] == "toggle" then
if allowVoiceToggle then
voiceEnabled = not voiceEnabled
TriggerEvent('chatMessage', '', {255,255,255}, "^4Voice Chat is " .. (voiceEnabled == true and "^2enabled" or "^8disabled") .. "^4.")
else
TriggerEvent('chatMessage', '', {255,255,255}, "^4The ability to toggle voice chat is disabled, disable voice chat in your GTA V settings instead.")
end
elseif args[1] == "distance" then
if allowProximityChange then
if args[2] == "veryclose" then
voiceChatProximity = args[2]
TriggerServerEvent("updateClients", voiceChatProximity)
elseif args[2] == "close" then
voiceChatProximity = args[2]
TriggerServerEvent("updateClients", voiceChatProximity)
elseif args[2] == "nearby" then
voiceChatProximity = args[2]
TriggerServerEvent("updateClients", voiceChatProximity)
elseif args[2] == "distant" then
voiceChatProximity = args[2]
TriggerServerEvent("updateClients", voiceChatProximity)
elseif args[2] == "far" then
voiceChatProximity = args[2]
TriggerServerEvent("updateClients", voiceChatProximity)
elseif args[2] == "veryfar" then
voiceChatProximity = args[2]
TriggerServerEvent("updateClients", voiceChatProximity)
elseif args[2] == "global" then
voiceChatProximity = args[2]
TriggerServerEvent("updateClients", voiceChatProximity)
else
sendUsageMessage()
end
else
TriggerEvent('chatMessage', '', {255,255,255}, "^4The ability to change the proximity has been disabled, contact the server owner if you believe that this is an error.")
end
else
sendUsageMessage()
end
end)
function sendUsageMessage()
TriggerEvent('chatMessage', '', {255,255,255}, "^8Usage: ^0/voice [toggle|distance] <veryclose, close, nearby, distant, far, veryfar, global>")
end
local prox = 0.01
RegisterNetEvent("changeProximity")
AddEventHandler('changeProximity', function(vprox)
if vprox == "veryclose" then
prox = 25.01
elseif vprox == "close" then
prox = 75.01
elseif vprox == "nearby" then
prox = 200.01
elseif vprox == "distant" then
prox = 500.01
elseif vprox == "far" then
prox = 2500.01
elseif vprox == "veryfar" then
prox = 8000.01
elseif vprox == "global" then
prox = 0.00
end
end)
function getProximity()
if voiceChatProximity == "veryclose" then
prox = 25.01
elseif voiceChatProximity == "close" then
prox = 75.01
elseif voiceChatProximity == "nearby" then
prox = 200.01
elseif voiceChatProximity == "distant" then
prox = 500.01
elseif voiceChatProximity == "far" then
prox = 2500.01
elseif voiceChatProximity == "veryfar" then
prox = 8000.01
elseif voiceChatProximity == "global" then
prox = 0.00
end
end
getProximity()
function displayText(text, justification, red, green, blue, alpha, posx, posy)
SetTextFont(4)
SetTextWrap(0.0, 1.0)
SetTextScale(1.0, 0.5)
SetTextJustification(justification)
SetTextColour(red, green, blue, alpha)
SetTextOutline()
BeginTextCommandDisplayText("STRING") -- old: SetTextEntry()
AddTextComponentSubstringPlayerName(text) -- old: AddTextComponentString
EndTextCommandDisplayText(posx, posy) -- old: DrawText()
end
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
NetworkSetTalkerProximity(prox)
NetworkClearVoiceChannel()
NetworkSetVoiceActive(voiceEnabled)
local playersTalking = {'empty'}
if voiceEnabled then
local count = 1
for i=0,31 do
if NetworkIsPlayerTalking(i) then
playersTalking[count] = GetPlayerName(i)
count = count + 1
end
end
if playersTalking[1] ~= "empty" then
displayText("Currently talking:", 0, 255, 255, 255, 255, 0.5, 0.0)
count = 0
for k,v in pairs(playersTalking) do
displayText("~f~" .. v, 0, 255, 255, 255, 255, 0.5, 0.025 + (0.025*(count)))
count = count + 1
end
end
end
end
end)