From 383aebf4bd5cfaf31702b3b5bbf94d331d6256fd Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Tue, 29 Dec 2015 22:34:58 -0500 Subject: Added dodos --- gamemode/npcsystem/aidirector.lua | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'gamemode/npcsystem/aidirector.lua') 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) -- cgit v1.2.3-70-g09d2