diff options
Diffstat (limited to 'entities')
| -rw-r--r-- | entities/entities/ws_arrow/init.lua | 16 | ||||
| -rw-r--r-- | entities/entities/ws_npc_ambient/init.lua | 61 | ||||
| -rw-r--r-- | entities/entities/ws_npc_ambient/shared.lua | 76 |
3 files changed, 129 insertions, 24 deletions
diff --git a/entities/entities/ws_arrow/init.lua b/entities/entities/ws_arrow/init.lua index e27dda9..63bfa6e 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,16 @@ function ENT:Think() return true
end
+function ENT:PhysicsCollide(data, phys)
+ if phys:GetEntity():IsPlayer() or phys:GetEntity():IsNPC() then
+ print("We hit something!")
+ 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 485b6c9..523333c 100644 --- a/entities/entities/ws_npc_ambient/init.lua +++ b/entities/entities/ws_npc_ambient/init.lua @@ -6,8 +6,20 @@ include('shared.lua') function ENT:Initialize()
--print("NPC spawned!")
+ --self:SetMoveType(MOVETYPE_STEP)
+ self:SetSolid(SOLID_NONE)
+ --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: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
+ 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 );
@@ -25,27 +37,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 ba65e2b..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
@@ -17,6 +16,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 +101,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
|
