Make NPC targeting actually work
This commit is contained in:
parent
278a0a9d7d
commit
786e997351
3 changed files with 115 additions and 27 deletions
96
lua/entities/npc_ragdoll_target.lua
Normal file
96
lua/entities/npc_ragdoll_target.lua
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
AddCSLuaFile()
|
||||||
|
|
||||||
|
ENT.Type = "ai"
|
||||||
|
ENT.Base = "base_ai"
|
||||||
|
ENT.AutomaticFrameAdvance = true
|
||||||
|
|
||||||
|
local debug_show_ragdoll_targets = CreateConVar("zcnpci_debug_show_ragdoll_targets", 0, bit.bor(FCVAR_ARCHIVE, FCVAR_REPLICATED))
|
||||||
|
|
||||||
|
local function UpdateRelationship(ent, me)
|
||||||
|
if !IsValid(ent) or !ent:IsNPC() then return end
|
||||||
|
|
||||||
|
if ent:Disposition(me.dummy_entity) == D_HT then
|
||||||
|
ent:AddEntityRelationship(me, D_HT)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function RemoveRelationship(ent, me)
|
||||||
|
if !IsValid(ent) or !ent:IsNPC() then return end
|
||||||
|
|
||||||
|
if ent:Disposition(me.dummy_entity) == D_HT then
|
||||||
|
ent:AddEntityRelationship(me, D_NU)
|
||||||
|
ent:ClearEnemyMemory(me)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function ENT:Initialize()
|
||||||
|
if SERVER then
|
||||||
|
self:SetModel("models/maxofs2d/hover_basic.mdl")
|
||||||
|
self:SetCollisionGroup(COLLISION_GROUP_DEBRIS)
|
||||||
|
self:SetHullType(HULL_TINY_CENTERED)
|
||||||
|
self:SetNoDraw(!debug_show_ragdoll_targets:GetBool())
|
||||||
|
self.dummy_entity = ents.Create(self.ragdoll_to_follow.class_in_previous_life)
|
||||||
|
self.last_stop_targeting = debug_show_ragdoll_targets:GetBool()
|
||||||
|
|
||||||
|
hook.Add("OnEntityCreated", "zcnpci-"..self:GetCreationID(), function(new_entity)
|
||||||
|
if !IsValid(new_entity) or !new_entity:IsNPC() then return end
|
||||||
|
|
||||||
|
if !self.last_stop_targeting then
|
||||||
|
UpdateRelationship(new_entity, self)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
for i,ent in ipairs(ents.GetAll()) do
|
||||||
|
UpdateRelationship(ent, self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function ENT:Think()
|
||||||
|
if SERVER then
|
||||||
|
local ragdoll = self.ragdoll_to_follow
|
||||||
|
if !IsValid(ragdoll) then return end
|
||||||
|
|
||||||
|
self:SetPos(ragdoll:GetPos())
|
||||||
|
|
||||||
|
self:SetNoDraw(!debug_show_ragdoll_targets:GetBool())
|
||||||
|
|
||||||
|
if !ragdoll.organism then return true end
|
||||||
|
|
||||||
|
local should_stop_targeting = (
|
||||||
|
(ragdoll.organism.consciousness <= 0.4) or
|
||||||
|
(ragdoll.organism.critical)
|
||||||
|
)
|
||||||
|
|
||||||
|
if should_stop_targeting != self.last_stop_targeting then
|
||||||
|
self.last_stop_targeting = should_stop_targeting
|
||||||
|
|
||||||
|
if should_stop_targeting then
|
||||||
|
self:SetColor(Color(255, 0, 0))
|
||||||
|
for i,ent in ipairs(ents.GetAll()) do
|
||||||
|
RemoveRelationship(ent, self)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
self:SetColor(Color(0, 255, 0))
|
||||||
|
for i,ent in ipairs(ents.GetAll()) do
|
||||||
|
UpdateRelationship(ent, self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
self:NextThink(CurTime())
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function ENT:OnRemove()
|
||||||
|
if SERVER then
|
||||||
|
print("I AM DYING!!!!!!")
|
||||||
|
for i,ent in ipairs(ents.GetAll()) do
|
||||||
|
RemoveRelationship(ent, self)
|
||||||
|
end
|
||||||
|
hook.Remove("OnEntityCreated", "zcnpci-"..self:GetCreationID())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -142,25 +142,38 @@ end)
|
||||||
hook.Add("EntityTakeDamage", "zcnpci", function(ent, dmginfo)
|
hook.Add("EntityTakeDamage", "zcnpci", function(ent, dmginfo)
|
||||||
if !IsValid(ent) or !IsValid(dmginfo) then return end
|
if !IsValid(ent) or !IsValid(dmginfo) then return end
|
||||||
|
|
||||||
if ent:GetClass() == "npc_bullseye" then
|
print('damage taken')
|
||||||
|
|
||||||
|
if ent:GetClass() == "bullseye_strider_focus" then
|
||||||
|
print("BULLSEYE!")
|
||||||
local npc_rag = IsValid(ent.npc_rag) and ent.npc_rag
|
local npc_rag = IsValid(ent.npc_rag) and ent.npc_rag
|
||||||
|
|
||||||
if IsValid(npc_rag) then
|
if IsValid(npc_rag) then
|
||||||
npc_rag:TakeDamageInfo(dmgInfo)
|
if !IsValid(dmginfo) then
|
||||||
|
print("FUUUUCK NO DMGINFO")
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
print("DAMAGE MOVED")
|
||||||
|
|
||||||
|
--ent.npc_rag:TakeDamageInfo(dmginfo)
|
||||||
|
|
||||||
|
--hook.Run("HomigradDamage", , dmginfo)
|
||||||
end
|
end
|
||||||
|
|
||||||
return
|
return true
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
hook.Add("HomigradDamage", "zcnpci", function(ent, dmginfo)
|
hook.Add("HomigradDamage", "zcnpci", function(ent, dmginfo)
|
||||||
if !enabled:GetBool() or !IsValid(dmginfo) then return end
|
if !enabled:GetBool() or !IsValid(dmginfo) then return end
|
||||||
|
|
||||||
if !ent:IsNPC() then
|
if !ent:IsNPC() then
|
||||||
if !ent.organism or !ent.StartDie then return end
|
if !ent.organism or !ent.StartDie then return end
|
||||||
|
|
||||||
if dmginfo:IsDamageType(DMG_BULLET + DMG_BUCKSHOT + DMG_BLAST + DMG_CLUB + DMG_SLASH + DMG_GENERIC) then
|
if dmginfo:IsDamageType(DMG_BULLET + DMG_BUCKSHOT + DMG_BLAST + DMG_CLUB + DMG_SLASH + DMG_GENERIC) then
|
||||||
-- Reset ragdoll get up timer -- don't want someone getting up mid-curbstomp
|
-- Reset ragdoll get up timer -- don't want someone getting up mid-curbstomp
|
||||||
ent.StartDie = CurTime()
|
ent.StartDie = CurTime()
|
||||||
|
print("I'M HIT FOR "..dmginfo:GetDamage())
|
||||||
end
|
end
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -196,27 +196,11 @@ function MODULE:Init()
|
||||||
self.LastThink = CurTime()
|
self.LastThink = CurTime()
|
||||||
self.LastFakeUpCheck = CurTime()
|
self.LastFakeUpCheck = CurTime()
|
||||||
|
|
||||||
self.bullseye = ents.Create("npc_bullseye")
|
self.bullseye = ents.Create("npc_ragdoll_target")
|
||||||
self.bullseye:SetPos(target:GetPos())
|
self.bullseye:SetPos(target:GetPos())
|
||||||
self.bullseye:SetMoveType(MOVETYPE_OBSERVER)
|
self.bullseye.ragdoll_to_follow = target
|
||||||
self.bullseye:SetModel("models/editor/bullseye.mdl")
|
|
||||||
self.bullseye:SetHealth(99999)
|
|
||||||
self.bullseye:Spawn()
|
self.bullseye:Spawn()
|
||||||
self.bullseye:Activate()
|
self.bullseye:Activate()
|
||||||
self.bullseye:SetNotSolid(true)
|
|
||||||
self.bullseye.npc_rag = target
|
|
||||||
|
|
||||||
self.dummy_entity = ents.Create(target.class_in_previous_life)
|
|
||||||
|
|
||||||
for i,ent in ipairs(ents.GetAll()) do
|
|
||||||
if !IsValid(ent) or !ent.IsNPC() then continue end
|
|
||||||
|
|
||||||
if ent:Disposition(self.dummy_entity) == D_HT then
|
|
||||||
ent:AddEntityRelationship(self.bullseye, D_HT, -1)
|
|
||||||
|
|
||||||
print("HATE. HATE. HATE")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Add damping to all bones.
|
-- Add damping to all bones.
|
||||||
local phys = self:GetPhysicsObject()
|
local phys = self:GetPhysicsObject()
|
||||||
|
|
@ -241,8 +225,6 @@ end
|
||||||
|
|
||||||
function MODULE:Think()
|
function MODULE:Think()
|
||||||
--if (CurTime() - self.LastThink) < 1 then return end
|
--if (CurTime() - self.LastThink) < 1 then return end
|
||||||
print("thinking")
|
|
||||||
|
|
||||||
local target = self:GetTarget()
|
local target = self:GetTarget()
|
||||||
if !IsValid(target) then return end
|
if !IsValid(target) then return end
|
||||||
|
|
||||||
|
|
@ -309,7 +291,6 @@ function MODULE:PhysicsSimulate(phys, dt)
|
||||||
if not IsValid(target) then self:Remove(); self.bullseye:Remove(); return false end
|
if not IsValid(target) then self:Remove(); self.bullseye:Remove(); return false end
|
||||||
|
|
||||||
if target.FakeUp then
|
if target.FakeUp then
|
||||||
print("fucking it")
|
|
||||||
local parent = self.FakeParent
|
local parent = self.FakeParent
|
||||||
|
|
||||||
if !IsValid(parent) then
|
if !IsValid(parent) then
|
||||||
|
|
@ -380,8 +361,6 @@ function MODULE:PhysicsSimulate(phys, dt)
|
||||||
|
|
||||||
phys:Wake()
|
phys:Wake()
|
||||||
|
|
||||||
|
|
||||||
self.bullseye:SetPos(target:GetPos())
|
|
||||||
--self.bullseye:SetAngles(target:EyeAngles())
|
--self.bullseye:SetAngles(target:EyeAngles())
|
||||||
|
|
||||||
target.is_npc_corpse = true
|
target.is_npc_corpse = true
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue