From 31641879af7d32f1570b59bb5d27a193ed0931c3 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sun, 10 Jan 2016 21:10:03 -0500 Subject: Fixed npc's breaking when they don't have an initial target --- gamemode/npcsystem/aidirector.lua | 14 +++++++++++--- gamemode/npcsystem/npcs/antlion1.lua | 5 ++++- gamemode/npcsystem/npcs/antlion2.lua | 5 ++++- gamemode/npcsystem/npcs/bird.lua | 7 +++++-- gamemode/npcsystem/npcs/zombie.lua | 1 + 5 files changed, 25 insertions(+), 7 deletions(-) (limited to 'gamemode/npcsystem') diff --git a/gamemode/npcsystem/aidirector.lua b/gamemode/npcsystem/aidirector.lua index fb85b2d..2f9b7a7 100644 --- a/gamemode/npcsystem/aidirector.lua +++ b/gamemode/npcsystem/aidirector.lua @@ -8,7 +8,7 @@ concommand.Add("ws_spawnbird",function(ply,cmd,args) SpawnNpcByName("Bird",ply:GetPos()) end) -concommand.Add("ws_spawnnpc",function(ply,cmd,args) +local function spawnnpcfunc(ply,cmd,args) if(!args[1]) then print("You must enter the name of an npc") return end @@ -18,7 +18,9 @@ concommand.Add("ws_spawnnpc",function(ply,cmd,args) print("attempting to spawn npc...") SpawnNpcByName(args[1],ply:GetPos()) print("NPC spawned!") -end, function(cmd,stringargs) +end + +local function spawnnpccomplete(cmd,stringargs) print(cmd, stringargs) local tbl = {} stringargs = string.sub(stringargs,2) @@ -36,7 +38,13 @@ end, function(cmd,stringargs) end end return tbl -end, "Spawns an NPC from winter survival, useage: ws_spawnnpc ") +end + +if(SERVER) then + concommand.Add("ws_spawnnpc",spawnnpcfunc, spawnnpccomplete, "Spawns an NPC from winter survival, useage: ws_spawnnpc ") +else + concommand.Add("ws_spawnnpc",spawnnpcfunc, spawnnpccomplete, "Spawns an NPC from winter survival, useage: ws_spawnnpc ") +end function SpawnNpcByName(name, position) if(CLIENT) then return end diff --git a/gamemode/npcsystem/npcs/antlion1.lua b/gamemode/npcsystem/npcs/antlion1.lua index 0e62a92..502ebc6 100644 --- a/gamemode/npcsystem/npcs/antlion1.lua +++ b/gamemode/npcsystem/npcs/antlion1.lua @@ -87,7 +87,10 @@ NPC.Attacks = { --Attack priority is a fucntion that takes a player, and returns an int describing it's prority to attack (higher = more important) NPC will always attack the player with the highest priority function NPC:AttackPriority(ply) - local dist = ply:GetPos():Distance(self:GetPos()) + local plypos = ply:GetPos() + local mypas = self:GetPos() + if not plypos then return 0 end + local dist = plypos:Distance(mypos)s return self.Stats["AwareDist"] - dist end diff --git a/gamemode/npcsystem/npcs/antlion2.lua b/gamemode/npcsystem/npcs/antlion2.lua index 1d2087b..d6a7390 100644 --- a/gamemode/npcsystem/npcs/antlion2.lua +++ b/gamemode/npcsystem/npcs/antlion2.lua @@ -109,7 +109,10 @@ NPC.Attacks = { --Attack priority is a fucntion that takes a player, and returns an int describing it's prority to attack (higher = more important) NPC will always attack the player with the highest priority function NPC:AttackPriority(ply) - local dist = ply:GetPos():Distance(self:GetPos()) + local plypos = ply:GetPos() + local mypas = self:GetPos() + if not plypos then return 0 end + local dist = plypos:Distance(mypos) return self.Stats["AwareDist"] - dist end diff --git a/gamemode/npcsystem/npcs/bird.lua b/gamemode/npcsystem/npcs/bird.lua index 7b19457..d8dfb30 100644 --- a/gamemode/npcsystem/npcs/bird.lua +++ b/gamemode/npcsystem/npcs/bird.lua @@ -70,10 +70,13 @@ NPC.Target = nil --All enemies that this NPC is aware of NPC.AwareEnemies = {} - +`w` --Attack priority is a fucntion that takes a player, and returns an int describing it's prority to attack (higher = more important) NPC will always attack the player with the highest priority function NPC:AttackPriority(ply) - local dist = ply:GetPos():Distance(self:GetPos()) + local plypos = ply:GetPos() + local mypas = self:GetPos() + if not plypos then return 0 end + local dist = plypos:Distance(mypos) return self.Stats["AwareDist"] - dist end diff --git a/gamemode/npcsystem/npcs/zombie.lua b/gamemode/npcsystem/npcs/zombie.lua index ce4105b..b4718a4 100644 --- a/gamemode/npcsystem/npcs/zombie.lua +++ b/gamemode/npcsystem/npcs/zombie.lua @@ -90,6 +90,7 @@ NPC.Attacks = { function NPC:AttackPriority(ply) local plypos = ply:GetPos() local mypas = self:GetPos() + if not plypos then return 0 end local dist = plypos:Distance(mypos) return self.Stats["AwareDist"] - dist end -- cgit v1.2.3-70-g09d2