SNPC Schedules

So i’m trying to make my SNPC chase a player then stop when they get nearby and begin to shoot them.

My current SNPCs are able to locate and run to the player, but when they are supposed to shoot they just sit there and play the animation. I’ve tried a shitload of things and none of them seem to work.

I prefer to use the default engine stuff because the Lua tasks seem much less functional (was it Avon who posted that thread showing the differences between scripted and engine tasks?).

Here’s what i have currently:

[lua]function ENT:SelectSchedule()

local enemy = self.Entity:GetEnemy()
local sched = SCHED_IDLE_WANDER 

if enemy and enemy:IsValid() then

	if self.Entity:HasCondition( 21 ) then // COND_CAN_RANGE_ATTACK1
		sched = SCHED_RANGE_ATTACK1		
	else
		sched = SCHED_CHASE_ENEMY
	end
	
else

	self.Entity:UpdateEnemy( self.Entity:FindEnemy() )
	
end

self.Entity:SetSchedule( sched ) 

end
[/lua]

I tried using StartSchedule instead of using SCHED_RANGE_ATTACK1 and it also didn’t work:

[lua]local shooter = ai_schedule.New( “AIFighter Chase” )
shooter:EngTask( “TASK_GET_PATH_TO_RANGE_ENEMY_LKP_LOS”, 0 )
shooter:EngTask( “TASK_RUN_PATH”, 0 )
shooter:EngTask( “TASK_WAIT_FOR_MOVEMENT”, 0 )

// Shoot it
shooter:EngTask( “TASK_STOP_MOVING”, 0 )
shooter:EngTask( “TASK_FACE_ENEMY”, 0 )
shooter:EngTask( “TASK_ANNOUNCE_ATTACK”, 0 )
shooter:EngTask( “TASK_RANGE_ATTACK1”, 0 )[/lua]

You need to manually shoot the bullets I think.

Have there been SNPCs previously made that could fire bullets with no hassle?

Give them a weapon to fire?

i’ve given them all sorts of weapons.

weapon_pistol shows a muzzleflash but doesn’t shoot
any SWEP just doesn’t do anything.

i’ve been told i have to manually get the weapon ent and call PrimaryFire from the NPC. That’s horrible.

can you show me the code where you give it the weapon?

[lua]ENT.StartHealth = 100
ENT.StartWeapon = “weapon_pistol”
ENT.Model = “models/Humans/Group01/Male_02.mdl”

function ENT:Initialize()

self.Entity:SetModel( self.Model )

self.Entity:SetHullSizeNormal()
self.Entity:SetHullType( HULL_HUMAN )

self.Entity:SetSolid( SOLID_BBOX ) 
self.Entity:SetMoveType( MOVETYPE_STEP )
self.Entity:CapabilitiesAdd( CAP_MOVE_GROUND | CAP_TURN_HEAD | CAP_USE_WEAPONS | CAP_AIM_GUN | CAP_WEAPON_RANGE_ATTACK1 | CAP_MOVE_SHOOT ) 

self.Entity:SetMaxYawSpeed( 5000 )
self.Entity:SetHealth( 100 )
self.Entity:Give( self.StartWeapon )

self.Entity:DropToFloor()

self.Entity:UpdateEnemy( self.Entity:FindEnemy() )

end[/lua]

change [lua]ENT.StartWeapon = “weapon_pistol”[/lua]
to: [lua]ENT.StartWeapon = “ai_weapon_pistol”[/lua]

Okay so it was a little hacky, but my method worked. It’s also very customizable so i’m happy.

I’ve been calling the weapon’s PrimaryFire from the NPC’s think function when it’s in range of a player. I had to jack the shit out of the bullet spread though because the NPCs have hax aim.

I made a separate weapon base for the NPCs with customizable reload times, etc. But i can’t get them to do the reload animation or have muzzle flashes, oh well.

that gamemode looks awesome :slight_smile:

THAT’s what’s needed, better AI stuff. goes to post on that silly site

That gamemode looks interesting.Would you be so kind as to release the snpc on its own?It would be fun having a guy chase you around,then stop to shoot you.Would be much nicer that the shitto metropolice or some remodeled soldier with a citizen or rebel model,while making sounds like some sort of robotcyborgmutantalien thing.

The problem is that they need custom tailored SWEPs since you’re calling the PrimaryFire manually from the SNPC. SetNextPrimaryFire doesn’t seem to work when the SNPCs use weapons so they fire every weapon with no delay between shots.

Will this work? NPC.SetEnemy

Uh my SNPCs have been using that since day 1. It doesn’t have anything to do with them firing the weapon. You’d either use SetSchedule or use a scripted schedule to make them fire the weapon.

Description on the wiki page is a little misleading.

EDIT: http://wiki.garrysmod.com/?title=NPC.AddEntityRelationship
If you’re just going to use with it player/NPCs, this should work.

He needed help on firing the weapon, NOT RELATIONSHIPS.
Get that into yer 'ead

You aren’t helping at all.

You aren’t helping either. At least I’m attempting to find a way to do it, rather than making a blind assumption, as I’ve gotten NPCs to shoot at other NPCs and Players, just never attempted to get them to shoot at Props. :stuck_out_tongue:

I assumed it was about shooting at NPCs, my bad.