aboutsummaryrefslogtreecommitdiff
path: root/gamemode
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode')
-rw-r--r--gamemode/npcsystem/aidirector.lua46
-rw-r--r--gamemode/npcsystem/npcs/bird.lua35
2 files changed, 70 insertions, 11 deletions
diff --git a/gamemode/npcsystem/aidirector.lua b/gamemode/npcsystem/aidirector.lua
index bcaa63b..d5da7db 100644
--- a/gamemode/npcsystem/aidirector.lua
+++ b/gamemode/npcsystem/aidirector.lua
@@ -34,3 +34,49 @@ function SpawnNpcByName(name, position)
end
ent:Spawn()
end
+
+local random = math.random
+local traceline = util.TraceLine
+local contents = util.PointContents
+local Up = Vector(0,0,1)
+
+--Randomly spawn npc's around?
+local Tick = CurTime()
+hook.Add("Tick","SpawnAmbient",function()
+ if(CLIENT) then return end
+ if (Tick < CurTime()) then
+ --Assume most players are about ground level
+ --Spawn 1 bird for each player on the server
+ local areas = {}
+ for k,v in pairs(player.GetAllHumans()) do
+
+ for i,area in pairs(ents.FindByClass("info_target")) do
+ if (area:GetName() == "survival_spawn") then
+ local parent = area:GetParent()
+ if (IsValid(parent)) then
+ areas[area] = parent
+ end
+ end
+ end
+ --SpawnNpcByName("Bird",v:GetPos() + (v:GetUp()*500))
+ end
+
+ for pAe,pBe in pairs(areas) do
+ local pA,pB = pAe:GetPos(),pBe:GetPos()
+ local Dis = pA:Distance(pB)
+
+ local V = Vector(random(pB.x,pA.x),random(pB.y,pA.y),random(pB.z,pA.z))
+ local Tr = traceline({start=V,endpos=V-Up*40000})
+ local Pos = Tr.HitPos+Up*20
+ local C = contents(Pos)
+
+ if (C != CONTENTS_WATER and C != CONTENTS_WATER+CONTENTS_TRANSLUCENT) then
+ print("Appropriate place found, spawning bird)")
+ SpawnNpcByName("Bird",Pos)
+ break
+ end
+ end
+
+ Tick = CurTime()+30
+ end
+end)
diff --git a/gamemode/npcsystem/npcs/bird.lua b/gamemode/npcsystem/npcs/bird.lua
index 007c16a..d09f1ef 100644
--- a/gamemode/npcsystem/npcs/bird.lua
+++ b/gamemode/npcsystem/npcs/bird.lua
@@ -36,30 +36,43 @@ function NPC:Behave()
print("Going into bird's custom behaviour")
while ( true ) do
self:StartActivity( ACT_IDLE ) -- walk anims
- self.loco:SetDesiredSpeed( 100 ) -- walk speeds
- self:MoveToPos( self:GetPos() + Vector( math.Rand( -1, 1 ), math.Rand( -1, 1 ), 0 ) * 200 ) -- walk to a random place within about 200 units (yielding)
-
-
- -- revert to idle activity
-
-
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())
- if((dist < fardist and not iscrouched) or (dist < closedist)) then
+ --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)
- print("I should fly away")
self:SetSequence( "Fly01" )
- local topos = self:GetPos() + Vector( math.Rand( -1, 1 ), math.Rand( -1, 1 ), 0 ) * 1000
+
+ --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
self:MoveToPos(topos)
- print("Flying to (" .. topos.x .. "," .. topos.y .. "," .. topos.z .. ")")
+
+ --Check to see if we're being chased
+ iscrouched = v:Crouching()
+ dist = v:GetPos():Distance(self:GetPos())
end
end
+ if not playernearby then
+ local di = DamageInfo()
+ self:BecomeRagdoll(di)
+ end
--self:SetSequence( "sit_ground" ) -- Stay sitting
--coroutine.wait( self:PlayScene( "scenes/eli_lab/mo_gowithalyx01.vcd" ) ) -- play a scene and wait for it to finish before progressing
-- Get up