-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.lua
64 lines (55 loc) · 1.81 KB
/
functions.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
---@class functions
local functions = {}
---@param pid integer PlayerID
---@return vector3 playerCoordinates
function functions.getPlayerCoords(pid)
return vec3(tes3mp.GetPosX(pid), tes3mp.GetPosY(pid), tes3mp.GetPosZ(pid))
end
---@param message string
function functions.log(message)
tes3mp.LogMessage(enumerations.log.VERBOSE, "[ RPChat ]: " .. message)
end
---@param message table
---@return string text
function functions.concatenateMessage(message)
local text = ""
for i, j in pairs(message) do
if i ~= 1 then
text = text .. " " .. j
end
end
return text
end
---@param pid integer Source PlayerID
---@param pidTarget integer pid of target player
---@param maxDisplacement integer Voice Range
---@param message string
function functions.sendRangedMessage(pid, pidTarget, maxDisplacement, message)
if not pidTarget then return end
local source, target = functions.getPlayerCoords(pid), functions.getPlayerCoords(pidTarget)
if -(source - target) > maxDisplacement then return end
tes3mp.SendMessage(pidTarget, message, false)
end
---@param pid integer Source Player ID
---@param message string
---@param maxDisplacement integer Voice Range
function functions.RangedMethod(pid, message, maxDisplacement)
local otherPlayers = functions.retrieveOtherPlayerInfo(pid)
if next(otherPlayers) then
for tid in pairs(otherPlayers) do
functions.sendRangedMessage(pid, tid, maxDisplacement, message)
end
end
tes3mp.SendMessage(pid, message, false)
end
---@param pid integer Source PlayerID
function functions.retrieveOtherPlayerInfo(pid)
local otherPlayers = {}
for i in pairs(Players) do
if i ~= pid then
otherPlayers[#otherPlayers+1] = i
end
end
return otherPlayers
end
return functions