Character generation

From Dragon Age Toolset Wiki
(Redirected from Character creation)
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. Unfortunately there is no 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 the nImportEnabled parameter of StartCharGen is set, it enables importing a character from a saved game. This also disables using a character made with the standalone Character Creator (which can crash if the campaign has custom backgrounds).

  int nImportEnabled = TRUE;
 
  StartCharGen(GetHero(), 0, nImportEnabled);

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);
 
    // Allow the player to finesse the character build using Level Up
 
    SetCanLevelUp(oHero, TRUE);
  }

Since there is only one custom background in this example, it is simply assigned.

If regression to level 1 is not required, or there are multiple custom backgrounds, the builder will probably need to examine Chargen_SelectBackground, with a view to making a custom function that doesn't change abilities etc. Background selection from a list might be achieved in conversation at the start of gameplay.

Imported Plots & Codex

An imported character retains plot flag settings from the previous campaign.

This probably isn't an issue, because none of the old plots appear in the journal. Codex slots only appear for codex plots which are used in the new campaign.

The risk of a duplicate plot GUID is presumably negligible.

Of course, creature codex entries will be unlocked for creatures encountered in the old campaign. If that's inappropriate, change or delete the Codex Plot entry in the APR_base 2DA for the creatures in question.

Modifying the morph-generating step of character generation

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