NPC Attack Prop

I’ve been searching for a way to get NPC’s to attack props and this is all I could come up with.



BZ_SpawnedNPC:Fire( "setrelationship", "prop_physics D_HT 999" )


But they ignore props…

Any Ideas??

EDIT:

To make sure this function was doing anything I tried



BZ_SpawnedNPC:Fire( "setrelationship", "npc_zombie D_HT 999" )


And they attacked themselves, so I’m not sure whats up, any help in the right direction would be amazing! :slight_smile:

BUMP:

Any help would be greatly appreciated :slight_smile:

I was able to stick an ‘npc_bullseye’ on top of every prop as it’s spawned and have npc’s hate ‘npc_bullseye’ but they don’t go for it if the bullseye isn’t in line of sight…

There must be a way to make them go directly for prop_physics??

You have to do a custom check for “prop_physics”. I only worked with SNPC’s for a bit but I don’t think that you can navigate an npc to a prop. I may be mistaken but I had to do custom checks for the props in order to have the NPC attack it.

Any advice as to how I can force the NPC to move to a location? I’ve been trying all sorts of different functions to no avail…

npc:SetLastPosition( Pos );
npc:SetSchedule( SCHED_FORCED_GO ) All Schedules like “SCHED_FORCED_GO_RUN”, “SCHED_COWER” … ect

I would recommend waiting for the nextbot stuff that garry is working on, if not, read on:

I was able to do this with lua (lol), my way is very dodgy though, as you’re not meant to do it.

[lua]-- Remove our enemy:
v:SetEnemy()
v.Enemy = nil

– Walk to position:
v:SetLastPosition(pos)
v:NavSetGoal(pos)
v:SetSchedule(SCHED_FORCED_GO)[/lua]

Where V is the npc.

As for attacking a prop:

[lua]local seq = self:LookupSequence(“attackA”)
self:ResetSequence(seq)[/lua]

That will play the attack animation (there is also B and C attack types, possibly others),then, you want to set a timer depending on the animation, so when the swing is roughly where it should be to hit, you check the distance to the prop (since it’s a prop, it wont move, so you probably wouldnt have to check the distance), then just apply the damage via lua.

[lua]function ENT:DoAnAttack()
local seq = self:LookupSequence(“attackA”)
self:ResetSequence(seq)
self.attacking = true
self.started = CurTime()
self.AttackEnd = CurTime() + self:SequenceDuration()
self:SetNPCState(NPC_STATE_SCRIPT)
end

function ENT:Think()
if self.attacking then
if not self.attacked then
if CurTime() + 27 / 33 >= self.started then
– do the damage here
self.attacked = true
end
end

    if( CurTime() < self.AttackEnd ) then return end

   -- Complete the task:
self:TaskComplete()
self:SetNPCState( NPC_STATE_NONE )

    self.attacking = false
    self.attacked = false
end

end[/lua]

That code is mostly from the top of my head, but should give a VERY BASIC idea on how to do it, again, better off waiting for nextbot, that’s why i didn’t put that much detail into it.

Thank you very much, I’ll put the basics in and wait for Next Bot :slight_smile: It seems like controlling the AI is kind of rough at the moment.

maybe something like?

NPC.Navigate (prop:GetPos()) ??

[editline]6th September 2013[/editline]

no this post is before nextbot?