forked from AvarianKnight/pma-voice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared.lua
93 lines (83 loc) · 2.32 KB
/
shared.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
Cfg = {}
voiceTarget = 1
gameVersion = GetGameName()
-- these are just here to satisfy linting
if not IsDuplicityVersion() then
LocalPlayer = LocalPlayer
playerServerId = GetPlayerServerId(PlayerId())
end
Player = Player
Entity = Entity
if GetConvar('voice_useNativeAudio', 'false') == 'true' then
-- native audio distance seems to be larger then regular gta units
Cfg.voiceModes = {
{1.5, "Whisper"}, -- Whisper speech distance in gta distance units
{3.0, "Normal"}, -- Normal speech distance in gta distance units
{6.0, "Shouting"} -- Shout speech distance in gta distance units
}
else
Cfg.voiceModes = {
{3.0, "Whisper"}, -- Whisper speech distance in gta distance units
{7.0, "Normal"}, -- Normal speech distance in gta distance units
{15.0, "Shouting"} -- Shout speech distance in gta distance units
}
end
logger = {
log = function(message, ...)
print((message):format(...))
end,
info = function(message, ...)
if GetConvarInt('voice_debugMode', 0) >= 1 then
print(('[info] ' .. message):format(...))
end
end,
warn = function(message, ...)
print(('[^1WARNING^7] ' .. message):format(...))
end,
error = function(message, ...)
error((message):format(...))
end,
verbose = function(message, ...)
if GetConvarInt('voice_debugMode', 0) >= 4 then
print(('[verbose] ' .. message):format(...))
end
end,
}
function tPrint(tbl, indent)
indent = indent or 0
for k, v in pairs(tbl) do
local tblType = type(v)
local formatting = string.rep(" ", indent) .. k .. ": "
if tblType == "table" then
print(formatting)
tPrint(v, indent + 1)
elseif tblType == 'boolean' then
print(formatting .. tostring(v))
elseif tblType == "function" then
print(formatting .. tostring(v))
else
print(formatting .. v)
end
end
end
local function types(args)
local argType = type(args[1])
for i = 2, #args do
local arg = args[i]
if argType == arg then
return true, argType
end
end
return false, argType
end
function type_check(...)
local vars = {...}
for i = 1, #vars do
local var = vars[i]
local matchesType, varType = types(var)
if not matchesType then
table.remove(var, 1)
error(("Invalid type sent to argument #%s, expected %s, got %s"):format(i, table.concat(var, "|"), varType))
end
end
end