diff --git a/lua/glide/client/spawn_tab.lua b/lua/glide/client/spawn_tab.lua index 2c60ceb1..005d72a1 100644 --- a/lua/glide/client/spawn_tab.lua +++ b/lua/glide/client/spawn_tab.lua @@ -1,27 +1,12 @@ local function GetCategoryVehicles( category ) - local type = type - - local function Validate( t ) - if type( t ) ~= "table" then return false end - if type( t.ClassName ) ~= "string" then return false end - if type( t.GlideCategory ) ~= "string" then return false end - - return true - end - local filtered = {} - local i = 0 - - for class, data in pairs( scripted_ents.GetList() ) do - local t = data.t - - if Validate( t ) and t.GlideCategory == category then - i = i + 1 - filtered[i] = { + for class, data in pairs( list.Get( "GlideVehicles" ) or {} ) do + if data.Category == category then + filtered[#filtered + 1] = { class = class, - name = t.PrintName, - icon = t.IconOverride or "entities/" .. class .. ".png", - adminOnly = t.AdminOnly + name = data.Name, + icon = data.IconOverride or "entities/" .. class .. ".png", + adminOnly = data.AdminOnly } end end diff --git a/lua/glide/sh_lists.lua b/lua/glide/sh_lists.lua index 6daca94a..b812940e 100644 --- a/lua/glide/sh_lists.lua +++ b/lua/glide/sh_lists.lua @@ -51,32 +51,30 @@ list.Set( "GlideProjectileModels", "models/props_phx/misc/potato_launcher_explos -- Find and register all entities that are children of `base_glide` -- (or any of it's children classes) on the duplicator/entity limit system. -- Also add them to a separate list, and make them spawnable on Starfall. -hook.Add( "InitPostEntity", "Glide.RegisterEntityClasses", function() - local IsBasedOn = scripted_ents.IsBasedOn - local RegisterEntityClass = duplicator.RegisterEntityClass +if SERVER then + hook.Add( "InitPostEntity", "Glide.RegisterEntityClasses", function() + if SF == nil then return end - local isStarfallAvailable = SF ~= nil - local starfallData = { {} } - - for class, data in pairs( scripted_ents.GetList() ) do - if IsBasedOn( class, "base_glide" ) then - if SERVER then - RegisterEntityClass( class, Glide.VehicleFactory, "Data" ) - - if isStarfallAvailable then - list.Set( "starfall_creatable_sent", class, starfallData ) - end - end + local starfallData = { {} } + for class, _ in pairs( list.Get( "GlideVehicles" ) ) do + list.Set( "starfall_creatable_sent", class, starfallData ) + end + end ) +end - local entTable = data["t"] +local RegisterEntityClass = duplicator.RegisterEntityClass +hook.Add( "PreRegisterSENT", "Glide.RegisterEntityClasses", function( tbl, class ) + if not tbl or not class then return end + if not tbl.GlideCategory or tbl.GlideCategory == "" then return end - if entTable and entTable.GlideCategory then - list.Set( "GlideVehicles", class, { - Name = entTable.PrintName or class, - Category = entTable.GlideCategory or "Default", - Model = entTable.ChassisModel - } ) - end - end + if SERVER then + RegisterEntityClass( class, Glide.VehicleFactory, "Data" ) end -end ) + + list.Set( "GlideVehicles", class, { + Name = tbl.PrintName or class, + Category = tbl.GlideCategory or "Default", + IconOverride = tbl.IconOverride, + Model = tbl.ChassisModel + } ) +end ) \ No newline at end of file