working blacklist system and apply list command
This commit is contained in:
parent
dd0d995f3f
commit
154ffe2fed
@ -1,33 +1,52 @@
|
||||
local npcs = list.Get("NPC")
|
||||
local citizenEnemy = npcs["npc_citizen_rebel_enemy"]
|
||||
local originalListSet = list.Set
|
||||
|
||||
local function loadNPCBlacklist()
|
||||
local function loadBlacklistFile()
|
||||
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
|
||||
local function resetHostile()
|
||||
local npcs = list.Get("NPC")
|
||||
for class, npc in pairs(npcs) do
|
||||
if npc["m_OldData"] then
|
||||
local oldData = util.JSONToTable(npc["m_OldData"])
|
||||
if oldData then
|
||||
list.Set("NPC", class, oldData)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function replaceHostile()
|
||||
local blacklist = loadBlacklistFile()
|
||||
local npcs = list.Get("NPC")
|
||||
local citizenEnemy = npcs["npc_citizen_rebel_enemy"]
|
||||
|
||||
for class, npc in pairs(npcs) do
|
||||
if table.HasValue(blacklist, class) then continue end
|
||||
if npc["Class"] == "npc_combine_s" and npc["Category"] ~= "#spawnmenu.category.combine" then
|
||||
npc["m_OldData"] = npc["m_OldData"] or util.TableToJSON(npc, false)
|
||||
npc["Class"] = citizenEnemy["Class"]
|
||||
npc["KeyValues"] = {
|
||||
Hostile = 1,
|
||||
SquadName = "overwatch",
|
||||
citizentype = 4
|
||||
}
|
||||
list.Set("NPC", class, npc)
|
||||
end
|
||||
end
|
||||
originalListSet(listType, class, npc)
|
||||
end
|
||||
|
||||
CreateClientConVar("replacehostile_blacklist", "", false, false, "Blacklist NPC Classes")
|
||||
|
||||
concommand.Add("replacehostile_reload", function()
|
||||
resetHostile()
|
||||
replaceHostile()
|
||||
print("NPC Hostile Reloaded")
|
||||
end)
|
||||
|
||||
hook.Add("PopulateToolMenu", "ReplaceHostileMenu", function()
|
||||
local blacklist = loadNPCBlacklist()
|
||||
local blacklist = loadBlacklistFile()
|
||||
local defaultBlacklistStr = table.concat(blacklist, ",")
|
||||
|
||||
RunConsoleCommand("replacehostile_blacklist", defaultBlacklistStr)
|
||||
@ -38,6 +57,7 @@ hook.Add("PopulateToolMenu", "ReplaceHostileMenu", function()
|
||||
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")
|
||||
panel:Button("Reload NPCs", "replacehostile_reload")
|
||||
|
||||
blacklistEntry.OnChange = function(self)
|
||||
local val = self:GetValue() or ""
|
||||
@ -62,22 +82,9 @@ hook.Add("PopulateToolMenu", "ReplaceHostileMenu", function()
|
||||
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
|
||||
if npc["Class"] == "npc_combine_s" and npc["Category"] ~= "#spawnmenu.category.combine" then
|
||||
npc["Class"] = citizenEnemy["Class"]
|
||||
npc["KeyValues"] = {
|
||||
Hostile = 1,
|
||||
SquadName = "overwatch",
|
||||
citizentype = 4
|
||||
}
|
||||
originalListSet("NPC", class, npc)
|
||||
end
|
||||
end
|
||||
replaceHostile()
|
||||
end)
|
Loading…
x
Reference in New Issue
Block a user