Skip to content

Instantly share code, notes, and snippets.

@dhkatz
Created June 15, 2020 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhkatz/bbd926dc4b83f5c843f8f7ff0bd614ca to your computer and use it in GitHub Desktop.
Save dhkatz/bbd926dc4b83f5c843f8f7ff0bd614ca to your computer and use it in GitHub Desktop.
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