Created
June 15, 2020 06:37
-
-
Save dhkatz/bbd926dc4b83f5c843f8f7ff0bd614ca to your computer and use it in GitHub Desktop.
Garry's Mod Server Optimizations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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