<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://www.datoolset.net/mw/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Hydra1448</id>
		<title>Dragon Age Toolset Wiki - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://www.datoolset.net/mw/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Hydra1448"/>
		<link rel="alternate" type="text/html" href="https://www.datoolset.net/wiki/Special:Contributions/Hydra1448"/>
		<updated>2026-04-23T16:41:46Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.25.6</generator>

	<entry>
		<id>https://www.datoolset.net/mw/index.php?title=Scripting_tutorial&amp;diff=7526</id>
		<title>Scripting tutorial</title>
		<link rel="alternate" type="text/html" href="https://www.datoolset.net/mw/index.php?title=Scripting_tutorial&amp;diff=7526"/>
				<updated>2009-11-08T23:55:05Z</updated>
		
		<summary type="html">&lt;p&gt;Hydra1448: /* Passing execution to other event handlers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The final piece of the puzzle in our little tutorial game is getting the &amp;lt;code&amp;gt;MONSTERS_SLAIN&amp;lt;/code&amp;gt; flag set on our plot so that when the hero succeeds in his quest, the quest giver will know about it. This is done via scripting.&lt;br /&gt;
&lt;br /&gt;
Scripting is a programming language with a syntax similar to C. This tutorial assumes a small amount of programming knowlege but hopefully it will be possible even for one with no experience to pick up the basics here.&lt;br /&gt;
&lt;br /&gt;
== Dragon Age's event-driven model ==&lt;br /&gt;
&lt;br /&gt;
In Dragon Age scripts are primarily event-driven. An &amp;quot;event&amp;quot; is a package of information in a special format that gets passed around in the game to trigger behaviour. They are generated by other scripts or the game engine and are passed to an object's event-handling script.&lt;br /&gt;
&lt;br /&gt;
Events have a type, a target object, a time delay and a package of parameters (arbitrary number of ints, objects, floats and strings).&lt;br /&gt;
&lt;br /&gt;
As an example, the &amp;quot;&amp;lt;code&amp;gt;[[EVENT_TYPE_ATTACK_IMPACT]]&amp;lt;/code&amp;gt;&amp;quot; event is sent by the game engine whenever an attack hits a target. It contains the identities of the attacker and the target, whether the attack was a critical hit, and the amount of damage that the attack did. It is sent to an event-handling script attached to the attacker, which takes the information it contains and handles it in whatever way is appropriate (reducing the target's hit points, usually).&lt;br /&gt;
&lt;br /&gt;
For our purposes right now we're not going to need to generate any events of our own. We have set all of the hut monsters to be members of team 1, and the game has a built-in feature that will generate an event when all of the members of a particular team of creatures has been killed. Our new script will respond to that event by setting the plot flag so that when the hut monsters are all defeated, the plot will change to indicate the quest objective has been accomplished.&lt;br /&gt;
&lt;br /&gt;
An enormous list of events for all occasions can be found at the [[event]] page. The one we're going to want our script to look for is &amp;lt;code&amp;gt;[[EVENT_TYPE_TEAM_DESTROYED]]&amp;lt;/code&amp;gt;, which is sent when the last member of a team of creatures is destroyed. The event contains the team number within it.&lt;br /&gt;
&lt;br /&gt;
== Creating a basic event-handling script ==&lt;br /&gt;
&lt;br /&gt;
Start by creating a new script resource. We'll call our script &amp;quot;&amp;lt;code&amp;gt;hut_monsters_slain&amp;lt;/code&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In most cases when a script is run the scripting engine will start with a function named &amp;quot;&amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;&amp;quot;. So for most scripts you'll want to start with this very basic beginning:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code that will perform our tasks will be inserted between the { and } brackets. &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; doesn't return any results directly, so the function's return type is &amp;quot;&amp;lt;code&amp;gt;[[void]]&amp;lt;/code&amp;gt;&amp;quot;, and it takes no parameters, so the parameter list is an empty ().&lt;br /&gt;
&lt;br /&gt;
=== Event type constants ===&lt;br /&gt;
&lt;br /&gt;
Next we're going to need to make sure the script will know what we're talking about when we make references to events. The tag that tells us the type of each event is is actually represented internally by a number, but since it would be impossible for a programmer to keep track of all the different event numbers without making hard-to-find mistakes Dragon Age has instead used named constants to represent them in a more human-readable name.&lt;br /&gt;
&lt;br /&gt;
Those constants are defined in the script &amp;lt;code&amp;gt;events_h&amp;lt;/code&amp;gt;.  The &amp;quot;&amp;lt;code&amp;gt;_h&amp;lt;/code&amp;gt;&amp;quot; suffix stands for &amp;quot;header&amp;quot;, which is a special class of script that contains only various definitions meant to be included in other scripts and doesn't do anything on its own.&lt;br /&gt;
&lt;br /&gt;
To include the header file, add this line to the top of our script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;quot;events_h&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All &amp;lt;code&amp;gt;#include&amp;lt;/code&amp;gt; commands should be at the top of your script before anything else, but if there's more than one it shouldn't matter what order they are in.&lt;br /&gt;
&lt;br /&gt;
To see whether our script now knows what &amp;lt;code&amp;gt;[[EVENT_TYPE_TEAM_DESTROYED]]&amp;lt;/code&amp;gt; means you can use the constant browser on the right edge of the script editor to check if it's listed. The browser defaults to showing a list of all defined functions (the &amp;quot;f()&amp;quot; button), to set it to show all defined constants click on the &amp;quot;C&amp;quot; button.&lt;br /&gt;
&lt;br /&gt;
[[Image:Scripting constant browser.png]]&lt;br /&gt;
&lt;br /&gt;
Even without any included files the list of defined constants is going to be quite long, and for scripts with many include files it can be very difficult to find any particular constant - especially if you aren't sure exactly what its name is. To find constants more easily, type any part of its name into the filter field at the top.&lt;br /&gt;
&lt;br /&gt;
[[Image:Scripting constant browser filtered.png]]&lt;br /&gt;
&lt;br /&gt;
To insert the constant into the script at the location where the cursor is currently located, simply double-click on the constant in the constant browser. This avoids any risk of making a typo.&lt;br /&gt;
&lt;br /&gt;
=== Extracting information about the current event ===&lt;br /&gt;
&lt;br /&gt;
When an event is sent to a script the script's &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; function will be run, but it won't know anything about the event that caused it to be run without some explicit instructions.&lt;br /&gt;
&lt;br /&gt;
First, you will need to retrieve the package of data that is the event. We'll define a variable named &amp;lt;code&amp;gt;ev&amp;lt;/code&amp;gt; that will hold this package, and set it to the &amp;quot;&amp;lt;code&amp;gt;event&amp;lt;/code&amp;gt;&amp;quot; data type. To retrieve the current event and stick it into that variable, we'll use the engine-defined function &amp;lt;code&amp;gt;[[GetCurrentEvent]]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The first line of the main function will therefore be:&lt;br /&gt;
&amp;lt;code&amp;gt;event ev = GetCurrentEvent();&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every event will have an event type. As described above, this event type is represented internally by an integer. We'll create an integer variable named &amp;lt;code&amp;gt;nEventType&amp;lt;/code&amp;gt; to hold it, and use the &amp;lt;code&amp;gt;GetEventType&amp;lt;/code&amp;gt; function to extract it from &amp;lt;code&amp;gt;ev&amp;lt;/code&amp;gt;. The next line will be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;int nEventType = [[GetEventType]](ev);&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The rest of the information packaged with the event depends on exactly what kind of event it is, so the rest of the code we write will be event-specific. To make sure only the correct code is run we'll use a &amp;lt;code&amp;gt;switch&amp;lt;/code&amp;gt; statement. We're only looking for one particular event so we could just as easily have used an &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement but a &amp;lt;code&amp;gt;switch&amp;lt;/code&amp;gt; is more extendable for future use.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
switch(nEventType)&lt;br /&gt;
    {&lt;br /&gt;
         case EVENT_TYPE_TEAM_DESTROYED:&lt;br /&gt;
         {&lt;br /&gt;
             //our event-specific code goes here&lt;br /&gt;
             break;&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We know from the documentation for the &amp;lt;code&amp;gt;[[EVENT_TYPE_TEAM_DESTROYED]]&amp;lt;/code&amp;gt; event, that it comes with a single piece of information; the team number. It's an integer, so we can extract it with the &amp;lt;code&amp;gt;[[GetEventInteger]]&amp;lt;/code&amp;gt; function. &amp;lt;code&amp;gt;[[GetEventInteger]]&amp;lt;/code&amp;gt; takes two parameters, the event object (which we've stored in the variable &amp;lt;code&amp;gt;ev&amp;lt;/code&amp;gt;) and the index of the integer we want, in this case 0 (this is listed in the documentation).&lt;br /&gt;
&lt;br /&gt;
We also know that the team number we gave the hut monsters is 1, so we want to update the plot only when we receive an event indicating that team number 1 has been destroyed. We can do this with an &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if (GetEventInteger(ev,0) == 1)&lt;br /&gt;
{&lt;br /&gt;
    //code to update the plot here&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Interacting with plots ==&lt;br /&gt;
&lt;br /&gt;
To interact with a plot's flags you'll need to have some way for the script to know where the plot flags are and what they're named. This is done in a similar manner to how we told the script what the event types were named; by including the plot file in the script.&lt;br /&gt;
&lt;br /&gt;
Plots are not the same as regular scripts, though, so when including them they are distinguished from regular scripts through the use of a &amp;lt;code&amp;gt;plt_&amp;lt;/code&amp;gt; prefix in their name. The plot we wish to interact with is called &amp;lt;code&amp;gt;clear_the_hut&amp;lt;/code&amp;gt;, so at the top of the script file you'll need to put the line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;#include &amp;quot;plt_clear_the_hut&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now your script will have access to the plot's flags and will be able to read or change them. You'll find that several new constants have been defined; &amp;lt;code&amp;gt;PLT_CLEAR_THE_HUT&amp;lt;/code&amp;gt; contains the plot object, and the integer constants &amp;lt;code&amp;gt;MONSTERS_SLAIN&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;QUEST_ACCEPTED&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;REWARD_RECEIVED&amp;lt;/code&amp;gt; identify the flags within the plot.&lt;br /&gt;
&lt;br /&gt;
Changing the state of the flags is done with the &amp;lt;code&amp;gt;WR_SetPlotFlag&amp;lt;/code&amp;gt; function that is defined in the include file &amp;lt;code&amp;gt;wrappers_h&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;wrappers_h&amp;lt;/code&amp;gt; contains a variety of utility functions that handle operations requiring low-level access to the game. Add &amp;lt;code&amp;gt;#include &amp;quot;wrappers_h&amp;quot;&amp;lt;/code&amp;gt; to the top of your script). In our case, we want to set the plot flag &amp;lt;code&amp;gt;MONSTERS_SLAIN&amp;lt;/code&amp;gt;. The &amp;lt;code&amp;gt;WR_SetPlotFlag&amp;lt;/code&amp;gt; function takes three parameters; the plot identifier, the flag identifier, and the state we want to set it to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
WR_SetPlotFlag(PLT_CLEAR_THE_HUT, MONSTERS_SLAIN, TRUE);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Associating an event script with an object ==&lt;br /&gt;
&lt;br /&gt;
The script is almost complete now, but until we've linked it up to some object in the game that can receive events it will never actually be run.&lt;br /&gt;
&lt;br /&gt;
Most objects in the game will have a field named &amp;quot;Script&amp;quot; shown in the object inspector. According to the documentation for the &amp;lt;code&amp;gt;EVENT_TYPE_TEAM_DESTROYED&amp;lt;/code&amp;gt; event it is sent to the area object the team is in, so we'll want to open the hut_interior area now and go to its Script entry. The default event script for areas is &amp;lt;code&amp;gt;area_core&amp;lt;/code&amp;gt;, which handles basic area events in a default way.&lt;br /&gt;
&lt;br /&gt;
This is where you'll want to put the &amp;lt;code&amp;gt;hut_monsters_slain&amp;lt;/code&amp;gt; script. Click on the ellipsis ([[Image:ellipsis.png]]) button and select the new script. It will replace &amp;lt;code&amp;gt;area_core&amp;lt;/code&amp;gt;, and now when there are events sent to this area our new script will be triggered and handle them.&lt;br /&gt;
&lt;br /&gt;
=== Passing execution to other event handlers ===&lt;br /&gt;
&lt;br /&gt;
There is just one problem remaining to be resolved now. As mentioned above, the &amp;lt;code&amp;gt;area_core&amp;lt;/code&amp;gt; script normally handles a variety of events that are sent to areas. Now that we've replaced the default event handler with our custom script, and our script only responds to one specific event, there's nothing responding to the rest of the events coming into the area any more. Our custom script has preempted and therefore effectively disabled all the default area event processing by not responding to every possible area event.&lt;br /&gt;
&lt;br /&gt;
We don't want to re-implement all that default event handling in our own script, for a variety of reasons; it's a lot of work, we could make mistakes, and it would be difficult to update the default event handling across all of our areas in the future. Fortunately there's an easy way to tell Dragon Age to use another script to handle events; namely, the &amp;lt;code&amp;gt;[[HandleEvent]]&amp;lt;/code&amp;gt; function. It takes two parameters, the event object to be handled and an identifier for the script that should handle it.&lt;br /&gt;
&lt;br /&gt;
A set of constants defining identifiers for the common default scripts is in the &amp;lt;code&amp;gt;global_objects_h&amp;lt;/code&amp;gt; header file, but we won't need to include that because &amp;lt;code&amp;gt;wrappers_h&amp;lt;/code&amp;gt; includes it already. So all we need to do is insert the following line after our switch statement:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HandleEvent(ev, RESOURCE_SCRIPT_AREA_CORE);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(The RESOURCE_SCRIPT_AREA_CORE constant is defined in global_objects_h, which we don't need to include explicitly in this case because it's already included in wrappers_h.)&lt;br /&gt;
&lt;br /&gt;
With this addition, whenever any event is sent to the hut_interior area, first our script will run and process the event, and then it will send it on to &amp;lt;code&amp;gt;area_core&amp;lt;/code&amp;gt; to handle the default area processing normally done when no custom event handling script is being used.&lt;br /&gt;
&lt;br /&gt;
The final text of our script, then, is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;quot;events_h&amp;quot;&lt;br /&gt;
#include &amp;quot;plt_clear_The_hut&amp;quot;&lt;br /&gt;
#include &amp;quot;wrappers_h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{   &lt;br /&gt;
    event ev = GetCurrentEvent();&lt;br /&gt;
    int nEventType = GetEventType(ev);&lt;br /&gt;
    &lt;br /&gt;
    switch(nEventType)&lt;br /&gt;
    {&lt;br /&gt;
         case EVENT_TYPE_TEAM_DESTROYED:&lt;br /&gt;
         {&lt;br /&gt;
              if(GetEventInteger(ev,0) == 1)&lt;br /&gt;
              {&lt;br /&gt;
                   WR_SetPlotFlag(PLT_CLEAR_THE_HUT, MONSTERS_SLAIN, TRUE);&lt;br /&gt;
              }&lt;br /&gt;
              break;&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
    HandleEvent(ev, RESOURCE_SCRIPT_AREA_CORE);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripts]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Hydra1448</name></author>	</entry>

	<entry>
		<id>https://www.datoolset.net/mw/index.php?title=Module_tutorial&amp;diff=7435</id>
		<title>Module tutorial</title>
		<link rel="alternate" type="text/html" href="https://www.datoolset.net/mw/index.php?title=Module_tutorial&amp;diff=7435"/>
				<updated>2009-11-06T22:23:24Z</updated>
		
		<summary type="html">&lt;p&gt;Hydra1448: /* Naming conventions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This simple demo module is intended to show off a variety of methods that will be commonly used in real stand-alone modules. The documentation here on this website will walk you through the major steps required to set it all up, but the module itself also has documentation embedded within it in the form of comments; it is intended to be explored in the designer toolkit and dissected to see how things tick.&lt;br /&gt;
&lt;br /&gt;
One thing that this demo doesn't demonstrate is the art of writing. As such the 'plot' of the adventure is somewhat nonsensical.&lt;br /&gt;
&lt;br /&gt;
This tutorial also assumes that you've read many of the other basic tutorials elsewhere on this site and are familiar with the basic functioning of the toolkit. Links will be provided directing you to more specific information if needed.&lt;br /&gt;
&lt;br /&gt;
== Organization ==&lt;br /&gt;
&lt;br /&gt;
There are two major groups of resources that are used when creating a Dragon Age module; designer resources and art resources. Designer resources are housed in a database whereas art resources take the form of conventional files on your file system.&lt;br /&gt;
&lt;br /&gt;
For your art resources the most convenient approach it is probably to create a directory tree with subdirectories sorting your art resources by what regions of the game they appear in. The directory tree should be someplace easily accessible and with full read/write priviledges - somewhere in your &amp;quot;My Documents&amp;quot; folder is a good place to put them.&lt;br /&gt;
&lt;br /&gt;
In our example we're going to have three areas:&lt;br /&gt;
*A swampy outdoor area with a small tavern in it&lt;br /&gt;
*The tavern's interior&lt;br /&gt;
*An outdoor roadway&lt;br /&gt;
&lt;br /&gt;
=== Naming conventions ===&lt;br /&gt;
&lt;br /&gt;
For the most part the names you give your resources will matter only to you, there are very few situations where the toolset pays attention to the specific form that a resource name takes. So provided you're working on your own, any naming convention that suits your particular style will suffice.&lt;br /&gt;
&lt;br /&gt;
Dragon Age is a large and complex game to create content for, however, so establishing ''some'' form of naming convention and adhering to it from the outset is important to ensure you don't lose track of things later on. A consistent naming system is very useful for debugging and if you later choose to collaborate with other builders it allows you to find your way around other peoples' work without needing to know it intimately.&lt;br /&gt;
&lt;br /&gt;
The convention used in the main Single Player campaign of Dragon Age is as follows:&lt;br /&gt;
&lt;br /&gt;
*Three-letter prefix indicating which large-scale area of the game the resource begins to (particular origin story, prelude, etc)&lt;br /&gt;
*three-digit number unique to a particular area, generally starting with 100 and incrementing in hundreds for major areas. Accessory areas are given numbers within the block of one hundred that their 'parent' area belongs to. &amp;quot;global&amp;quot; resources are often given the number 000.&lt;br /&gt;
*two-letter code indicating what general type of resource it is (for example &amp;quot;ar&amp;quot; for area, &amp;quot;pl&amp;quot; for placeable). A major exception here is event scripts, which have exactly the same name as the resource they're the script for. Dialogue files are also generally named exactly the same as their owner resource.&lt;br /&gt;
*An underscore.&lt;br /&gt;
*The remainder of the name is free-form  and human-readable, a descriptive term to remind you at a glance what the resource is.&lt;br /&gt;
&lt;br /&gt;
Designer resources will have a three-letter extension, much like a regular file system file, but this is not editable and does not frequently come up.&lt;br /&gt;
&lt;br /&gt;
Resources in the designer toolkit can also be placed into folders, again much like a regular file system. Unlike most file systems, though, you don't need to explicitly create a folder in order to put a resource into it. Just edit the resource's &amp;quot;folder&amp;quot; property and if the folder didn't have anything in it before it'll be created automatically. Folders that don't have any resources in them are removed automatically.&lt;br /&gt;
&lt;br /&gt;
Here's a preview of what we're going to put into the demo module, to illustrate how this naming convention looks in practice. We'll be using the four-letter prefix &amp;quot;demo&amp;quot; instead of the usual three-letter one for clarity.&lt;br /&gt;
&lt;br /&gt;
[[screenshot of demo resource palette]]&lt;br /&gt;
&lt;br /&gt;
== Setting up character generation in a new module ==&lt;br /&gt;
&lt;br /&gt;
The most basic steps of creating a new module are described in &amp;quot;[[creating a module]]&amp;quot;. A Dragon Age module, when first created, lacks many very basic components such as the ability to generate a character or an area to start in.&lt;br /&gt;
&lt;br /&gt;
Note that you can actually start creating areas and testing content before you set up character creation if you prefer, the game will provide a player with a simple (and very weak!) default character if character generation isn't performed. You can also override the default starting area and waypoint every time you export for testing purposes, using the &amp;quot;Export Options&amp;quot; found under the &amp;quot;Tools&amp;quot; menu, so you can skip directly to the area you're working on without needing to write debugging scripts.&lt;br /&gt;
&lt;br /&gt;
We're going to follow the flow of the finished game for now, though, so after creating the module the first thing we'll want to do is create a module script that triggers character generation.&lt;br /&gt;
&lt;br /&gt;
Once you've created the initial empty module you'll need to create a module script. We call it &amp;quot;demo_module&amp;quot;. The event that we'll want to handle character generation in is EVENT_TYPE_MODULE_START, which is sent to the module script only once when the game is first started up.&lt;br /&gt;
&lt;br /&gt;
To call the default character generation system, simply have this event call the following functions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            PreloadCharGen();&lt;br /&gt;
            StartCharGen(GetHero(),0);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PreloadCharGen causes the game to load up various resources that will be used in character generation, and StartCharGen causes the game to show the character generation GUI to the player.&lt;br /&gt;
&lt;br /&gt;
== Creating our areas ==&lt;br /&gt;
&lt;br /&gt;
This module will be very simple, consisting of only three areas - only two of which will have any signficiant amount of detail. They will be named:&lt;br /&gt;
&lt;br /&gt;
* demo100ar_wilderness&lt;br /&gt;
* demo200ar_tavern&lt;br /&gt;
* demo300ar_road&lt;br /&gt;
&lt;br /&gt;
Three level layouts ([[LVL]] files) are included with the module for use in these areas; ost101d (a swampy wasteland with a small wooden structure), hrt002d (a small tavern interior), and lgt600d (a section of roadway). The naming convention for level layouts used internally at BioWare is specific to the single player campaign, the meaning of these filenames is not relevant to this basic tutorial.&lt;br /&gt;
&lt;br /&gt;
The area editor (and the game itself) cannot use a LVL file directly, it must be compiled into a more efficient form for use. Open up each LVL file in the level editor and, under tools, select &amp;quot;Post to local&amp;quot; to compile the level and export it to an appropriate directory where the game and toolset will be able to find it.&lt;br /&gt;
&lt;br /&gt;
Once you've done this you can select the layout in the area editor's &amp;quot;Area Layout&amp;quot; property field.&lt;br /&gt;
&lt;br /&gt;
== Placing area transitions and setting up the world map ==&lt;br /&gt;
&lt;br /&gt;
See the [[Area tutorial]] for details on how to link areas up with level transitions. The transition from demo100ar_wilderness to demo200_tavern is straightforward and is basically the same as what's shown in that tutorial.&lt;br /&gt;
&lt;br /&gt;
The transition between demo100ar_wilderness and demo300ar_road, however, is going to be handled via the world [[map]] instead. The demo's map is a resource named demo000mp_world.&lt;br /&gt;
&lt;br /&gt;
To create an area transition that sends the player to the world map, set the PLC_AT_DEST_AREA_TAG to the string &amp;quot;world_map&amp;quot;. The placeable_core script recognizes this string as a special override that triggers a map transition by sending the module script an EVENT_TYPE_BEGIN_TRAVEL event.&lt;br /&gt;
&lt;br /&gt;
Note that you can have multiple world maps in a module, but under the default code you can't directly specify which one an area transition will send the player to. Instead, you will need to call the script function WR_SetWorldMapPrimary to specify which world map is the currently active &amp;quot;primary&amp;quot; one. In this demo the code that performs this is also in the EVENT_TYPE_MODULE_START event of the module script, since we only have one map and it only needs to be set as primary once. If you have multiple maps in your module you'll need to call this function again later from some other scripted event to change it.&lt;br /&gt;
&lt;br /&gt;
Here, then, is the complete code for the demo module's EVENT_TYPE_MODULE_START event:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      case EVENT_TYPE_MODULE_START:&lt;br /&gt;
        {&lt;br /&gt;
            object oMapId = GetObjectByTag(&amp;quot;demo000mp_world&amp;quot;);&lt;br /&gt;
            WR_SetWorldMapPrimary(oMapId);&lt;br /&gt;
&lt;br /&gt;
            PreloadCharGen();&lt;br /&gt;
            StartCharGen(GetHero(),0);&lt;br /&gt;
            break;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although the default placeable_core script has code in it to recognize that the &amp;quot;world_map&amp;quot; string should lead to a world transition and generates an EVENT_TYPE_BEGIN_TRAVEL event, the default module_core script doesn't actually do anything with this event. This is because the map transition code used in Dragon Age's single player world map transitions is rather complex and has to handle many special cases that depend on plot elements specific to the single player campaign, so BioWare never implemented a basic default - it would have had to be overridden completely anyway.&lt;br /&gt;
&lt;br /&gt;
Fortunately it's quite easy to add one, though there's a slight hitch; the area transition code needs to be split over two different events.&lt;br /&gt;
&lt;br /&gt;
* In EVENT_TYPE_BEGIN_TRAVEL you'll be able to get the target area and waypoint tags from the event object, and then call the &amp;lt;pre&amp;gt;WorldMapStartTravelling&amp;lt;/pre&amp;gt; function to cause the map to start animating the map trail path the player is following.&lt;br /&gt;
&lt;br /&gt;
* While the map trail animation is playing, the EVENT_TYPE_WORLDMAP_PRETRANSITION event is called. This is the event where you'll want to call the &amp;lt;pre&amp;gt;UT_DoAreaTransition&amp;lt;/pre&amp;gt; function to start the loading process of the destination area. The area will load at the same time that the map trail animation is playing, making the transition seem more seamless for the player. Note, however, that EVENT_TYPE_WORLDMAP_PRETRANSITION's event object ''doesn't'' contain the destination area and waypoint tags as members; you'll need to use local variables in the module's variable table to preserve these strings and pass them on from EVENT_TYPE_BEGIN_TRAVEL.&lt;br /&gt;
&lt;br /&gt;
The basic code to handle map travel, then, is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        ////////////////////////////////////////////////////////////////////////&lt;br /&gt;
        // Sent by: The engine&lt;br /&gt;
        // When: the player clicks on a destination in the world map&lt;br /&gt;
        ////////////////////////////////////////////////////////////////////////&lt;br /&gt;
        case EVENT_TYPE_BEGIN_TRAVEL:&lt;br /&gt;
        {&lt;br /&gt;
            string sSource = GetEventString(ev, 0); //area tag source location&lt;br /&gt;
            string sTarget = GetEventString(ev, 1); // area tag target location&lt;br /&gt;
            string sWPOverride = GetEventString(ev, 2); // waypoint tag override&lt;br /&gt;
            if (sSource != sTarget)&lt;br /&gt;
            {&lt;br /&gt;
                //store target area's tag to a local module variable&lt;br /&gt;
                SetLocalString(GetModule(), &amp;quot;WM_STORED_AREA&amp;quot;, sTarget);&lt;br /&gt;
                //store target waypoint tag&lt;br /&gt;
                SetLocalString(GetModule(), &amp;quot;WM_STORED_WP&amp;quot;, sWPOverride);&lt;br /&gt;
                //initiate the map's travelling animation. The engine will&lt;br /&gt;
                //send EVENT_TYPE_WORLDMAP_PRETRANSITION once it's started.&lt;br /&gt;
                WorldMapStartTravelling();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        ////////////////////////////////////////////////////////////////////////&lt;br /&gt;
        // Sent by: The engine&lt;br /&gt;
        // When: the world map has begun its &amp;quot;travelling&amp;quot; animation&lt;br /&gt;
        ////////////////////////////////////////////////////////////////////////&lt;br /&gt;
        case EVENT_TYPE_WORLDMAP_PRETRANSITION:&lt;br /&gt;
        {&lt;br /&gt;
            //retrieve the target area tag we stored in EVENT_TYPE_BEGIN_TRAVEL&lt;br /&gt;
            string sArea = GetLocalString(GetModule(), &amp;quot;WM_STORED_AREA&amp;quot;);&lt;br /&gt;
            //retrieve the target waypoint tag&lt;br /&gt;
            string sWP = GetLocalString(GetModule(), &amp;quot;WM_STORED_WP&amp;quot;);&lt;br /&gt;
            //execute the area transition to that target.&lt;br /&gt;
            UT_DoAreaTransition(sArea, sWP);&lt;br /&gt;
            break;&lt;br /&gt;
        }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We'll need to come back to the module script later on to add some plot-specific code, but for now this is all that's needed to enable a basic adventure to stand on its own.&lt;br /&gt;
&lt;br /&gt;
== Introductory cutscene ==&lt;br /&gt;
&lt;br /&gt;
After the player has finished character generation we play an introductory cutscene for him before the game starts.&lt;br /&gt;
&lt;br /&gt;
The cutscene itself is quite simple, consisting of a few camera movements and an actor (substituted by the player) playing a walking animation. See [[cutscene tutorial]] for how to create a cutscene.&lt;br /&gt;
&lt;br /&gt;
To make it play when the game begins we need to call it at the appropriate time with the CS_LoadCutscene function. The appropriate time has to be after the area that the cutscene is located in as loaded, otherwise the cutscene won't be able to play. The event that's best suited for this is EVENT_TYPE_AREALOAD_SPECIAL, which is called on an area's event script after the area has loaded but before any of the other game systems (AI and so forth) have been enabled. So in this case we want to insert the function call into the area script for the starting area, demo100ar_wilderness. We only want the cutscene to play the first time we enter this area so we've wrapped the function call in a plot flag check;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
case EVENT_TYPE_AREALOAD_SPECIAL:&lt;br /&gt;
        {&lt;br /&gt;
            if (!WR_GetPlotFlag(PLT_DEMO000PL_MAIN, DEMO_INTRO_COMPLETE))&lt;br /&gt;
            {&lt;br /&gt;
                CS_LoadCutscene(R&amp;quot;demo100ct_intro.cut&amp;quot;);&lt;br /&gt;
                WR_SetPlotFlag(PLT_DEMO000PL_MAIN, DEMO_INTRO_COMPLETE,TRUE); //sets the plot flag to ensure we don't repeat the intro cutscene.&lt;br /&gt;
            }&lt;br /&gt;
            break;&lt;br /&gt;
        }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== The main plot file ==&lt;br /&gt;
&lt;br /&gt;
For this demo module, all of the major events relating to the development of the plot are kept track of in the demo000pl_main plot file. This also allows for a centralized place to put scripting that deals with these events.&lt;br /&gt;
&lt;br /&gt;
The plot outline of the demo module is:&lt;br /&gt;
&lt;br /&gt;
#Player encounters the innkeeper outside his inn and speaks with him, receiving the quest to retrieve the innkeeper's sword.&lt;br /&gt;
#Player enters the inn. As he approaches the lever that will open the door to the room the sword is in, the bandit that's taken over the inn initiates conversation with the player. This leads to combat.&lt;br /&gt;
#Player pulls the lever, blowing up the door to the room the sword is in&lt;br /&gt;
#Player retrieves the sword&lt;br /&gt;
#Player returns the sword to the innkeeper, who offers to join the party. A new area also opens up on the world map at this point.&lt;br /&gt;
&lt;br /&gt;
We'll cover each of these events in a separate section of this documentation.&lt;br /&gt;
&lt;br /&gt;
You may also note that many of the constants used in the code have been separated out into a &amp;quot;demo_consts_h&amp;quot; script file, even if they are only currently used in one particular place. This is not strictly necessary, and in fact the toolset doesn't recognize the &amp;quot;_h&amp;quot; suffix as having any special significance; whenever you save an _h script the toolset will try to compile it and complain about the lack of a main() or StartingConditional() function (you can ignore this complaint). However, it makes typos much easier to find and debug, and should you need to change a constant later on this approach ensures that you can always catch every instance of it.&lt;br /&gt;
&lt;br /&gt;
== Giving the player an item ==&lt;br /&gt;
&lt;br /&gt;
The first thing that happens if the player talks to the barkeep and accepts the quest is that the barkeep will give him a key. The key is a &amp;quot;plot item&amp;quot;, meaning it will be shown in a separate section of the player's inventory and can't be given away or destroyed by the player, but the mechanism used here can give the player non-plot items as well.&lt;br /&gt;
&lt;br /&gt;
The function UT_AddItemToInventory takes a resource variable as its parameter. It causes a new instance of the item to be created and added. If you call it multiple times with the same resource, earlier copies won't be affected - multiple copies of the item will be created. You'll see one way of removing an object from the player's inventory at the end of the quest when the innkeeper takes back his sword.&lt;br /&gt;
&lt;br /&gt;
== Using a trigger to initiate conversation ==&lt;br /&gt;
&lt;br /&gt;
We want the bandit and his loyal patrons to attack the player before the lever can be pulled. A trigger has been placed in such a manner that the player will have to pass through it before reaching the lever; the trick is now to use that trigger to make the things we want to have happen, happen.&lt;br /&gt;
&lt;br /&gt;
When a trigger is entered by any entity the trigger's event script is sent an EVENT_TYPE_ENTER event. Note that this is sent ''every'' time the trigger is entered, by ''any'' entity, so the first thing we'll need to do in the event script is a test to ensure that the triggering entity is the player or one of his party members.&lt;br /&gt;
&lt;br /&gt;
The IsPartyMember function tests to see whether an object is player-controllable, which is true for the player's character and for any creature currently in the player's party. We call it on the event's creator to check if this is the right person; if it's not the event script does nothing.&lt;br /&gt;
&lt;br /&gt;
If we wanted the bandit and patrons to simply charge and attack the player, we'd have the trigger call UT_TeamGoesHostile(BANDIT_TEAM); directly (the bandit and patrons' creature templates are all set to the same team so that we don't need to set each one hostile individually). In this case an unexplained attack would be strange, so instead a conversation has been set up that has the bandit and patrons explain themselves before attacking. So we've set the trigger script to call UT_Talk instead.&lt;br /&gt;
&lt;br /&gt;
Once this has been called, we never want the trigger to fire again for anyone. It is important to note that setting a trigger to &amp;quot;inactive&amp;quot; will ''not'' work; an inactive trigger still fires EVENT_TYPE_ENTER whenever an entity enters it. There are several approaches that can be used here:&lt;br /&gt;
&lt;br /&gt;
*Set the event script to check the trigger's active status and not perform any action if it's inactive&lt;br /&gt;
*Use a plot flag to make the code only fire once&lt;br /&gt;
*call Safe_Destroy_Object(OBJECT_SELF, 0); to destroy the trigger entirely&lt;br /&gt;
&lt;br /&gt;
Since there will be no circumstances where we'll need the trigger to become active again in the future, destroying the trigger is the simplest and most foolproof way of accomplishing this.&lt;br /&gt;
&lt;br /&gt;
== Using a placeable to call a script ==&lt;br /&gt;
&lt;br /&gt;
The lever placeable has a &amp;quot;use&amp;quot; option that allows the player to flip it from one state to the other. When this happens an EVENT_TYPE_USE event is sent to the placeable's event script. We've added a custom event script to the lever to intercept this event and do something special; demo200pl_security_lever.nss.&lt;br /&gt;
&lt;br /&gt;
Rather than handling all the details of what should happen when the lever is pulled right in this script, though, we've instead put them into the main plot file's script. The custom placeable script serves only to set the appropriate main plot file flag.&lt;br /&gt;
&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Hydra1448</name></author>	</entry>

	</feed>