-
Notifications
You must be signed in to change notification settings - Fork 18
NPCs ‐ Reactions
One way to give life to an NPC is to have him react to the world around him. If the player appears wearing a fancy hat, have the NPC react to it.
We can do that through an array attribute called reactions
. By default this will be checked each round the NPC is in the same room as the player. If you want it to happen even when not in the same location:
settings.npcReactionsAlways = true
This is an array of dictionaries, with each entry in the array being a different reaction.
Each reaction has a "name", a "test", a "script" and (optionally) an "override". The "test" and "script" attributes should be functions taking a dictionary parameter which will include the NPC as the "char2 attribute (you cannot use this
inside the functions as it will refer to the dictionary in the array, not the NPC).
The "override" attribute, if present, should be an array of strings. The "name" attribute is just a string used by the reaction system to identify each reaction. If an NPC has several reactions with the same name, only one will ever get used - this can be useful!
If the NPC is present, Quest will go through each reaction in the dictionary. If the reaction has already been used, it will be skipped. Otherwise, the test is run, and if it returns true
, the action will be run and any reactions listed in override will be flagged as completed as well as this one. Only one action will be used per turn per character - the first in the list that returns true from its "test" function.
In this example, two reactions are set. The two "test" functions determine if the reaction will be used, whilst the "script" functions do the work of the reaction. The parameter in "test" and "script" can be omitted when not used, the second "script" uses it to illustrate how to do so.
Note that the "bigHat" reaction takes priority, it overrides "smallHat". If the first reaction fires, it will override the second, so Mary will never comment on the small hat if she sees the player wearing the big hat first. The reaction that takes priority must appear earlier in the list.
reactions:[
{
name:'big_hat',
test:function() {
return player.getOuterWearable("head") === w.big_hat
},
script:function() {
msg("'Wow, what a great hat,' Mary says.")
},
override:["small_hat"],
},
{
name:'small_hat',
test:function() {
return player.getOuterWearable("head") === w.small_hat
},
script:function(params) {
msg("'What a lovely hat,' " + lang.getName(params.char) + " says.")
},
},
],
If a reaction has no name, it can be used multiple times. This can be useful too.
If there is a reaction, Quest will call pause() on the NPC to stop him doing anything else this turn. If you do not want that to happen, add noPause:true,
to the dictionary.
Reactions use the respond
function, and so can be nested.
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