Best way to make a ranged chat

Ok so what i want to do is a rp chat, so people thats to far away from you cant see what your saying. But idk what hook i should use for this.
Ive tried the hook **[Gamemode.PlayerCanSeePlayersChat

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Gamemode.PlayerCanSeePlayersChat) **but i cant really get it to work, when i return false on everything but i use chat.AddText to print the chat on the client.

Take a look at my code for Voice Chat Radius

[lua]VC_MAX_RADIUS = 120
timer.Create( “VoiceChatRadius”, 1, 0, function()
local lpl = LocalPlayer();
for _,ply in ipairs(player:GetAll()) do
if (ply ~= lpl) then
if (ply:GetPos():Distance(lpl:GetPos()) <= VC_MAX_RADIUS) then
if (ply:IsMuted()) then
lpl:SetMuted(ply);
end
elseif (not ply:IsMuted()) then
lpl:SetMuted(ply);
end
end
end
end)
[/lua]

You can easily do something like that for Chat Range as well

Ive made the voice chat radous for my gamemode but it shouldnt return exacly the same on all chat types.
If your yelling the text should be orange if its local ooc it should be grey…

Take a look at how DarkRP did the tags for OOC, Yell, IC and whatnot, and just set the colour on that.

Don’t do that, it’s stupid and inefficient.

[lua]
local voiceRadius = 500
hook.Add( “PlayerCanHearPlayersVoice”, “SomeUniqueName”, function( pListener, pTalker )
if pListener:GetPos():Distance( pTalker:GetPos() ) > voiceRadius then
return false
end
end )[/lua]

raBBish, you set upa a “VoiceRadius” variable but you aren’t using it, I think you meant

[lua]
local voiceRadius = 500
hook.Add( “PlayerCanHearPlayersVoice”, “SomeUniqueName”, function( pListener, pTalker )
if pListener:GetPos():Distance( pTalker:GetPos() ) > voiceRadius then
return false
end
end )
[/lua]

Whoops, thanks for notifying :3:

Guys why do you reply with voice radius code when i said ive already made it.
Also i will take a look at the DarkRP code.

uhm i just got an idea. If i return true will the chat messege return trow another hook at the client? cause then i can fix the colors there.

for other people who want to see how to do it. and since you werent sincere enough to post your script, others are helping out and showing them how to do it. Thats why…

ehm we are talking about a chat script not a voice script so it doesn’t belong in this topic…

Tip: Use vector:LengthSqr() and square your maximum distance as well. That way you don’t have to do a square root to every player every time someone says something.

Just use this hooks:
**[Gamemode.PlayerCanHearPlayersVoice

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Gamemode.PlayerCanHearPlayersVoice)**
**[Gamemode.PlayerCanSeePlayersChat

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Gamemode.PlayerCanSeePlayersChat)**
and this function vector1:Distance(vector2) and i solved it



VectorFinal = vector1 - vector2 //The order you do this in doesn't matter, since you square the result anyways, it'll always be positive. You could do vector2 - vector1 and get the same answer.
if VectorFinal:LengthSqr() > MaximumRadius ^ 2 then


That’s far, far more efficient.

Why is the OP answering the people that are trying to help him. You ask a question, then you disregard what people say with the reply “I done that already”