Compare commits
1 Commits
1.1.0
...
work/onspa
| Author | SHA1 | Date | |
|---|---|---|---|
| 32966fac0e |
@@ -1,90 +1,61 @@
|
|||||||
local function loadBlacklistFile()
|
local npcs = list.Get("NPC")
|
||||||
local json = file.Read("npc_blacklist.json", "DATA")
|
local citizenEnemy = npcs["npc_citizen_rebel_enemy"]
|
||||||
if not json or json == "" then return {} end
|
local originalListSet = list.Set
|
||||||
local data = util.JSONToTable(json)
|
|
||||||
return istable(data) and data or {}
|
|
||||||
end
|
|
||||||
|
|
||||||
local function resetHostile()
|
function list.Set(listType, class, npc)
|
||||||
local npcs = list.Get("NPC")
|
if listType == "NPC" then
|
||||||
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)
|
if !npc["KeyValues"] then
|
||||||
npc["Class"] = citizenEnemy["Class"]
|
npc["KeyValues"] = {}
|
||||||
npc["KeyValues"] = {
|
end
|
||||||
Hostile = 1,
|
npc["KeyValues"]["SquadName"] = "m_EnemyRebel"
|
||||||
SquadName = "overwatch",
|
|
||||||
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")
|
hook.Add("OnEntityCreated", "ForceReplaceCombine", function(ent)
|
||||||
|
timer.Simple(0, function()
|
||||||
|
if !SERVER then return end
|
||||||
|
if not IsValid(ent) then return end
|
||||||
|
|
||||||
concommand.Add("replacehostile_reload", function()
|
if ent:GetClass() == "npc_citizen" then
|
||||||
resetHostile()
|
|
||||||
replaceHostile()
|
|
||||||
print("NPC Hostile Reloaded")
|
|
||||||
end)
|
|
||||||
|
|
||||||
hook.Add("PopulateToolMenu", "ReplaceHostileMenu", function()
|
|
||||||
local blacklist = loadBlacklistFile()
|
|
||||||
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")
|
|
||||||
panel:Button("Reload NPCs", "replacehostile_reload")
|
|
||||||
|
|
||||||
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
|
end
|
||||||
|
|
||||||
local valid = true
|
if ent:GetKeyValues()["squadname"] == "m_EnemyRebel" then
|
||||||
for _, v in ipairs(newBlacklist) do
|
local pos = ent:GetPos()
|
||||||
if type(v) ~= "string" or v == "" then
|
local ang = ent:GetAngles()
|
||||||
valid = false
|
local mdl = ent:GetModel()
|
||||||
break
|
local weps = ent:GetWeapons()
|
||||||
end
|
local health = ent:GetMaxHealth()
|
||||||
|
local keyValues = ent:GetKeyValues()
|
||||||
|
|
||||||
|
ent:Remove()
|
||||||
|
|
||||||
|
local npc = ents.Create("npc_citizen")
|
||||||
|
if not IsValid(npc) then return end
|
||||||
|
|
||||||
|
for key, value in pairs(keyValues) do
|
||||||
|
npc:SetKeyValue(key, tostring(value))
|
||||||
|
-- if value ~= "" then
|
||||||
|
-- end
|
||||||
end
|
end
|
||||||
|
|
||||||
if valid then
|
npc:SetHealth(health)
|
||||||
file.Write("npc_blacklist.json", util.TableToJSON(newBlacklist, false))
|
npc:SetMaxHealth(health)
|
||||||
|
|
||||||
|
npc:SetKeyValue("hostile", 1)
|
||||||
|
npc:SetKeyValue("squadname", "overwatch")
|
||||||
|
npc:SetKeyValue("citizentype", 4)
|
||||||
|
|
||||||
|
for _, wep in ipairs(weps) do
|
||||||
|
npc:Give(wep:GetClass())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
npc:SetPos(pos)
|
||||||
|
npc:SetAngles(ang)
|
||||||
|
npc:SetModel(mdl)
|
||||||
|
npc:Spawn()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
timer.Simple(0, function()
|
|
||||||
replaceHostile()
|
|
||||||
end)
|
|
||||||
Reference in New Issue
Block a user