Garry's Mod

Garry's Mod

Star Wars Lightsabers
Vaqxai 1 Sep, 2023 @ 4:23am
Rubat, why is there a FindByClass in a Think hook?
Here, I patched this huge clientside performance issue for you:

(lua/autorun/rb655_lightsaber_clientside.lua; lines: 344, onwards)
local lightsaber_cache = {} hook.Add("OnEntityCreated", "rb655_lightsaber_cache", function( ent ) if ( !IsValid( ent ) ) then return end if ( !ent.GetBladeLength ) then return end table.insert( lightsaber_cache, ent ) local entOldRemove = ent.Remove ent.Remove = function( self ) lightsaber_cache[ self:EntIndex() ] = nil table.RemoveByValue( lightsaber_cache, self ) end end ) hook.Add( "Think", "rb655_lightsaber_ugly_fixes", function() for id, ent in ipairs( lightsaber_cache ) do if ( !IsValid( ent:GetOwner() ) or ent:GetOwner():GetActiveWeapon() != ent or !ent.GetBladeLength or ent:GetBladeLength() <= 0 ) then continue end rb655_ProcessLightsaberEntity( ent ) end for id, ent in ipairs( lightsaber_cache ) do if ( !ent.GetBladeLength or ent:GetBladeLength() <= 0 ) then continue end rb655_ProcessLightsaberEntity( ent ) end end )
< >
Showing 1-1 of 1 comments
< >
Showing 1-1 of 1 comments
Per page: 1530 50