NPC behavior?

Skull Kingz

Active member
Is there a way to change the behavior on your NPC character? It seems as if they only act one way. They constantly walk back and forth as if they know an enemy is gonna be spawned.
Any suggestions?
 
Also 'subtype follow' makes them follow you, add range to idle anim to control it.

Code:
follow: For npcs. Will cause an npc to attempt to follow the entity that spawned or summoned it (see below). 
Uses range setting in *idle* animation to determine how close it will follow. 
If the npc exceeds the minimum range and no entities it is hostile towards are nearby, 
it will move to the spawning entity normally. If it exceeds maximum range, 
the npc will instantly warp to the spawning entity regardless of what it is currently doing and play it’s respawn
animation if it has one. An npc without this subtype will behave exactly like an enemy with the chase subtype. 
It can potentially follow a hostile across the entire level, and will wander randomly if no hostiles are available.
 
I wrote that, and it could probably use a bit of cleanup. See here (assuming NPC with follow subtype):

  • General: NPC behaves like an enemy with chase subtype and follows the same rules for fighting and moving about (i.e. walk, back walk, jumping, running, attacks, etc.). Set the NPC up carefully with aggression, attack ranges, jumping ranges and such if you want it to be an able companion.
  • Hostiles: As above, by default the NPC behaves as a chase subtype enemy, meaning it will immediately engage the nearest hostile entity using whatever movements and attacks it has available. By default NPCs are hostile to enemy types.
  • No Hostiles: Depending on range settings in its IDLE animation, NPCs will attempt to follow spawning entity with any normal movement ability at its disposal.
    • If the current parent (by default whatever entity that spawned it) is within MINIMUM range and no hostiles are around, NPC will WALK toward parent.
    • If it is between MINIMUM and MAXIMUM range and no hostiles are nearby the NPC will RUN toward parent if it can.
    • If for any reason the NPC gets outside of MAXIMUM range, it will warp to parent instantly regardless of what it was previously doing and play RESPAWN if available.

What this means is that you will usually want to set the range where MINIMUM is around half screen and MAXIMUM is about full screen. Then create a RESPAWN that makes sense (jumping back to parent, teleport smoke, whatever). If you don't feel like doing the latter, make sure to give the NPC a run animation so it can keep up when its parent moves quickly and use a very long MAXIMUM range.

Once again, remember that aside from their default hostility settings and not counting toward level spawns, NPCs are essentially enemy types. They use the same basic AI behavior and are not bound to screen edges by default. Keep those things in mind when creating NPCs, and you'll be golden.

DC
 
Minor update; items.

NPCs can and will collect items, but only if they have a reason to, and obviously only if the item is assessable (NPCs are not hostile to obstacles and so won't bust open containers themselves). An NPC won't take a weapon it can't use, and won't pick up food/health items when it's at full HP.

Hint: By making an NPC hostile to obstacles and always at 1 point under max health, then scripting collected items to take effect on the parent instead, you could create a nifty little in game fetching tool.

DC
 
Now he wont go offscreen but he will be standing on the screen border like moron trying to fight enemies that are offscreen if his ai is set to chase enemies ;D
 
I dont think so, it should be fixed in source code, i remember bringing that up in 2010 when making fightin spirit mod, i ended up adding code to walking animation of npcs to check if theyre offscreen and they would perform dash attack to get back into playable area from offscreen and i removed subject_to_screen from header.They perform dash attack everytime theyre offscreen but its better than standing there wanting to attack invisible enemies like retard.NPC's should ignore all enemies from offscreen and return to player if theres no enemies in playable area.
 
but he will be standing on the screen border like moron trying to fight enemies that are offscreen if his ai is set to chase enemies

Then, what about adding script in enemy's text so they move onscreen if they got offscreen too far?
That would solve the problem more cause it helps player too :)
 
try this
Code:
offscreen_noatk_factor {bi}

~This command determines the ability of an entity to be able to attack while off screen. Useful to prevent entities that use ranged attacks like shots for example, they can attack without being in the visible area.
0 Means that the entity can attack outside the visible area (default)
1 Means that the entity CAN NOT attack outside the visible area.
 
I didn't actully update anything recently; my posts above were just better documentation of how NPCs work.

Anyway, I think the best solution would be to look into a perception range setting for AI entities. This would control how far they can "see". It would default to limitless for enemies so they don't get stuck out of the player's reach, and be much shorter for NPCs so they don't go gallivanting to the other end of the world. An additional flag to make them blind to anything that goes out of screen edge regardless of distance should solve the border humping problem.

DC
 
They perform dash attack everytime theyre offscreen but its better than standing there wanting to attack invisible enemies like retard

hahahahahahaha. Yeah, that was my idea too, to make it dash when it get out of screen. Mind to share the code?

Then, what about adding script in enemy's text so they move onscreen if they got offscreen too far?  That would solve the problem more cause it helps player too
NPC would still chase it and try to attack it. And I want the enemies to attack while they are offscreen.

offscreen_noatk_factor
This would make the NPC stop to attack when its outside of the screen, so it will be an easy target.

So, I think I have two options:
- force NPC to dash back to the screen area.
- offscreen_noatk_factor in both enemies (not bosses) and NPC.



 
yeah problem is not attacking, its walking outside and detecting enemies outside , im not sure, maybe if subject to screen and offscreen_noatk_factor would be enabled then npcs would completely ignore enemies offscreen.

@script
                void self = getlocalvar("self");
                int  pos  = openborvariant("xpos");
                int  selfx    = getentityproperty(self, "x");
                if ((selfx > pos + 480 )&&(frame == 0)){
                changeentityproperty(self, "direction", 0);
                performattack(self, openborconstant("ANI_FREESPECIAL3"));
}
if ((selfx < pos + 1 )&&(frame == 0)){
                changeentityproperty(self, "direction", 1);
                performattack(self, openborconstant("ANI_FREESPECIAL3"));
}
@end_script
Heres the code but sometimes they perform dash attack a couple of times one after another, its for 480x272 mod
 
Back
Top Bottom