diff options
Diffstat (limited to 'gamemode/npcsystem/npcs/bird.lua')
| -rw-r--r-- | gamemode/npcsystem/npcs/bird.lua | 124 |
1 files changed, 54 insertions, 70 deletions
diff --git a/gamemode/npcsystem/npcs/bird.lua b/gamemode/npcsystem/npcs/bird.lua index fa3ad8d..0b05e62 100644 --- a/gamemode/npcsystem/npcs/bird.lua +++ b/gamemode/npcsystem/npcs/bird.lua @@ -6,17 +6,58 @@ NPC.Icon = Material("wintersurvival2/hud/ws1_icons/icon_rock") NPC.Social = "Pack" --Solo, Pack
-NPC.Vitality = 10
-NPC.Speed = 100
+NPC.Stats = {
+ ["Vitality"] = 10,
+ ["Speed"] = 50,
+ ["AwareDist"] = 800,
+}
+
+--Some npc's like birds have diffent names for their idle sequences
+NPC.IdleSequences = {
+ [0] = "Idle01",
+ [1] = "Eat_A",
+}
+
--Drops should be formated as [index]={["item name"], percent_drop} where percent_drop is a number from 0 to 100
NPC.Drops = {
- [0] = {"Meat",100},--Birds will drop at least 1 meat, and have a 50% chance of dropping 2
- [1] = {"Meat",50},
- [2] = {"Feather",50},
+ [0] = {"Meat",100},
+ [1] = {"Meat",100},
+ [2] = {"Meat",100},
+ [3] = {"Meat",100},
+ [4] = {"Meat",80},
+ [5] = {"Meat",40},
+ [6] = {"Meat",10},
}
--Attacks should be formated as [i]={function attackpriority() = function doattack()}
-NPC.Attacks = nil
+local checkrun = function(self,ply)
+ --If we're awayre of any enemies, run away!
+ return 1
+end
+local dorun = function(self,ply)
+ self:StartActivity(ACT_FLY)
+ self:PlaySequenceAndWait( "Fly01" )
+
+ --Find a position in roughly the oposite direction of the player
+ local tpos = self:GetPos()
+ local ppos = ply:GetPos()
+ local direction = Vector(tpos.x - ppos.x, tpos.y - ppos.y, tpos.z - ppos.z)
+ direction:Normalize()
+ local addition = direction * 1000
+ local topos = self:GetPos() + addition
+ local navarea = navmesh.GetNavArea(self:GetPos(), 100)
+ if navarea:IsValid() then
+ self:MoveToPos(topos)
+ else
+ print("Suicideing a bird to prevent server crash!")
+ self:BecomeRagdoll(DamageInfo())
+ end
+end
+NPC.Attacks = {
+ [1] = {--run away from the player
+ [checkrun] = dorun
+ },
+}
--A function that takes a position and returns true if this is an acceptable place to spawn
NPC.SpawnLocations = nil
@@ -25,7 +66,13 @@ NPC.SpawnLocations = nil NPC.Target = nil
--All enemies that this NPC is aware of
-NPC.AwareEnemies = nil
+NPC.AwareEnemies = {}
+
+--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())
+ return self.Stats["AwareDist"] - dist
+end
--What to replace the ENT:BehaveAct with
function NPC:Act()
@@ -36,69 +83,6 @@ function NPC:Stuck() end
---What to replace ENT:RunBehaviour with
-function NPC:Behave()
- --print("Going into bird's custom behaviour")
- while ( true ) do
- self:StartActivity( ACT_IDLE ) -- walk anims
- self:PlaySequenceAndWait( "Idle01" ) -- Sit on the floor
- --Check if there are any players nearby
- local players = ents.FindByClass("Player")
- local playernearby = false
- for k,v in pairs(players) do
- local fardist = 800
- local closedist = 300
- local removedist = 2000
- local iscrouched = v:Crouching()
- local dist = v:GetPos():Distance(self:GetPos())
- --Remove ourselves if there's noone nearby
- if(dist > 2000) then
- playernearby = true
- end
- --Keep flying away as long as we're being chased
- while((dist < fardist and not iscrouched) or (dist < closedist)) do
- self:StartActivity(ACT_FLY)
- self:PlaySequenceAndWait( "Fly01" )
-
- --Find a position in roughly the oposite direction of the player
- local tpos = self:GetPos()
- local ppos = v:GetPos()
- local direction = Vector(tpos.x - ppos.x, tpos.y - ppos.y, tpos.z - ppos.z)
- direction:Normalize()
- local addition = direction * 1000
- local topos = self:GetPos() + addition
-
- --Check to make sure we can make it somewhere, so we don't crash
- --[[
- if not self.loco:IsAreaTraversable(navmesh.GetNavArea(self:GetPos(),100)) then
- print("No way to go forward!")
- break
- end
- --]]
- local navarea = navmesh.GetNavArea(self:GetPos(), 100)
-
- if navarea:IsValid() then
- --print("Looks like nav area is valid")
- self:MoveToPos(topos)
- else
- --print("Looks like nav area is invalid")
- self:BecomeRagdoll(DamageInfo())
- end
-
-
-
- --Check to see if we're being chased
- iscrouched = v:Crouching()
- dist = v:GetPos():Distance(self:GetPos())
- end
- end
- if not playernearby then
- self:BecomeRagdoll(DamageInfo())
- end
- end
- coroutine.yield()
-end
-
--These are just here to tell the editors/develoeprs what functions are available.. dont un-comment them out, as this could affect all the items.
/*
function NPC:OnSpawn()
|
