diff options
| author | Alexander Pickering <Alexander.Pickering@anondomain.site90.net> | 2016-01-10 21:10:03 -0500 |
|---|---|---|
| committer | Alexander Pickering <Alexander.Pickering@anondomain.site90.net> | 2016-01-10 21:10:03 -0500 |
| commit | 31641879af7d32f1570b59bb5d27a193ed0931c3 (patch) | |
| tree | 65799bc24214382c26ee212b460a6b84ace5b8e9 /gamemode/npcsystem | |
| parent | 312f321f771960872fb3ee3e1bb24ebaf91aa38f (diff) | |
| download | wintersurvival2-31641879af7d32f1570b59bb5d27a193ed0931c3.tar.gz wintersurvival2-31641879af7d32f1570b59bb5d27a193ed0931c3.tar.bz2 wintersurvival2-31641879af7d32f1570b59bb5d27a193ed0931c3.zip | |
Fixed npc's breaking when they don't have an initial target
Diffstat (limited to 'gamemode/npcsystem')
| -rw-r--r-- | gamemode/npcsystem/aidirector.lua | 14 | ||||
| -rw-r--r-- | gamemode/npcsystem/npcs/antlion1.lua | 5 | ||||
| -rw-r--r-- | gamemode/npcsystem/npcs/antlion2.lua | 5 | ||||
| -rw-r--r-- | gamemode/npcsystem/npcs/bird.lua | 7 | ||||
| -rw-r--r-- | gamemode/npcsystem/npcs/zombie.lua | 1 |
5 files changed, 25 insertions, 7 deletions
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 <name>")
+end
+
+if(SERVER) then
+ concommand.Add("ws_spawnnpc",spawnnpcfunc, spawnnpccomplete, "Spawns an NPC from winter survival, useage: ws_spawnnpc <name>")
+else
+ concommand.Add("ws_spawnnpc",spawnnpcfunc, spawnnpccomplete, "Spawns an NPC from winter survival, useage: ws_spawnnpc <name>")
+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
|
