Character generation

From Dragon Age Toolset Wiki
Revision as of 09:35, 8 October 2010 by Proleric1 (Talk | contribs) (Importing a character from a saved game)

Jump to: navigation, search

Basics

A module with no event script will start the player without going through character generation, which will leave the player with an almost unusable character to play with. To send the player through a basic character generation UI use the below script as the module event script. This is done by first creating the below script, and saving it, then opening your module properties (file > manage modules > properties), and changing the "script" field to be whatever you named your script (hit the ellipsis and browse for it).

#include "events_h"
#include "global_objects_h"
 
void main()
{
    // keep track of whether the event has been handled
    int nEventHandled = FALSE; 
 
    event ev = GetCurrentEvent();
    switch(GetEventType(ev))
    {
         case EVENT_TYPE_MODULE_START:
         {
            // preloads resources needed for character generation
            PreloadCharGen(); 
 
            // initiates character generation
            StartCharGen(GetHero(),0); 
 
            break;
         }
    }
 
    // if this event wasn't handled by this script fall through to the core script
    if(!nEventHandled)
    {
        HandleEvent(ev, RESOURCE_SCRIPT_MODULE_CORE);
    }
}

Skipping Character Generation

A basic script that skips the character generation interface:

#include "sys_chargen_h"
#include "utility_h" 
 
void main()
{
    // keep track of whether the event has been handled
    int nEventHandled = FALSE; 
 
    event ev = GetCurrentEvent();
    switch(GetEventType(ev))
    {
        case EVENT_TYPE_MODULE_START:
        {
            object oHero = GetHero();
 
            // skip character generation
            Chargen_InitializeCharacter(oHero);
            Chargen_SelectGender(oHero, GENDER_MALE);
            Chargen_SelectRace(oHero, RACE_HUMAN);
            Chargen_SelectCoreClass(oHero, CLASS_WARRIOR);
            Chargen_SelectBackground(oHero, BACKGROUND_NOBLE);
 
            // give the player some equipment
            EquipItem(oHero, UT_AddItemToInventory(R"gen_im_arm_cht_lgt_rlr.uti"));
            EquipItem(oHero, UT_AddItemToInventory(R"gen_im_arm_bot_lgt_rlr.uti"));
            EquipItem(oHero, UT_AddItemToInventory(R"gen_im_arm_glv_lgt_rlr.uti"));
            EquipItem(oHero, UT_AddItemToInventory(R"gen_im_arm_shd_sml_wdn.uti"));
            EquipItem(oHero, UT_AddItemToInventory(R"gen_im_wep_mel_lsw_lsw.uti"));
 
            break;
        }
    }
 
    // if this event wasn't handled by this script fall through to the core script
    if(!nEventHandled)
    {
        HandleEvent(ev, RESOURCE_SCRIPT_MODULE_CORE);
    }
}

Another alternative is to create a template creature with the appropriate starting equipment and then call LoadItemsFromTemplate to copy it to the player:

         case EVENT_TYPE_MODULE_START:
         {
            object oHero = GetHero();
 
            // skip character generation
            Chargen_InitializeCharacter(oHero);
            Chargen_SelectRace(oHero, RACE_HUMAN);
            Chargen_SelectCoreClass(oHero, CLASS_WARRIOR);
            Chargen_SelectBackground(oHero, BACKGROUND_NOBLE);
 
            // give the player some equipment
            LoadItemsFromTemplate(oHero, "gcd_hero.utc", TRUE);
 
            break;
         }

It should be noted that, by skipping the internal character generation process that way, the character will have the correct stats but will be featureless and bald. To change that Bioware is working on an additional function to change the head morph via script.

Initial levelup or other modifications

If you want to increase the starting level a basic script can be created by merging one of the above with the following template:

// [additional includes goes here]
#include "sys_rewards_h"
 
const int FORCE_AUTOLEVEL = 2;
 
void main()
{
    // keep track of whether the event has been handled
    int nEventHandled = FALSE; 
 
    event ev = GetCurrentEvent();
    switch(GetEventType(ev))
    {
         case EVENT_TYPE_MODULE_START:
         {
            object oHero = GetHero();
 
            // [chargen code goes here]
 
            // auto-level the player to level 10
            RewardXP(oHero, RW_GetXPNeededForLevel(10), FALSE, FALSE);
            SetAutoLevelUp(oHero, FORCE_AUTOLEVEL);
 
            break;
         }
    }
 
    // if this event wasn't handled by this script fall through to the core script
    if(!nEventHandled)
    {
        HandleEvent(ev, RESOURCE_SCRIPT_MODULE_CORE);
    }
}

A more sophisticated script could include other set-up code, for example triggering an introductory cinematic to inform the player of the game's plot.

Importing a character from a saved game

We saw earlier how to invoke the basic chargen UI.

If you set the nImportEnabled parameter of StartCharGen, it enables importing a character from a saved game, and disables using a pre-generated character (which can crash if the campaign has custom backgrounds).

  StartCharGen(GetHero(), 0, TRUE);

The player still has the option to make a new character from scratch in the UI.

When the player decides to import from a saved game, the CHARGEN_IMPORT_HERO event can be intercepted in the module script, so the imported character can be modified.

By default, the character might be very high level, with a powerful inventory and lots of gold. In the following example, we revert to level 1, remove all possessions, and load the default inventory.

The example also assumes that the campaign has a custom background, for which an integer constant BACKGROUND_FOUNDLING has been defined.

case EVENT_TYPE_CHARGEN_IMPORT_HERO:
  {
    object oHero = GetHero(); 
    int nGender = GetCreatureGender(oHero); 
    int nRace = GetCreatureRacialType(oHero);
    int nclass = GetCreatureCoreclass(oHero);
    int nBackground = BACKGROUND_FOUNDLING;
    int nEquipIndex = Chargen_GetEquipIndex(nRace, nclass, nBackground);
 
    // Reset to level 1
 
    Chargen_InitializeCharacter(oHero);
    Chargen_SelectGender (oHero, nGender);
    Chargen_SelectRace (oHero, nRace);
    Chargen_SelectCoreclass (oHero, nclass); 
    Chargen_SelectBackground(oHero, nBackground); 
 
    // Reset inventory and gold
 
    Chargen_InitInventory (oHero, nclass, nEquipIndex);
    SetCreatureMoney(0, oHero);
  }

N.B. This example is rather crude, because the player has no opportunity to finesse their character build - it's like doing a Quick Start in the UI. For this reason, some builders will prefer to allow the character to remain high-level, and design the campaign to scale to that scenario.

Since there is only one custom background in this example, it is simply assigned. More work is needed to establish how to handle multiple custom backgrounds - for example, the player might select a background in conversation.

Modifying the morph-generating step of character generation

See Chargenmorphcfg.xml for information about how to modify this step of character generation.