-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
37 lines (32 loc) · 1.48 KB
/
Copy pathserver.lua
File metadata and controls
37 lines (32 loc) · 1.48 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
function outputMessage(element, text)
assert(isElement(element), "outputMessage @ Bad argument: expected element at argument 1, got "..type(element).." "..tostring(element))
triggerClientEvent("onChatIncome", element, tostring(text))
end
function sendMessageToClient(message,messagetype)
if not wasEventCancelled() then
if messagetype == 0 or messagetype == 2 then
triggerClientEvent("onChatIncome", source, message, messagetype)
end
end
end
addEventHandler("onPlayerChat",getRootElement(),sendMessageToClient)
local chatRadius = 0 --units
-- define a handler that will distribute the message to all nearby players
function sendMessageToNearbyPlayers(message, messageType)
-- we will only send normal chat messages, action and team types will be ignored
if messageType == 0 then
-- get the chatting player's position
local posX1, posY1, posZ1 = getElementPosition(source)
-- loop through all player and check distance
for id, player in ipairs(getElementsByType("player")) do
local posX2, posY2, posZ2 = getElementPosition(player)
if getDistanceBetweenPoints3D(posX1, posY1, posZ1, posX2, posY2, posZ2) <= chatRadius then
outputChatBox(message, player)
end
end
end
-- block the original message by cancelling this event
cancelEvent()
end
-- attach our new chat handler to onPlayerChat
addEventHandler( "onPlayerChat", root, sendMessageToNearbyPlayers )