Jump to content

[Discussion]NPC Design

Recommended Posts

So we've recently been talking a little bit about NPC design in the Discord, so I thought I'd make a discussion thread about it so we can have a place to keep the ideas around.  There should be a couple of things to keep in mind regarding NPC behavior and purposes that I want to talk about first, especially in regards to their goals and purpose in the game.  Most of this deals with Phase 2 and later design, so just assume we're talking about that phase here, since NPCs will have little to no use in Phase 1 (as of right now).  I'm going to discuss some of my thoughts on the design, but want to hear feedback from other players/developers.

NPC Purposes in JKG

I think its helpful to review NPCs from a gameplay design aspect.  Why are NPCs in JKG?

  • To serve as facilitators of items.  Some NPCs produce items and you can trade with them to acquire new items.  eg: A shop vendor can sell you a new e-11.
  • To serve as facilitators of skills/abilities.  Some NPCs can help players unlock new skills/abilities.  eg: An npc craftsman can help a player unlock the craft items skill so the player can then craft items.
  • To serve as distributors of quests/missions.  Some NPCs can help players learn about new things and give them things to do, they can also help move the story along.  eg: A caravan guard on Tatooine might ask you for help when they get stranded by a Krayt Dragon attack.
  • To serve as obstacles and antagonists, that make quests/missions more challenging and interesting.
  • To serve as helpers or allies, that make quests/missions easier, interesting, or even more challenging.
  • To help fill the void of a server with the semblance of life and add to the game's atmosphere when other player's are not around.


