-
Notifications
You must be signed in to change notification settings - Fork 17
RPG Library ‐ NPC Behaviour
To have the NPC attack the player, call "performAttack".
w.orc.performAttack(player)
That will just trigger one attack. To have the NPC continue to attack, call "antagonise".
w.orc.antagonise(player)
You can also do this as part of an agenda. Use "antagoniseNow" to have it become aggressive and attack in the same round.
w.orc.agenda = [
"walkTo:player:'Prepare to die!', says the orc with a cruel grin.",
'antagonise:player',
]
By default an NPC will stop attacking once the player moves to another room (but will attack again if the player returns). You can set the NPC to give chase by setting its "pursueToAttack" attribute. This can be set to any function, but the easiest way is to use the built-in one, which will give chase as long as there is an exit the NPC can take to the player's current location.
createItem("orc", RPG_NPC(false), {
loc:"practice_room",
ex:"A large green humanoid; hairless and dressed in leather.",
pursueToAttack:rpg.pursueToAttack,
// etc.
You can set this on the NPC at character creation too.
A common scenario in an RPG is to have an NPC guarding an item or location.
Use the "setGuard" function of an NPC to have it guard an exit from a location. It takes two arguments - the direction and an optional string or function that describes the NPC reacting to the player trying to use the exit. The NPC will guard the given exit on the room it is currently in.
w.orc.setGuard("east", "The orc looks at {nm:char:the} suspiciously.")
w.orc.setGuard("east", function(char, exit) {
msg("It chucks a rock at {nm:char:the}.", {char:char})
})
The player will be unable to use the exit while the NPC is in place; instead the message will be displayed or function run. If the NPC moves to another location or is dead, the player will be able to use it. Note that there is nothing to stop the player coming the other way, as that uses a different exit.
Use "unsetGuard" to stop the NPC guarding the exit.
w.orc.unsetGuard()
Note that both the room and the NPC must exist before you call "setGuard". I suggest creating the room first, then the guards, then calling this function.
Use the "setGuard" function, as before, but set the direction to false
.
w.orc.setGuard(false, 'The orc eyes you suspiciously.')
In this example, the orc will not actually stop the player, but you could give it a function that initiates an attack.
To have the NPC guard an item, a rather different approach works best. In this case, you are better giving the NPC an agenda.
w.orc.agenda = ['guardItemNow:tapestry:The orc draws his sword.']
This relies on the item being flagged as scenery. The guard will attack when the item in question no longer has the scenery tag - that is to say, when it gets picked up.
This version will have the orc react a bit more slowly; after the tapestry is taken, the orc will draw its sword. It will attack after the player takes a further turn.
w.orc.agenda = ['guardItem:tapestry:The orc draws his sword.']
You can use the "waitUntil" or waitUntilNow" agenda items to gave any attribute change trigger the guard. This example does the same as the previous, but illustrates the technique.
w.orc.agenda = ['waitUntilNow:tapestry:scenery:false:The orc draws his sword.', 'antagoniseNow']
To just kill an NPC call the "terminate" function, passing the fatal attack as a parameter, if applicable. If it is already dead, nothing will happened. If it is alive, it will become dead, triggering its afterDeath function and printing its "msgDeath". Its "dead" attribute will be set to true
.
w.orc.terminate()
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