From 52fb13ef163bcea7f1409e17fd62509703de9f69 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Thu, 17 Nov 2016 17:11:15 -0500 Subject: Added persistance --- gamemode/npcsystem/aidirector.lua | 71 ++++++++++----------------------------- 1 file changed, 17 insertions(+), 54 deletions(-) (limited to 'gamemode/npcsystem/aidirector.lua') diff --git a/gamemode/npcsystem/aidirector.lua b/gamemode/npcsystem/aidirector.lua index bda81d7..f5cfc93 100644 --- a/gamemode/npcsystem/aidirector.lua +++ b/gamemode/npcsystem/aidirector.lua @@ -15,9 +15,7 @@ local function spawnnpcfunc(ply,cmd,args) local npc = GetNpcByName(args[1]) if(npc == nil) then print("Not a valid name!") return end - print("attempting to spawn npc...") SpawnNpcByName(args[1],ply:GetPos()) - print("NPC spawned!") end local function spawnnpccomplete(cmd,stringargs) @@ -34,7 +32,7 @@ local function spawnnpccomplete(cmd,stringargs) if(string.find(string.lower(v.Name),stringargs)) then table.insert(tbl,cmd .. " \"" .. v.Name .. "\"") else - print("Could not find " .. stringargs .. " in " .. string.lower(v.Name)) + ErrorNoHalt("Could not find " .. stringargs .. " in " .. string.lower(v.Name)) end end return tbl @@ -46,69 +44,34 @@ else concommand.Add("ws_spawnnpc",spawnnpcfunc, spawnnpccomplete, "Spawns an NPC from winter survival, useage: ws_spawnnpc ") end +local npcfields = { + "Model","Drops","OnDammage","Behave", + "Act","Stats","IdleSequences","Attacks", + "AttackPriority","AwareEnemies","OnSpawn" +} + function SpawnNpcByName(name, position) if(CLIENT) then return end entdata = GetNpcByName(name) if not entdata then - print("Could not find npc data for name " .. name) + ErrorNoHalt("Could not find npc data for name ",name) return end if not position then - print("Invalid position:") - print(position) + ErrorNoHalt("Attempted to spawn an NPC at an invalid location",position) return end ent = ents.Create("ws_npc_ambient") if(not ent) then - print("Could not spawn npc ws_npc_ambient") return end ent:SetPos(position) - print("From server!") - if(entdata.Name) then - ent.Name = entdata.Name - end - if(entdata.Model) then - ent.Model = entdata.Model - end - if(entdata.Drops) then - ent.Drops = entdata.Drops - end - if(entdata.OnDammage) then - ent.OnDammage = entdata.OnDammage - end - if(entdata.Behave) then - ent.Behave = entdata.Behave - end - if(entdata.Act) then - ent.Act = entdata.Act - end - if(entdata.Stats) then - ent.Stats = entdata.Stats - end - if(entdata.IdleSequences) then - ent.IdleSequences = entdata.IdleSequences - end - if(entdata.Attacks) then - ent.Attacks = entdata.Attacks - end - if(entdata.AttackPriority) then - ent.AttackPriority = entdata.AttackPriority - end - if(entdata.AwareEnemies) then - ent.AwareEnemies = entdata.AwareEnemies - end - if(entdata.OnSpawn) then - ent.OnSpawn = entdata.OnSpawn - end - --[[ - if(entdata.BehaveCycle) then - ent.BehaveCycle = entdata.BehaveCycle + for k,v in pairs(npcfields) do + if entdata[v] then + ent[v] = entdata[v] + end end - ]]-- - print("NPC created") ent:Spawn() - print("NPC spawned") end local random = math.random @@ -153,13 +116,13 @@ hook.Add("Tick","SpawnAmbient",function() local C = contents(Pos) if (C != CONTENTS_WATER and C != CONTENTS_WATER+CONTENTS_TRANSLUCENT) then - --print("Appropriate place found, spawning bird)") local randnpcnum = math.Round(math.Rand(0, #ambientnpcs)) local npc = GetNpcByName(ambientnpcs[randnpcnum]) if(npc == nil) then - print("Found npc that getnpcbyname returned nil for") - print(ambientnpcs[randnpcnum]) - continue + ErrorNoHalt(string.format([[ + Tried to spawn an NPC that wasn't registered: %s + ]],ambientnpcs[randnpcnum])) + continue end if(npc:SpawnLocations(Pos)) then SpawnNpcByName(ambientnpcs[randnpcnum],Pos) -- cgit v1.2.3-70-g09d2