From f1e99d19a5aa6e5fa61518366235e3da09689d0b Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 2 Jan 2016 22:10:06 -0500 Subject: Ai overhual now working --- entities/entities/ws_npc_ambient/init.lua | 5 ++ entities/entities/ws_npc_ambient/shared.lua | 75 ++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 1 deletion(-) (limited to 'entities') diff --git a/entities/entities/ws_npc_ambient/init.lua b/entities/entities/ws_npc_ambient/init.lua index 485b6c9..a0497dd 100644 --- a/entities/entities/ws_npc_ambient/init.lua +++ b/entities/entities/ws_npc_ambient/init.lua @@ -8,6 +8,11 @@ function ENT:Initialize() --print("NPC spawned!") if(self.Model) then self:SetModel(self.Model) else print("NPC created without model, this might be a bug!") end + if(self.Stats["Vitality"]) then self.Vitality = self.Stats["Vitality"] + else print("NPC created with no stat for vitality, this might be a bug!")end + if(self.Stats["Accel"]) then self.loco:SetAcceleration(self.Stats["Accel"])end + if(self.Stats["Decel"]) then self.loco:SetDeceleration(self.Stats["Decel"]) end + if(self.Stats["Step"]) then self.loco:SetJumpHeight(self.Stats["Step"]) end --self:SetModel( "models/Humans/Group01/Female_01.mdl" ) --[[ self:SetHullType( HULL_HUMAN ); diff --git a/entities/entities/ws_npc_ambient/shared.lua b/entities/entities/ws_npc_ambient/shared.lua index ba65e2b..7fa3661 100644 --- a/entities/entities/ws_npc_ambient/shared.lua +++ b/entities/entities/ws_npc_ambient/shared.lua @@ -17,6 +17,79 @@ ENT.Act = nil function ENT:OnRemove() end +function ENT:DefaultBehaviour() + while ( true ) do + --Main loop for ai + + --Update aware enemies + local players = ents.FindByClass("Player") + for k,v in pairs(players) do + if(v:IsPigeon()) then continue end + local dist = v:GetPos():Distance(self:GetPos()) + if( dist < self.Stats["AwareDist"]) then + table.insert(self.AwareEnemies,v) + end + end + + --Find the enemy with the highest priority + local maxpriority = -1 + local maxprioritytarget = nil + for k,v in pairs(self.AwareEnemies) do + local priority = self:AttackPriority(v) + if(priority > maxpriority) then + maxpriority = priority + maxprioritytarget = v + end + end + self.Target = maxprioritytarget + + --If we can't find anyone to attack, just stay idle + if(self.Target == nil) then + print("Couldn't find anyone to attack!") + --Play an idle sequence + local randanim = math.Round(math.Rand(0,#self.IdleSequences)) + self:PlaySequenceAndWait( self.IdleSequences[randanim] ) + self:StartActivity( ACT_IDLE ) + --If there's noone within 4000 units, just remove ourselves to save server resources + local closest = 5000 + for k,v in pairs(player.GetAll()) do + local thisdist = self:GetPos():Distance(v:GetPos()) + if(thisdist > closest) then + closest = thisdist + end + end + if(closest > 4000) then self:BecomeRagdoll(DamageInfo()) end + else + --We have a target to attack! + + --Find which attack will do the most dammage + local maxdammage = -1 + local maxdammagefunc = nil + for k,v in pairs(self.Attacks) do + local dammagefunc = nil + local attackfunc = nil + for i,j in pairs(v) do + dammagefunc = i + attackfunc = j + end + local dammage = dammagefunc(self, self.Target) + if(dammage > maxdammage) then + maxdammage = dammage + maxdammagefunc = attackfunc + end + end + + --Do that attack + if(maxdammagefunc) then + maxdammagefunc(self, self.Target) + end + end + coroutine.yield() + end + + coroutine.yield() +end + function ENT:BehaveAct() if(self.Act) then self:Act() @@ -29,6 +102,6 @@ function ENT:RunBehaviour() if(self.Behave) then self:Behave() else - print("NPC spawned without a Behave function, this might be an error!") + self:DefaultBehaviour() end end -- cgit v1.2.3-70-g09d2 From 60755b6e0f24770117c39e0faddfcfaca5bf9afb Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 2 Jan 2016 22:41:57 -0500 Subject: Allow arrows to be picked up again --- entities/entities/ws_arrow/init.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'entities') diff --git a/entities/entities/ws_arrow/init.lua b/entities/entities/ws_arrow/init.lua index e27dda9..db5adb6 100644 --- a/entities/entities/ws_arrow/init.lua +++ b/entities/entities/ws_arrow/init.lua @@ -13,9 +13,9 @@ function ENT:Initialize() self:SetCollisionGroup(COLLISION_GROUP_INTERACTIVE) self:PhysWake() self:SetUseType(SIMPLE_USE) - + util.SpriteTrail( self, 0, Ab, true, 1, 0, 1, 1, "sprites/smoke_trail.vmt" ) - + self:NextThink(CurTime()+10) end @@ -24,4 +24,8 @@ function ENT:Think() return true end - +function ENT:Use(activator, caller, usetype, value) + if caller:IsPigeon() then return end + caller:AddItem("Arrow",1) + self:Remove() +end -- cgit v1.2.3-70-g09d2 From 8e0e1e34108c1ba8909b186772596f8b1aae9f03 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 2 Jan 2016 23:29:30 -0500 Subject: Fixed up more bugs with the ai overhaul --- entities/entities/ws_arrow/init.lua | 8 ++++ entities/entities/ws_npc_ambient/init.lua | 57 ++++++++++++++++++----------- entities/entities/ws_npc_ambient/shared.lua | 1 - gamemode/npcsystem/npcs/bird.lua | 2 +- 4 files changed, 45 insertions(+), 23 deletions(-) (limited to 'entities') diff --git a/entities/entities/ws_arrow/init.lua b/entities/entities/ws_arrow/init.lua index db5adb6..d87924a 100644 --- a/entities/entities/ws_arrow/init.lua +++ b/entities/entities/ws_arrow/init.lua @@ -24,8 +24,16 @@ function ENT:Think() return true end +function ENT:PhysicsCollide(data, phys) + if phys:GetEntity():IsPlayer() or phys:GetEntity():IsNPC() then + print("We hit a player!") + else + end +end + function ENT:Use(activator, caller, usetype, value) if caller:IsPigeon() then return end + print("Trying to pick up an arrow!") caller:AddItem("Arrow",1) self:Remove() end diff --git a/entities/entities/ws_npc_ambient/init.lua b/entities/entities/ws_npc_ambient/init.lua index a0497dd..6df03a0 100644 --- a/entities/entities/ws_npc_ambient/init.lua +++ b/entities/entities/ws_npc_ambient/init.lua @@ -6,9 +6,15 @@ include('shared.lua') function ENT:Initialize() --print("NPC spawned!") + self:SetMoveType(MOVETYPE_STEP) + self:SetSolid(SOLID_OBB) + self:SetCollisionGroup(COLLISION_GROUP_INTERACTIVE) + if(self.Model) then self:SetModel(self.Model) else print("NPC created without model, this might be a bug!") end - if(self.Stats["Vitality"]) then self.Vitality = self.Stats["Vitality"] + if(self.Stats["Vitality"]) then + self:SetHealth(self.Stats["Vitality"]) + print("Helath set to " .. self.Stats["Vitality"]) else print("NPC created with no stat for vitality, this might be a bug!")end if(self.Stats["Accel"]) then self.loco:SetAcceleration(self.Stats["Accel"])end if(self.Stats["Decel"]) then self.loco:SetDeceleration(self.Stats["Decel"]) end @@ -30,27 +36,36 @@ end function ENT:OnInjured(dmg) --print("Taking some dammage") local itempos = self:GetPos() - self:SetHealth(self:Health() - dmg:GetDamage()) + print("Takeing " .. dmg:GetDamage() .. " health from our " .. self:Health()) + --self:SetHealth(self:Health() - dmg:GetDamage()) + print("Health is now" .. self:Health()) if self.OnDammage != nil then self:OnDammage(dmg) end - if self:Health() <= 0 then //run on death - if(CLIENT) then return end - if not self.Drops then return end - --print("Looks like we have some drops") +end + +function ENT:OnContact(ent) + if(ent:GetClass() == "ws_arrow") then + self:TakeDamage(30) + ent:SetParent(self) + end +end + +function ENT:OnKilled(dmg) + if(CLIENT) then return end + if not self.Drops then return end + --print("Looks like we have some drops") + for k,v in pairs(self.Drops) do 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 + local itemname = self.Drops[k][1] + local itemchance = self.Drops[k][2] + local heightoffset = 10 + if rng < itemchance then + local drop = ents.Create("ws_item") + drop.Item = GetItemByName(itemname) + drop:SetModel(drop.Item.Model) + drop:SetPos(self:GetPos() + (self:GetUp()*heightoffset)) + drop:Spawn() + heightoffset = heightoffset + 10 end - --self:SetSchedule( SCHED_FALL_TO_GROUND ) - end + end + self:BecomeRagdoll( dmg ) end diff --git a/entities/entities/ws_npc_ambient/shared.lua b/entities/entities/ws_npc_ambient/shared.lua index 7fa3661..c84245c 100644 --- a/entities/entities/ws_npc_ambient/shared.lua +++ b/entities/entities/ws_npc_ambient/shared.lua @@ -3,7 +3,6 @@ ENT.Base = "base_nextbot" //WS stuff ENT.Drops = nil ENT.OnDammage = nil -ENT.Vitality = 1 ENT.Speed = 0 ENT.Model = nil diff --git a/gamemode/npcsystem/npcs/bird.lua b/gamemode/npcsystem/npcs/bird.lua index 14eef6a..ff4c2f2 100644 --- a/gamemode/npcsystem/npcs/bird.lua +++ b/gamemode/npcsystem/npcs/bird.lua @@ -7,7 +7,7 @@ NPC.Icon = Material("wintersurvival2/hud/ws1_icons/icon_rock") NPC.Social = "Pack" --Solo, Pack NPC.Stats = { - ["Vitality"] = 100, + ["Vitality"] = 10, ["Speed"] = 400, ["AwareDist"] = 1000, ["Accel"] = 200, -- cgit v1.2.3-70-g09d2 From f462f49f123f094b1799ee269a67c533a436f56b Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 2 Jan 2016 23:30:50 -0500 Subject: More stuff added from the air overhaul --- entities/entities/ws_npc_ambient/init.lua | 6 +++--- gamemode/npcsystem/npcs/zombie.lua | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'entities') diff --git a/entities/entities/ws_npc_ambient/init.lua b/entities/entities/ws_npc_ambient/init.lua index 6df03a0..b896726 100644 --- a/entities/entities/ws_npc_ambient/init.lua +++ b/entities/entities/ws_npc_ambient/init.lua @@ -6,9 +6,9 @@ include('shared.lua') function ENT:Initialize() --print("NPC spawned!") - self:SetMoveType(MOVETYPE_STEP) - self:SetSolid(SOLID_OBB) - self:SetCollisionGroup(COLLISION_GROUP_INTERACTIVE) + --self:SetMoveType(MOVETYPE_STEP) + --self:SetSolid(SOLID_OBB) + --self:SetCollisionGroup(COLLISION_GROUP_INTERACTIVE) if(self.Model) then self:SetModel(self.Model) else print("NPC created without model, this might be a bug!") end diff --git a/gamemode/npcsystem/npcs/zombie.lua b/gamemode/npcsystem/npcs/zombie.lua index f07bd5a..422080a 100644 --- a/gamemode/npcsystem/npcs/zombie.lua +++ b/gamemode/npcsystem/npcs/zombie.lua @@ -7,7 +7,7 @@ NPC.Icon = Material("wintersurvival2/hud/ws1_icons/icon_rock") NPC.Social = "Solo" --Solo, Pack NPC.Stats = { - ["Vitality"] = 100, + ["Vitality"] = 200, ["Speed"] = 50, ["AwareDist"] = 1000, ["Accel"] = 100, -- cgit v1.2.3-70-g09d2 From 9f68b88436d7514df847486163433fb87e06f770 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sun, 3 Jan 2016 23:56:18 -0500 Subject: Adjustements to antlion pouncer --- entities/entities/ws_npc_ambient/init.lua | 3 ++- gamemode/npcsystem/aidirector.lua | 3 +++ gamemode/npcsystem/npcs/antlion1.lua | 2 +- gamemode/npcsystem/npcs/antlion2.lua | 18 ++++++++++++++---- 4 files changed, 20 insertions(+), 6 deletions(-) (limited to 'entities') diff --git a/entities/entities/ws_npc_ambient/init.lua b/entities/entities/ws_npc_ambient/init.lua index b896726..523333c 100644 --- a/entities/entities/ws_npc_ambient/init.lua +++ b/entities/entities/ws_npc_ambient/init.lua @@ -7,7 +7,7 @@ include('shared.lua') function ENT:Initialize() --print("NPC spawned!") --self:SetMoveType(MOVETYPE_STEP) - --self:SetSolid(SOLID_OBB) + self:SetSolid(SOLID_NONE) --self:SetCollisionGroup(COLLISION_GROUP_INTERACTIVE) if(self.Model) then self:SetModel(self.Model) @@ -19,6 +19,7 @@ function ENT:Initialize() if(self.Stats["Accel"]) then self.loco:SetAcceleration(self.Stats["Accel"])end if(self.Stats["Decel"]) then self.loco:SetDeceleration(self.Stats["Decel"]) end if(self.Stats["Step"]) then self.loco:SetJumpHeight(self.Stats["Step"]) end + if(self.OnSpawn) then self:OnSpawn() end --self:SetModel( "models/Humans/Group01/Female_01.mdl" ) --[[ self:SetHullType( HULL_HUMAN ); diff --git a/gamemode/npcsystem/aidirector.lua b/gamemode/npcsystem/aidirector.lua index f9f7203..04e645d 100644 --- a/gamemode/npcsystem/aidirector.lua +++ b/gamemode/npcsystem/aidirector.lua @@ -58,6 +58,9 @@ function SpawnNpcByName(name, position) if(entdata.AwareEnemies) then ent.AwareEnemies = entdata.AwareEnemies end + if(entdata.OnSpawn) then + ent.OnSpawn = entdata.OnSpawn + end ent:Spawn() end diff --git a/gamemode/npcsystem/npcs/antlion1.lua b/gamemode/npcsystem/npcs/antlion1.lua index 5c5ccab..1b0a38f 100644 --- a/gamemode/npcsystem/npcs/antlion1.lua +++ b/gamemode/npcsystem/npcs/antlion1.lua @@ -57,7 +57,7 @@ local checkrun = function(self, ply) return 0 end local dorun = function(self, ply) local navarea = navmesh.GetNavArea(self:GetPos(), 100) - self.loco:SetDesiredSpeed( 50 ) + self.loco:SetDesiredSpeed(self.Stats["Speed"] ) if navarea:IsValid() then local moveop = {} moveop.tolerance = 50 diff --git a/gamemode/npcsystem/npcs/antlion2.lua b/gamemode/npcsystem/npcs/antlion2.lua index c232b22..738bb7e 100644 --- a/gamemode/npcsystem/npcs/antlion2.lua +++ b/gamemode/npcsystem/npcs/antlion2.lua @@ -59,19 +59,24 @@ local checkpounce = function(self, ply) end local dopounce = function(self,ply) - self:StartActivity(ACT_MELEE_ATTACK2) - coroutine.wait(0.5) + local randanim = math.Round(math.Rand(0,1)) + if(randanim) then + self:SetSequence("pounce") + else + self:SetSequence("pounce2") + end + coroutine.wait(0.23) if(ply:GetPos():Distance(self:GetPos()) < 200) then ply:TakeDamage(15) end - coroutine.wait(0.25) + coroutine.wait(0.15) end local checkrun = function(self, ply) return 0 end local dorun = function(self, ply) local navarea = navmesh.GetNavArea(self:GetPos(), 100) - self.loco:SetDesiredSpeed( 50 ) + self.loco:SetDesiredSpeed(self.Stats["Speed"]) if navarea:IsValid() then local moveop = {} moveop.tolerance = 50 @@ -129,6 +134,11 @@ function NPC:Stuck() 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() + self:SetSkin(2) +end + /* function NPC:OnSpawn() end -- cgit v1.2.3-70-g09d2 From 5f9616bc0d398721e1e459cd836c89906b6e4fd1 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sun, 3 Jan 2016 23:57:57 -0500 Subject: Simple change to arrow --- entities/entities/ws_arrow/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'entities') diff --git a/entities/entities/ws_arrow/init.lua b/entities/entities/ws_arrow/init.lua index d87924a..63bfa6e 100644 --- a/entities/entities/ws_arrow/init.lua +++ b/entities/entities/ws_arrow/init.lua @@ -26,7 +26,7 @@ end function ENT:PhysicsCollide(data, phys) if phys:GetEntity():IsPlayer() or phys:GetEntity():IsNPC() then - print("We hit a player!") + print("We hit something!") else end end -- cgit v1.2.3-70-g09d2