Script

From Dragon Age Toolset Wiki
Revision as of 22:48, 23 November 2009 by BryanDerksen (Talk | contribs) (2DA files - All-purpose game-wide data repositories: link to a 2DA ranges in use page)

Jump to: navigation, search

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 DA scripting language is very similar to C in terms of syntax. Files can be included into other files, with files containing libraries of functions designated by a "_h" suffix.

Events - 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.

Effects and Abilities - how to make things affect other things

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:

  1. Temporary: Applied for a short duration (measured in seconds)
  2. Permanent: Applied until manually removed through scripting
  3. Instant: These are one-shot modifiers that are not stored on the object (the death effect is an instant modifier for example)
  4. 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.

2DA row ID numbers need to be unique across all currently active addins for any given 2DA, otherwise they'll override each other with potentially disruptive effects. See 2DA ranges in use for a list of 2DA row IDs currently used by popular addins.

Treasure system

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.

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.