Scripts in Dragon Age are used to control all manner of game activity. Much of the functionality that would normally be handled by the game engine is actually managed by core scripts, allowing deep customizability.
Scripting overview - basic syntax
The Dragon Age scripting language is an evolution of nwscript which was used in Neverwinter Night Toolset. It is similar to C in terms of syntax but is much smaller and easier to learn. Scripts can be executable (i.e. they contain a StartingConditional or main function) or they can be libraries (often called "include files") which can be included into other scripts. In the Dragon Age Toolset include files usually have an "_h" suffix. (e.g. wrappers_h).
Event - driving practically everything
Dragon Age has an event-driven scripting model, with event objects being passed to scripts containing different parameters depending on the event's type. A large portion of script-writing for a standard adventure is going to involve dealing with events. Common examples include:
- An event is fired to a plot's script whenever one of its flags is set or cleared
- An event is fired to an area's script when a team of creatures dies in it or when a creature (such as the player) enters
- Events are fired to the module's script during character generation
- Events are fired to creatures when certain things happen to them (such as being hit)
Custom AI for creatures is handled by creating custom AI event handlers.
- See Event for more details.
Effects are a bundle of modifiers that are applied to an object or creature. Every effect has a type set on it that determines how it affects the object it is applied to. They also have a number of parameters on them, which vary based on the type, that change the specific behaviour. When the effect is removed (usually because the duration on the effect expires) the modifier is removed. These modifiers can be rule or stat based or more complicated visual and game effects.
They can be assigned different duration types which affect how they're applied and removed:
- Temporary: Applied for a short duration (measured in seconds)
- Permanent: Applied until manually removed through scripting
- Instant: These are one-shot modifiers that are not stored on the object (the death effect is an instant modifier for example)
- Equipped: Associated with an equipped item. The effect is removed when the item is unequipped.
Effects are commonly applied by Abilities, which are possessed by both creatures and player characters.
2DA files - All-purpose game-wide data repositories
2-Dimensional Arrays contain much of the raw data used by the game. They are generated from Microsoft Excel files. If you want to add new basic creature types, new treasure types, and so forth, you'll need to create new 2DA files.
- See Main Article: 2DA
The treasure possessed by most creatures and containers is randomly generated by the game's core scripts using a system that selects from appropriate treasure types (for example, wild animals should rarely possess steel armor in their inventories, and Darkspawn are unlikely to be carrying fine porcelain vases) and auto-scales it to be reasonably useful or valuable at the character's level. Manipulating the treasure system can involve both local variables and events.
To put a specific treasure item in a specific creature's inventory, you'll have to create a new creature template for that creature. Inventory cannot be directly defined for particular objects already placed in an area.
- See main article: Treasure system
Local variables - data repositories for individual objects
Local variables are persistent variables that are associated with in-game objects. They are not the same as the temporary variables you can create in a script; local variables retain their values even when no scripts are using them, and are shared across any scripts that choose to access them.
Local variables are set using the SetLocal* functions and read using the GetLocal* functions. There are a number of SetLocal* functions in the game engine.
Local variables must be pre-defined in a variable 2DA before they can be read or set using these functions. Dragon Age doesn't support the dynamic in-game allocation of new local variables.
An alternative to local variables can be found in the unlimited variable storage project. With a single include file and a simple function call in your module script, you can have unlimited variable and array storage with no need to declare anything in a 2da.
- See main article: Local variables
|Language:||English • русский|