From abe2e3b4de8a7d131babc40655fcd41e92ab528b Mon Sep 17 00:00:00 2001 From: Vitroze Date: Fri, 5 Jun 2026 03:22:48 +0200 Subject: [PATCH 1/3] Optimized the hook that allows adding vehicles to the Glide vehicle list. Removed `scripted_ents.GetList` from the spawnmenu and replaced it with the Glide vehicle list. --- lua/glide/client/spawn_tab.lua | 22 ++++------------ lua/glide/sh_lists.lua | 47 +++++++++++++++++----------------- 2 files changed, 29 insertions(+), 40 deletions(-) diff --git a/lua/glide/client/spawn_tab.lua b/lua/glide/client/spawn_tab.lua index 2c60ceb1..8ab807df 100644 --- a/lua/glide/client/spawn_tab.lua +++ b/lua/glide/client/spawn_tab.lua @@ -1,27 +1,15 @@ 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 + for class, data in pairs( list.Get( "GlideVehicles" ) or {} ) do + if data.Category == category then i = i + 1 filtered[i] = { 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..7e9a3f0b 100644 --- a/lua/glide/sh_lists.lua +++ b/lua/glide/sh_lists.lua @@ -51,32 +51,33 @@ 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() +if SERVER then local IsBasedOn = scripted_ents.IsBasedOn - local RegisterEntityClass = duplicator.RegisterEntityClass + 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 + local starfallData = { {} } + for class, _ in pairs( scripted_ents.GetList() ) do + if IsBasedOn( class, "base_glide" ) then + list.Set( "starfall_creatable_sent", class, starfallData ) end + 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 From e20158ad46ef16c60db3e814becb33ccd1977711 Mon Sep 17 00:00:00 2001 From: Vitroze Date: Fri, 5 Jun 2026 03:28:12 +0200 Subject: [PATCH 2/3] Modifying the table insertion --- lua/glide/client/spawn_tab.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lua/glide/client/spawn_tab.lua b/lua/glide/client/spawn_tab.lua index 8ab807df..005d72a1 100644 --- a/lua/glide/client/spawn_tab.lua +++ b/lua/glide/client/spawn_tab.lua @@ -1,11 +1,8 @@ local function GetCategoryVehicles( category ) local filtered = {} - local i = 0 - for class, data in pairs( list.Get( "GlideVehicles" ) or {} ) do if data.Category == category then - i = i + 1 - filtered[i] = { + filtered[#filtered + 1] = { class = class, name = data.Name, icon = data.IconOverride or "entities/" .. class .. ".png", From fa512c273b9ddf1fe5b50a328a07070e71cef12c Mon Sep 17 00:00:00 2001 From: Vitroze Date: Sat, 6 Jun 2026 15:44:09 +0200 Subject: [PATCH 3/3] Using list.Get instead of scripted_ents.GetList --- lua/glide/sh_lists.lua | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lua/glide/sh_lists.lua b/lua/glide/sh_lists.lua index 7e9a3f0b..b812940e 100644 --- a/lua/glide/sh_lists.lua +++ b/lua/glide/sh_lists.lua @@ -52,15 +52,12 @@ list.Set( "GlideProjectileModels", "models/props_phx/misc/potato_launcher_explos -- (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. if SERVER then - local IsBasedOn = scripted_ents.IsBasedOn hook.Add( "InitPostEntity", "Glide.RegisterEntityClasses", function() if SF == nil then return end local starfallData = { {} } - for class, _ in pairs( scripted_ents.GetList() ) do - if IsBasedOn( class, "base_glide" ) then - list.Set( "starfall_creatable_sent", class, starfallData ) - end + for class, _ in pairs( list.Get( "GlideVehicles" ) ) do + list.Set( "starfall_creatable_sent", class, starfallData ) end end ) end