NPCs - ThePix/QuestJS GitHub Wiki
Non-player characters (NPCs) are the people in your game world. People are complicated, and creating great NPCs is going to take a lot of work. All we will do here is get you started.
To create an NPC, use the NPC templare, which takes a Boolean indicating if the NPC is female.
createItem("Lara", NPC(true), {
loc:"dining_room",
examine:"A normal-sized bunny.",
properName:true,
})
For an NPC that is not male or female, just set the "pronouns" attribute. For example:
createItem("robot", NPC(false), {
loc:"lounge",
examine:"A big, shiny robot.",
pronouns:lang.pronouns.thirdperson,
})
For non-binary characters, your can use"nonbinary" for they, them, etc. but you can also use other pronoun sets, see here.
There is a lot you can do with NPCs...
- There is a list of attributes for NPCs here.
- By default, an NPC will do any command the player asks (if you have your own custom commands, you will need to set them up to allow that to happen). How you can control that is discussed here.
- You will probably want your NPC to talk. There are various approaches; you can read about them here.
- You might also want your NPC to do something, to act independently. To learn how to have an NPC follow an agenda, go here.
- It would be great if your NPCs react to events in the world around them. See here for how to do that.
- You might want to have the player give an item to an NPC, or to tell an NPC to give an item to the player See here.
- You might want an NPC to follow the player - or another NPC. See here.
- You might want the user to be able to change from one character to another, as described here.
- A way to allow the user to set the player's attitude to NPCs is discussed in the UI section.
Sometimes you may want to change the alias of an NPC, perhaps because the player has now learned his name; see here. Or perhaps the NPC has had a sex-change, and needs to use a different set of pronouns; see here.