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 function loadBlacklistFile()
|
||||||
local citizenEnemy = npcs["npc_citizen_rebel_enemy"]
|
|
||||||
local originalListSet = list.Set
|
|
||||||
|
|
||||||
local function loadNPCBlacklist()
|
|
||||||
local json = file.Read("npc_blacklist.json", "DATA")
|
local json = file.Read("npc_blacklist.json", "DATA")
|
||||||
print(json)
|
|
||||||
if not json or json == "" then return {} end
|
if not json or json == "" then return {} end
|
||||||
local data = util.JSONToTable(json)
|
local data = util.JSONToTable(json)
|
||||||
return istable(data) and data or {}
|
return istable(data) and data or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function list.Set(listType, class, npc)
|
local function resetHostile()
|
||||||
if listType == "NPC" then
|
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
|
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["Class"] = citizenEnemy["Class"]
|
||||||
npc["KeyValues"] = {
|
npc["KeyValues"] = {
|
||||||
Hostile = 1,
|
Hostile = 1,
|
||||||
SquadName = "overwatch",
|
SquadName = "overwatch",
|
||||||
citizentype = 4
|
citizentype = 4
|
||||||
}
|
}
|
||||||
|
list.Set("NPC", class, npc)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
originalListSet(listType, class, npc)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
CreateClientConVar("replacehostile_blacklist", "", false, false, "Blacklist NPC Classes")
|
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()
|
hook.Add("PopulateToolMenu", "ReplaceHostileMenu", function()
|
||||||
local blacklist = loadNPCBlacklist()
|
local blacklist = loadBlacklistFile()
|
||||||
local defaultBlacklistStr = table.concat(blacklist, ",")
|
local defaultBlacklistStr = table.concat(blacklist, ",")
|
||||||
|
|
||||||
RunConsoleCommand("replacehostile_blacklist", defaultBlacklistStr)
|
RunConsoleCommand("replacehostile_blacklist", defaultBlacklistStr)
|
||||||
@ -38,6 +57,7 @@ hook.Add("PopulateToolMenu", "ReplaceHostileMenu", function()
|
|||||||
local blacklistEntry = panel:TextEntry("Blacklist Classes", "replacehostile_blacklist")
|
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: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)
|
blacklistEntry.OnChange = function(self)
|
||||||
local val = self:GetValue() or ""
|
local val = self:GetValue() or ""
|
||||||
@ -62,22 +82,9 @@ hook.Add("PopulateToolMenu", "ReplaceHostileMenu", function()
|
|||||||
file.Write("npc_blacklist.json", util.TableToJSON(newBlacklist, false))
|
file.Write("npc_blacklist.json", util.TableToJSON(newBlacklist, false))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
panel:Help("NOTE: Restart the map to apply the changes.")
|
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Second stage. idk if one of these necessary
|
timer.Simple(0, function()
|
||||||
timer.Simple(0, function ()
|
replaceHostile()
|
||||||
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
|
|
||||||
end)
|
end)
|
Loading…
x
Reference in New Issue
Block a user