-
Notifications
You must be signed in to change notification settings - Fork 14
NPCs: Followers
Sometimes we want an NPC to follow either another NPC, or more often the player.
NOTE: If you want to do this in an agenda, see that page. It uses the same attributes, so is fully compatible, but the commands are in the agenda so are different.
The player can ask an NPC to follow her with [NPC], FOLLOW ME or TELL [NPC] TO FOLLOW ME. To stop the NPC following, use [NPC], STOP FOLLOWING ME or TELL [NPC] TO WAIT HERE, etc.
You can use "getAgreement" or "getAgreementFollow" to have the NPC decide whether or not to follow the player; this is discussed more here.
If you are using dynamic conversations, there are some example topics on that page.
Behind the scenes, the commands use these functions too.
To have an NPC follow someone, use the setLeader
function. In this example, Lara will follow Kyle.
w.Lara.setLeader(w.Kyle)
Lara will get her "leaderName" attribute set to "Kyle", and Kyle will have "Lara" added to his "followers" attribute (which is an array of strings).
You can use "getFollowers" on the leader to get a list of follower objects, rather than the names.
Use the "setLeader" function without a paramter to stop an NPC following. Unsetting a leader when there is no leader set will have no effect, so can be used if you are unsure. It is also safe to set a new leader when there is already one set.
w.Lara.setLeader()
You can give an NPC a "testFollowTo" function attribute, which can be used to stop the NPC going in certain rooms. There is an example here.
Note that if you want an NPC to follow the player from the start of the game, you should put the code inside settings.setup
to ensure player
has been set.
settings.setup = function() {
w.magpie.setLeader(player)
}
If an NPC will be following the player for much of the game, it is a good idea to mix up the text a bit. The best way to do that is with the NPC's "movingMsg" function attribute.
For this example, I have assigned an "enviro" attribute to every location, and I am using that to determine what the magpie does. A location can also have its own "magpieFollowMsg" to further individualise it.
followMsgs:{
town:'The magpie perches on a {random:window ledge:gutter:ridgetile}.',
forest_road:'The magpie hops along the road behind you.',
forest:'The magpie jumps onto a branch, and looks at you quizzically.',
marsh:'The magpe follows, circling for a moment before alighting on a relatively dry patch of ground.',
cave:'The magpie follows you, jumping from rock to rock.',
},
movingMsg:function(exit, isFollowing) {
if (isFollowing && currentLocation.magpieFollowMsg) {
currentLocation.magpieFollowMsg()
}
else if (isFollowing) {
msg(this.followMsgs[currentLocation.enviro])
}
else if (exit.msgNPC) {
exit.msgNPC(char)
}
else {
lang.npc_leaving_msg(this, exit)
lang.npc_entering_msg(this, exit)
}
},
The tavern then has this:
magpieFollowMsg() {
msg("The magpie flies into tavern too, and perches on a beam.")
if (!this.magpieflag) {
this.magpieflag = true
msg("'Get that filthy bird out of here,' says the innkeeper.")
msg("'Don't look at me,' you say. 'Stupid thing follows me round everywhere.' You wave your arms at it, and get it to fly to another beam.")
msg("'If it craps in here...' mutters the innkeeper.")
}
},
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
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
- 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
- Following an agenda
- Reactions
- Giving
- Followers
- 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!)
- Attributes for characters
- Attacking and guarding
- Skills and Spells
- Limiting Magic
- Effects
- The Attack Object
- 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)
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
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