-
Notifications
You must be signed in to change notification settings - Fork 17
NPCs ‐ Attributes
Most of the standard attributes also apply to NPCs. See here for more.
For items you should generally use their "moveToFrom" function attribute, but for characters, including the player, "moveChar" is used.
If you do need to just set "loc" for the player - and there are times - you should call a couple of functions after to make sure things are updated.
player.loc = 'ballroom'
world.update()
world.enterRoom(exit)
The world.enterRoom
function runs the various on entry functions and gives the room description. The exit
parameter is required if there is any possibility of the player having followers.
Moves the given character (which could be the player) to the given location. Characters are different to items for a number of reasons. If a hat is moving, it is because something else is doing it, and we can rely on that thing to tell the user about it. NPCs move on their own, so we may want to tell the user about, they may have followers, they might be carry an item that does something special when moved, etc.
Note that this moves the player silently - though it may trigger reactions that are not silent. To keep the player informed, you should also call "movingMsg".
Occasionally you will want to move the player to a location with no convenient exit. The solution is to create a disposable exit on the fly.
west:new Exit('lounge', {
simpleUse:function(char) {
if (w.lounge.rift_open) {
char.moveChar(new Exit('interdimensional_rift', this))
return true
}
return util.defaultSimpleExitUse(char, this)
}
},
Note that I am using this
, which refers to the original exit. The new exit will get all the attributes of the original exit except the name, so this sorts out all the attributes set in the background. Otherwise, you need to set "dir" to a string, and "origin" to a location.
player.moveChar(new Exit('interdimensional_rift', {dir:'west', origin:currentLocation}))
This is a function on the NPC; you can give the NPC a custom function to give it specific messages when it moves.
You should call this before you use "moveChar" in your own code to ensure the user is told the character is moving. Quest will work out if the player should be able to see it, and report accordingly.
This is generally best called before the move, so reactions to the move are reported after it happened.
Generally not used for the player character - you can just use a standard msg
command.
Sometimes it is better to just set "loc". Generally I advise again for moving items, as you cannot be sure it is using the "loc" attribute, but NPCs do, so we are safe wth regards to that.
Be aware that none of the reactions will trigger if you do it this way. It is good for when you are introducing the character to the game for the first time, or removing her entirely, but not so good when she is walking around, and should be using the standard exits.
For the player, there is some housekeeping you will need to do. Once the "loc" is set, you need to call world.update
to tell quest to update various things, and then world.enterRoom
to trigger the room enterng scripts and print a description of the new room.
msg("You head down the road to...")
player.loc = 'battlefield'
world.update()
world.enterRoom(exit)
Note that world.enterRoom
expected to be given an exit. If the player cannot possibly have any followers when this happens, this can be omitted.
You can replace these with your own values to make each NPC unique.
Arrays for ASK/ABOUT and TELL/ABOUT. See here for more.
Used by the agenda system. See here for more.
Used by the reactions system. See here for more.
These are called before certain commands. If they return true, the NPC can do it, otherwise, they should print a message and then return false. This allows you to have the NPC incapacitated in various ways.
Used to determine whether the NPC will do as the player asks. If they return true, the NPC is willing to do it, otherwise, they should print a message and then return false. This will be sent the name of the command and the item, if applicable, so you can finely control what the NPC will or will not do.
Generally you should not change these; they are there to make it easier for you to do things.
Each will return a list of objects for this NPC.
Returns true if the player is in the same location as the NPC.
Prints the given string only if the player is in the same location as the NPC.
Prints the given array of strings, in order, one string per call of the function (the first time the function is called, the first string is print, etc.). Once it gets to the end of the list, it will repeat the last item.
The purpose of this is to give variety in the messages for an NPC. Rather than say "Lara is watching you intently" every turn, you can provide an array of possible messages, and Quest will cycle through them.
As with msg
, only printed if the player is in the same location as the NPC (if the player is not present, the list does not iterate, so no entries are missed).
Note that this uses the first entry to create a counter attribute (stripping out all non-letters). This could cause a naming collision, but should be fine as long as the first entry is long and unique for this NPC.
Assign a leader to this NPC. The NPC will become part of a group following the leader's agenda.
Stops the NPC following his agenda (or the group following his leader's agenda) for a single turn.
Move the NPC to the destination. If the player is at the destination or the original location, she will see a message that the NPC has moved.
Returns the outer-most (i.e. visible) garment at the given slot.
Tutorial
- First steps
- Rooms and Exits
- Items
- Templates
- Items and rooms again
- More items
- Locks
- Commands
- Complex mechanisms
- Uploading
QuestJS Basics
- General
- Settings
- Attributes for items
- Attributes for rooms
- Attributes for exits
- Naming Items and Rooms
- Restrictions, Messages and Reactions
- Creating objects on the fly
- String Functions
- Random Functions
- Array/List Functions
- The
respond
function - Other Functions
The Text Processor
Commands
- Introduction
- Basic commands (from the tutorial)
- Complex commands
- Example of creating a command (implementing SHOOT GUN AT HENRY)
- More on commands
- Shortcut for commands
- Modifying existing commands
- Custom parser types
- Note on command results
- Meta-Commands
- Neutral language (including alternatives to "you")
- The parser
- Command matching
- Vari-verbs (for verbs that are almost synonyms)
Templates for Items
- Introduction
- Takeable
- Openable
- Container and surface
- Locks and keys
- Wearable
- Furniture
- Button and Switch
- Readable
- Edible
- Vessel (handling liquids)
- Components
- Countable
- Consultable
- Rope
- Construction
- Backscene (walls, etc.)
- Merchandise (including how to create a shop)
- Shiftable (can be pushed from one room to another)
See also:
- Custom templates (and alternatives)
Handing NPCs
- Introduction
- Attributes
- Allowing the player to give commands
- Conversations
- Simple TALK TO
- SAY
- ASK and TELL
- Dynamic conversations with TALK TO
- TALK and DISCUSS
- Following an agenda
- Reactions
- Giving
- Followers
- Visibility
- Changing the player point-of-view
The User Experience (UI)
The main screen
- Basics
- Printing Text Functions
- Special Text Effects
- Output effects (including pausing)
- Hyperlinks
- User Input
The Side Panes
Multi-media (sounds, images, maps, etc.)
- Images
- Sounds
- Youtube Video (Contribution by KV)
- Adding a map
- Node-based maps
- Image-based maps
- Hex maps
- Adding a playing board
- Roulette!... in a grid
Dialogue boxes
- Character Creation
- Other example dialogs [See also "User Input"]
Other Elements
- Toolbar (status bar across the top)
- Custom UI Elements
Role-playing Games
- Introduction
- Getting started
- Items
- Characters (and Monsters!)
- Spawning Monsters and Items)
- Systema Naturae
- Who, When and How NPCs Attack
- Attributes for characters
- Attacking and guarding
- Communicating monsters
- Skills and Spells
- Limiting Magic
- Effects
- The Attack Object
- [Extra utility functions](https://github.com/ThePix/QuestJS/wiki/RPG-Library-%E2%80%90-Extra Functions)
- Randomly Generated Dungeon
- Quests for Quest
- User Interface
Web Basics
- HTML (the basic elements of a web page)
- CSS (how to style web pages)
- SVG (scalable vector graphics)
- Colours
- JavaScript
- Regular Expressions
How-to
Time
- Events (and Turnscripts)
- Date and Time (including custom calendars)
- Timed Events (i.e., real time, not game time)
Items
- Phone a Friend
- Using the USE verb
- Display Verbs
- Change Listeners
- Ensembles (grouping items)
- How to spit
Locations
- Large, open areas
- Region,s with sky, walls, etc.
- Dynamic Room Descriptions
- Transit system (lifts/elevators, buses, trains, simple vehicles)
- Rooms split into multiple locations
- Create rooms on the fly
- Handling weather
Exits
- Alternative Directions (eg, port and starboard)
- Destinations, Not Directions
Meta
- Customise Help
- Provide hints
- Include Achievements
- Add comments to your code
-
End The Game (
io.finish
)
Meta: About The Whole Game
- Translate from Quest 5
- Authoring Several Games at Once
- Chaining Several Games Together
- Competition Entry
- Walk-throughs
- Unit testing
- Debugging (trouble-shooting)
Releasing Your Game
Reference
- The Language File
- List of settings
- Scope
- The Output Queue
- Security
- Implementation notes (initialisation order, data structures)
- Files
- Code guidelines
- Save/load
- UNDO
- The editor
- The Cloak of Darkness
- Versions
- Quest 6 or QuestJS
- The other Folders
- Choose your own adventure