diff --git a/lua/entities/npc_ragdoll_target.lua b/lua/entities/npc_ragdoll_target.lua new file mode 100644 index 0000000..cd52d4e --- /dev/null +++ b/lua/entities/npc_ragdoll_target.lua @@ -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 \ No newline at end of file diff --git a/lua/zcnpci.lua b/lua/zcnpci.lua index 3213fb8..6194e3e 100644 --- a/lua/zcnpci.lua +++ b/lua/zcnpci.lua @@ -142,25 +142,38 @@ end) hook.Add("EntityTakeDamage", "zcnpci", function(ent, dmginfo) 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 - + 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 - return + return true end end) hook.Add("HomigradDamage", "zcnpci", function(ent, dmginfo) if !enabled:GetBool() or !IsValid(dmginfo) then return end + if !ent:IsNPC() then 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 -- Reset ragdoll get up timer -- don't want someone getting up mid-curbstomp ent.StartDie = CurTime() + print("I'M HIT FOR "..dmginfo:GetDamage()) end return diff --git a/lua/zcnpci/modules/falling_legs.lua b/lua/zcnpci/modules/falling_legs.lua index 6a097ad..8d14918 100644 --- a/lua/zcnpci/modules/falling_legs.lua +++ b/lua/zcnpci/modules/falling_legs.lua @@ -196,27 +196,11 @@ function MODULE:Init() self.LastThink = CurTime() self.LastFakeUpCheck = CurTime() - self.bullseye = ents.Create("npc_bullseye") + self.bullseye = ents.Create("npc_ragdoll_target") self.bullseye:SetPos(target:GetPos()) - self.bullseye:SetMoveType(MOVETYPE_OBSERVER) - self.bullseye:SetModel("models/editor/bullseye.mdl") - self.bullseye:SetHealth(99999) + self.bullseye.ragdoll_to_follow = target self.bullseye:Spawn() 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. local phys = self:GetPhysicsObject() @@ -241,8 +225,6 @@ end function MODULE:Think() --if (CurTime() - self.LastThink) < 1 then return end - print("thinking") - local target = self:GetTarget() 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 target.FakeUp then - print("fucking it") local parent = self.FakeParent if !IsValid(parent) then @@ -380,8 +361,6 @@ function MODULE:PhysicsSimulate(phys, dt) phys:Wake() - - self.bullseye:SetPos(target:GetPos()) --self.bullseye:SetAngles(target:EyeAngles()) target.is_npc_corpse = true