• Help with npc_bullseye activation.
    3 replies, posted
So I have figured out that whenever I spawn someone who attacks my NPC first, they will shoot, but if I spawn my NPC first, then the attacker, they will not attack. My code makes it so that when my NPC is initialized it activates my npc_bullseye, however, shouldn't this last forever, instead of just being for when it is called after creation of enemies? function ENT:Initialize() -- Called when the entity is spawned, sets parameters     local ent = ( ents.FindByClass("recruitables") )     self:SetModel(modelselect[math.random(1, #modelselect)])     self:SetHealth(100)     self:SetUseType(SIMPLE_USE)     self.loco:SetStepHeight(33)     self.loco:SetJumpHeight(58)     self:AddFlags(FL_CLIENT, FL_NPC, FL_AIMTARGET)     self:SetCollisionBounds( Vector(-10,-10,-10), Vector(10,10,70) )     self.LoseTargetDist = 600  -- How far the enemy has to be before we lose them     self.SearchRadius   = 400  -- How far to search for enemies     self.TargetRadius = 500     self.LoseTarget = 700     self.RecruiterDistance = 100000     self.RecruiterRadius = 100000     self.Recruited = false     self.OnCoolDown = false     self.NoRecruiter = false     self.Spawner = self:GetCreator()     self.Shooting = false     self.Talking = false     self.CanFire = false     self.Healing = false     target = ents.Create("npc_bullseye")         target:SetParent(self)         target:SetPos(self:GetPos()+Vector(0,0,20))         target:Spawn()         target:SetHealth(9999999)         target:Activate()         target:SetKeyValue( "health","9999" )           target:SetKeyValue( "spawnflags","256" )          target:SetNotSolid( true )         -- This is where we find our enemies and list them, if they are listed, they will attack. (IK its inefficient...)         for k,v in pairs(ents.FindByClass("npc_*")) do              if ( string.find(v:GetClass(), "npc_antlionguard")) or                  ( string.find(v:GetClass(), "npc_combine*")) or                  ( string.find(v:GetClass(), "*zombie*")) or                  ( string.find(v:GetClass(), "npc_helicopter")) or                  ( string.find(v:GetClass(), "npc_manhack")) or                  ( string.find(v:GetClass(), "npc_metropolice")) or                  ( string.find(v:GetClass(), "npc_rollermine")) or                  ( string.find(v:GetClass(), "npc_strider")) or                  ( string.find(v:GetClass(), "npc_turret*")) or                  ( string.find(v:GetClass(), "npc_hunter")) or                 ( string.find(v:GetClass(), "npc_combine_s")) or                 ( string.find(v:GetClass(), "antlion")) then                 v:AddEntityRelationship( target, D_HT, 15 )             end         end     local gun = table.Random(self:GetGuns())         if type(gun) == "table" then             gun = gun[1]         end     self:GiveWeapon(gun)     if self.WeaponData[gun] then         self.Weapon.NPCShoot_Primary = nil     end end Another small side note, if anyone knows how to get the damage info for someone, specifically the GetAttacker() that would be great because I want to set the enemy for this NPC to whoever attacks his recruiter. Anyway, thank you in advance for any help!
While putting this in a think function, I tested it, and it crashes my game when someone shoots at him and this error is thrown: CUtIRBTree overflow
Well you only set the relationship to existing entities when you spawn the NPC. You need to use GM/OnEntityCreated aswell to add a new relationship whenever a new entity is made. Check for the class in that hook and if it matches, make a relationship with all npcs you want. (might need to use a short simple timer delay in that hook for the entity to initialize properly)
How can I call this if it is a gamemode function but I need it in my entity?
Sorry, you need to Log In to post a reply to this thread.