From 383aebf4bd5cfaf31702b3b5bbf94d331d6256fd Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Tue, 29 Dec 2015 22:34:58 -0500 Subject: Added dodos --- entities/entities/ws_npc_ambient/init.lua | 22 ++++++++++++-- entities/entities/ws_npc_ambient/shared.lua | 19 ------------ gamemode/npcsystem/aidirector.lua | 46 +++++++++++++++++++++++++++++ gamemode/npcsystem/npcs/bird.lua | 35 +++++++++++++++------- 4 files changed, 90 insertions(+), 32 deletions(-) diff --git a/entities/entities/ws_npc_ambient/init.lua b/entities/entities/ws_npc_ambient/init.lua index f9aa726..ee39178 100644 --- a/entities/entities/ws_npc_ambient/init.lua +++ b/entities/entities/ws_npc_ambient/init.lua @@ -22,12 +22,30 @@ function ENT:Initialize() ]]-- end -function ENT:OnTakeDamage(dmg) +function ENT:OnInjured(dmg) print("Taking some dammage") + local itempos = self:GetPos() self:SetHealth(self:Health() - dmg:GetDamage()) if self.OnDammage != nil then self:OnDammage(dmg) end if self:Health() <= 0 then //run on death - self:Remove() + if(CLIENT) then return end + if not self.Drops then return end + print("Looks like we have some drops") + local rng = math.random(0,100) + for k,v in pairs(self.Drops) do + local itemname = self.Drops[k][1] + local itemchance = self.Drops[k][2] + local heightoffset = 10 + if rng < itemchance then + print("Createing a " .. itemname) + local drop = ents.Create("ws_item") + drop.Item = GetItemByName(itemname) + drop:SetModel(drop.Item.Model) + drop:SetPos(itempos + (self:GetUp()*heightoffset)) + drop:Spawn() + heightoffset = heightoffset + 10 + end + end --self:SetSchedule( SCHED_FALL_TO_GROUND ) end end diff --git a/entities/entities/ws_npc_ambient/shared.lua b/entities/entities/ws_npc_ambient/shared.lua index cac9e39..ba65e2b 100644 --- a/entities/entities/ws_npc_ambient/shared.lua +++ b/entities/entities/ws_npc_ambient/shared.lua @@ -15,25 +15,6 @@ ENT.Act = nil Desc: Called just before entity is deleted ---------------------------------------------------------*/ function ENT:OnRemove() - print("Doing onremove") - if(CLIENT) then return end - if not self.Drops then return end - print("Looks like we have some drops") - local rng = math.random(0,100) - for k,v in pairs(self.Drops) do - local itemname = self.Drops[k][1] - local itemchance = self.Drops[k][2] - local heightoffset = 10 - if rng < itemchance then - print("Createing a " .. itemname) - local drop = ents.Create("ws_item") - drop.Item = GetItemByName(itemname) - drop:SetModel(drop.Item.Model) - drop:SetPos(self:GetUp()*heightoffset) - drop:Spawn() - heightoffset = heightoffset + 10 - end - end end function ENT:BehaveAct() 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 -- cgit v1.2.3-70-g09d2