Skip to content

Instantly share code, notes, and snippets.

@dhkatz
Created Jun 15, 2020
Embed
What would you like to do?
Garry's Mod Server Optimizations
timer.Create("CalculatePlayersHearing", 0.5, 0, function()
for index, ply in pairs(player.GetAll()) do
if !ply.Char then ply.CanHearTrue = nil ply.CanHear = nil continue end
ply.CanHearTrue = {}
ply.CanHear = {}
for index, pl in pairs(player.GetAll()) do
if !pl.Char then continue end
if pl == ply then ply.CanHear[#ply.CanHear + 1] = ply ply.CanHearTrue[pl] = true continue end
if ply:GetPos():DistToSqr(pl:GetPos()) < GetConVar("Voice.Range")^2 then
ply.CanHearTrue[pl] = true
end
local bool = hook.Run("CanPlayerHearPlayer", ply, pl)
if bool != nil then ply.CanHearTrue[pl] = true end
ply.CanHear[#ply.CanHear+1] = (ply.CanHearTrue[pl] and pl or nil)
end
end
end)
hook.Add( "PlayerCanHearPlayersVoice", "Maximum Range", function( listener, talker )
if talker.CanHear then
return talker.CanHearTrue[listener], true
else
return false -- for now
end
end )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment