From dd0d995f3f8279b62ea78b3fe1d8b97b9fe1bb38 Mon Sep 17 00:00:00 2001 From: nomi-nonsz Date: Sun, 10 Aug 2025 15:16:20 +0700 Subject: [PATCH] add blacklist settings --- lua/autorun/hostile_npcs_tocitizen.lua | 51 ++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/lua/autorun/hostile_npcs_tocitizen.lua b/lua/autorun/hostile_npcs_tocitizen.lua index 49f01d3..a95afb4 100644 --- a/lua/autorun/hostile_npcs_tocitizen.lua +++ b/lua/autorun/hostile_npcs_tocitizen.lua @@ -2,6 +2,14 @@ local npcs = list.Get("NPC") local citizenEnemy = npcs["npc_citizen_rebel_enemy"] local originalListSet = list.Set +local function loadNPCBlacklist() + local json = file.Read("npc_blacklist.json", "DATA") + print(json) + if not json or json == "" then return {} end + local data = util.JSONToTable(json) + return istable(data) and data or {} +end + function list.Set(listType, class, npc) if listType == "NPC" then if npc["Class"] == "npc_combine_s" and npc["Category"] ~= "#spawnmenu.category.combine" then @@ -16,6 +24,49 @@ function list.Set(listType, class, npc) originalListSet(listType, class, npc) end +CreateClientConVar("replacehostile_blacklist", "", false, false, "Blacklist NPC Classes") + +hook.Add("PopulateToolMenu", "ReplaceHostileMenu", function() + local blacklist = loadNPCBlacklist() + local defaultBlacklistStr = table.concat(blacklist, ",") + + RunConsoleCommand("replacehostile_blacklist", defaultBlacklistStr) + + spawnmenu.AddToolMenuOption("Options", "Replace Hostile", "ReplaceHostileConfig", "Settings", "", "", function(panel) + panel:ClearControls() + + local blacklistEntry = panel:TextEntry("Blacklist Classes", "replacehostile_blacklist") + + panel:ControlHelp("Separate classes with commas.\nExample: npc_my_custom_hostile,npc_my_hostile,npc_hostile_test") + + blacklistEntry.OnChange = function(self) + local val = self:GetValue() or "" + local newBlacklist = {} + + for e in string.gmatch(val, '([^,]+)') do + local trimmed = string.Trim(e) + if trimmed ~= "" then + table.insert(newBlacklist, trimmed) + end + end + + local valid = true + for _, v in ipairs(newBlacklist) do + if type(v) ~= "string" or v == "" then + valid = false + break + end + end + + if valid then + file.Write("npc_blacklist.json", util.TableToJSON(newBlacklist, false)) + end + end + + panel:Help("NOTE: Restart the map to apply the changes.") + end) +end) + -- Second stage. idk if one of these necessary timer.Simple(0, function () for class, npc in pairs(npcs) do