Given these primary reasons, it makes sense that we should probably optimize/design NPCs around these goals.  Not all NPCs are equal, and its fine to disable certain features with some NPCs to optimize.  For example, shop vendors probably do not need to serve as obstacles or antagonists so they shouldn't have the overhead of trying to figure out how to kill a player like a stormtrooper might.  Some NPCs should probably have scripted actions and not need to do anything other than follow a script.  Others should be more dynamic and self determining.  All NPCs should have a couple of different universal ways they might interact with a player:

  • +use on an NPC will open up a dialog with the NPC as long as the NPC is not currently hostile to the player, or is not a vendor that the player has interacted with previously.  There should probably be a check that goes something like:
    if(npc.attitude == HOSTILE)//doesn't like player, won't talk to them
    if(npc.quest.dialogflag == -1) //dialogflag: -1=talked to, no more interactions, 0=never talked to, 1=dialog available, 2=quest/special interactions, etc.
      //do default npc action here, such as a vendor opening his shop
    //other npc reactions below

    Otherwise, the NPC would open up a dialogue with the player and the player can choose how to respond.  All NPCs should have an escape dialogue choice available.  This will usually be the last listed and would be something like, "Goodbye" or "[Leave]".  This can always be called by pressing "ESC" to close out a dialog with an NPCNPC dialogs should be designed so that the player can leave the conversation at any moment and pick it up later (in case of a client disconnect or player backing out, whatever).  Other dialog choices would be based on the NPC itself.  For example when talking to a vendor for the first time, they might introduce themselves and tell you that they can sell you stuff, and one dialog option would be to look at their wares.  Most vendors, should probably only do this interaction once with each player, and then set their dialogflag to -1 (meaning that if you talk to them in the future it just skips straight to the shop screen).  Quest NPCs would have additional dialog choices available while the quest is available, for example a stormtrooper might give you an option to ask him about how he became a stormtrooper, which would lead into a imperial recruiting quest.

  • Attacking an NPC will probably be a little complex, but here's some basic ideas.  First, make sure the NPC is actually attackable and if not, don't bother doing anything.  For example, you shouldn't be able to kill or harm certain NPCs during certain points in the game.  In general though, assuming the NPC is a valid target and currently friendly toward the player the following steps should probably happen.  In general, while these principles apply to player vs NPC scenarios, they might also be applicable in NPC vs NPC scenarios.

    1. Lower the NPCs attitude value toward the player.  Reduce it more significantly depending on the amount of damage done or debuffs applied.  eg: A stun has far less severe consequences than lighting an NPC on fire does.  Doing 100 dmg, lowers the attitude far more than 10 dmg does.  This attitude value might be increased through other interactions with the NPC, such as healing it, talking to it, doing quests for it, belonging to the same faction as it, etc.

    2. Any nearby NPCs that have a visual on the player and the attacked NPC should also consider if they like or dislike or are indifferent toward the action the player is taking.  For example, Darth Vader would like it if the player kills a rebel NPC, but dislike it if the player kills a stormtrooper and be indifferent toward the player killing a jawa.  They should then lower or increase their attitude value toward the player.  This would be far less significant than the effect of a direct attack.  eg: 1 point up/down, instead of 20, etc.

    3. If the attitude value remains positive, the NPC should warn the player not to do that verbally/visually, but not do anything yet. eg: similar to the warn jaden sounds

    4. If the attitude drops to negative, the NPC will begin treating the player as hostile and any other player's he is currently on a team with.

    5. NPCs with a hostile attitude may do different things depending on the who they are.  For example, a stormtrooper will probably just begin attacking the player.  Not all NPCs of the same class should necessarily behave the same, see below for details. 

    6. If the player attacked an NPC at somewhere other than neutral/no man's land, they should also be given notoriety points, just as they would with attacking a player.

  • Hostile NPCs: When an npc becomes hostile toward another player it may do several different things depending on its class and personality.  For example: A jawa might run away in fear.  A quest npc, might fail your current quest/change the requirements.  A shopkeeper might refuse to trade with you. Etc.  Typically most NPCs will attack the player and their allies.  However there are a couple of things to factor in, the NPC will need to consider a couple of things:

    • Does it know where the hostile player/npc is?  (Does it a visual within its range?)

    • How long ago did it last have a visual on the target?

    • Does it have a weapon(s) to defend itself with?  And does that weapon have range to hit the target?

    • Is it outnumbered?

    • Is it outleveled?

    • How many of its allies has the target already killed/attacked?

    • What is its personality?  NPCs should have the option of having a random personality generated with each spawn, this way every npc is slightly different with how they approach situations to some degree.  Developers can script in certain restrictions so some NPCs always react the same way, but for most the default will be just random personality biases.  For example while Jawa's might tend to be more on the cowardly end of the spectrum and choosing to flee or find cover when in a hostile situation, occasionally one might have the rare chance of being born with courage and thus fight to defend itself instead of fleeing.  We would generate these similar to how treasureclass's work with items, where a set of ranges is specified for each npc class and the values generated for each behavior category being within the range specified (will talk about those categories later).

  • After evaluating the above, the hostile NPC will most likely either try to flee or fight the player.  Its personality and equipment will help determine its fighting 'style'.  For example, if its more cowardly, it might try to snipe the player while ducking down beneath cover if it is a considerable range away from the player.  If it is completely outmatched in level, equipment, and not brave, it will probably just try to run away from the player as far as it can get.  If it has other allies and feels confident in attacking the player, they might try to work together to flush the player out of hiding, by encircling the player's position for example.

  • NPC Personality Category Ideas, these would probably be variable amounts, eg: -100 to 100, or 0 to 100, depending on the NPC's value.  The npc file would determine the range generated for each category, or use a default if not specified:

    • <Brave-----Coward> (NPC will fight or flee)

    • <Reckless----Cautious>  (NPC will abandon self preservation vs prioritize staying alive.  NPCs with high reckless values will have no problem dishing out friendly fire.)

    • <Obsessive----Tactical> (How likely the NPC is to fixate on a specific target.  eg: if the player who attacked them is part of a team, will they put priority on the player who first caused them injury while putting their allies/team as secondary targets?  If the NPC is "tactical", the more likely the NPC is to switch targets based on tactical reasoning.  eg: if it can't see/hit the original target it will switch targets.  Regardless of this setting, if a player does excessive damage to the NPC (50+% of its HP), it will switch to a new target/fixation.

    • <Prefers Range-----Prefers Melee> (How close to the player with the NPC try to get?)

    • <Prefers Backup----Prefers to Solo>  (NPC might only fight if it has a group, or fight regardless of allies).

    • <Friendly Fire----Save Allies>   (NPC will kill its allies if it has to vs always prioritizing saving its allies instead of the player)

    • <Curious----Indifferent>  (How likely the NPC is to investigate odd things.  eg: If its companion dies, does it look for a cause or if it hears something odd, or does it ignore stuff)

    • <Darkside----Lightside> (Which spectrum is the NPC on?)

    • <Preferred Weapon> (Does the NPC have a preferred weapon, when given a choice.  eg: if an NPC has a rocket launcher, an e-11 and a grenade which one does it choose if they're all in range?)

    • <Loves> (Is there any entity the NPC prizes above their own safety?  eg: Is the NPC assigned to protect a VIP, such as the player or another NPC, and puts their safety at risk to protect the target if necessary?)

    • <Hates> (Is there anything the NPC hates above everything else?  eg: Does it hate Tusken Raiders and will focus a Tusken over a player whenever faced with both?)


We also need to talk about pathfinding/routing and how that should work, but I figured I'd let Xycaleth weigh in on that first since he's been playing with it the most.


z3filus likes this

JKG Developer

Link to comment

NPCs can have multiple items and weapons in their inventory as determined by treasure classes.

NPC Interactions in combat:

During combat, there are certain objects NPCs may interact with depending on what is happening. They may knock over a table for cover, or jump over it when they are trying to run away. They can also just simply take cover behind other objects or walls.

They may kick over a barrel of volatile tibanna gas and roll it towards a player, or attempt to stay away from them if they are in combat, if they are trying to flee they will ignore the fact that they are there and may run past them.

An NPC that hears gunfire may investigate or attempt to interact with a console that will raise the alarms, potentially activating turrets or calling for reinforcements, certain weapons are quieter than others and reduce the range at which NPCs can hear sounds of gunfire.

An NPC may attempt to dodge (some are more skilled at this than others; some might faceplant upon landing, taking an extended time to get up) in certain situations. They may attempt to dive away from a grenade if it's within their vision or even when a player is simply aiming at them.

NPCs may have multiple weapons in their loadout and may choose them based on situation. If an NPC fires a weapon long enough without causing damage to an enemy (other NPC or player) or the enemy goes out of sight they may try a new approach such as throwing a grenade or if the enemy is close to them they may swap to a stun baton, vibroblade, or simply their fists. If an enemy is close enough they also may simply kick them, pistol whip, or rifle butt. They may also use a sniper rifle at long range and a shotgun or pistol at close range if they have both in their inventory.

An NPC that gets knocked down may draw their sidearm and fire it while on the ground instead of getting back up immediately, especially if an enemy is rushing them with a melee weapon.

Futuza likes this
Link to comment
On 7/26/2020 at 8:16 PM, Darth Futuza said:

We also need to talk about pathfinding/routing and how that should work, but I figured I'd let Xycaleth weigh in on that first since he's been playing with it the most.

I'm not sure there's much to say. Pathfinding is a means to an end and usually an NPC will have have some location that they need to reach, whether that's an explicit location (chasing a player, running into a build, investigating a sound, etc), or something implicit (a cover point, anywhere out a player's line of sight, a randomly picked location for patrolling).

I'm looking into using navigation meshes instead of waypoints since it provides much better information about walkable areas compared to waypoints.

Futuza likes this
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...