PDA

View Full Version : Tutorial [Beginner coding]: Traits



alpaca
01-09-2007, 22:06
I actually wanted to start writing a few tutorials for MTW2 earlier, but you know how it is, something else leaps in every time.

So, I think I'll start a batch of tutorials with the basics. These can be quoted or linked to in modding questions or more advanced tutorials. But please don't mirror them (this is required in order to have discussion go on in a single thread)
All of these tutorials will carry a tag that signifies the required skill level for using them, too, so that new modders know where to start.
Most of them will also have a prerequisite section before the actual tutorial, that contains other threads and tutorials the apt reader should have under his belly beforehand.
To be easily accessible, I will also add them to the Tutorials DB (https://forums.totalwar.org/vb/forumdisplay.php?f=146)


Ok, enough of the pre-speech:

Prerequisites

In order to be able to follow this tutorial, you should be confident with the following:
- Either the files released by CA(here (https://forums.totalwar.org/vb/showthread.php?t=73971)) or the files export_descr_character_traits.txt, export_descr_ancillaries.txt, text/export_VnVs.txt and text/export_ancillaries.txt unpacked from the packs - for the latter two you need to convert them from the unpacked .strings.bin files using my .strings.bin converter (https://forums.totalwar.org/vb/showthread.php?t=75229)
- A working mod folder, or a config using file_first. See this tutorial (https://forums.totalwar.org/vb/showthread.php?t=76289) for instructions

Character Traits

One of the most important factors for immersion, as well as completely governing the character's attributes, are the personality traits (also referred to as Vices and Virtues sometimes).
You all know them from the game, prominent examples are GoodCommander, Noctophilia, GoodDiplomat and GoodPrincess.

Now, how do you edit those? Well the first step I'd always propose to a newbie, is to have a good look at the associated files, in this case export_descr_character_traits.txt and text/export_VnVs.txt, and try to make sense out of what you see there. If you get stuck with anything, you can return here for some explanations.

Go on ahead, do that now :)


Are you still here?


MOVE IT, OPEN THOSE FILES!:whip:






1. Overview

Well, I assume you had a good look at those files (if you didn't, scroll back up a bit and read again carefully), so I'll start explaining them now.

Each trait consists of these entities in export_descr_character_traits.txt:
- A trait definition
- One or more trait levels
- zero or more triggers that actually award the trait

Further, each trait level has a few (at least three) entries in text/export_VnVs.txt that determine which text actually shows up in the game (and is localised).

In the following tutorial, I will explain these points one by one. I hope you will enjoy it and, above all, learn something.


2. The Trait Definition

The trait definition is the first part of the trait that you see when looking at export_descr_character_traits.txt (from now on, edct), it always starts with the keyword Trait (<~~ keywords are always blue), followed by the internal trait name, the scope (keyword Characters) and then some settings. I will explain these later, but let's first have a look at a basic example:

Trait VictorVirtue
Characters family
Well, obviously, this is as easy as it gets. This describes the Trait line VictorVirtue (found in line 1436), a trait which is accessible to all family members (which means only male named generals).
As you can see, the Characters keyword governs which character types have access to the trait you are editing.

For more information on the Characters keyword, click on show:
Allowed values are: family, all, princess, admiral, spy, diplomat, assassin, merchant, inquisitor, priest, heretic, witch

It also accepts comma-separated list, so this example will be available for all religious agents:

Trait GoodDenouncer
Characters inquisitor, priest, heretic

2.1 Settings

The trait header also allows you to set some optional flags. However, they have to be used in a specific order or the game will crash. For more information on these, click on show:
If you in fact looked at the definition for GoodDenouncer in edct, you'll have noticed that it reads in full:
Trait GoodDenouncer
Characters inquisitor, priest, heretic
AntiTraits BadDenouncer
So, what does AntiTraits do?
Well, for this example:
If you gain a point in GoodDenouncer, if the character already has BadDenouncer, instead of gaining the GoodDenouncer trait, the character loses one point in the BadDenouncer trait.

This keyword again accepts a comma-separated list of AntiTraits, in which case an increase in Trait will result in a decrease of 1 point in each Anti-Trait if applicable.

At least, that's the theory.
However, due to a bug, how it actually works is (if you are a beginner, please proceed with the tutorial, and return to this later):
Assume you have a Trait A with AntiTraits B.
Then, if you gain points in B, you lose them in A (if you have some points in A) unless that would result exactly in the loss of a level in A -
in that case, you lose all levels in A.

Still not understood? Here's an example:
Imagine the following situation:
You have a princess with the GoodPrincess trait at level 2 (2 points). She fails a diplomacy mission and gets one point in BadPrincess. Now, instead of simply going back to GoodPrincess level 1 (which would happen if she simply lost a point), she loses all points in GoodPrincess.

A possible workaround if you don't use NoGoingBackLevel is apparently to have a NoGoingBackLevel that is higher than your highest trait level.


The other settings are:

ExcludeCultures
Well this does what it says on the box. If you specify one or more cultures here, characters of that culture won't be able to get this trait.
You can the culture list in descr_cultures.txt and the factions assoctiated to them in descr_sm_factions.txt

NoGoingBackLevel
This can be a very useful keyword. Basically, after the character has reached a certain level in a trait (see below), he won't be able to revert below that level again (although above it, the system works normally)

Hidden
If you give a trait this keyword, it won't show up in the character details scroll. This can be very useful for triggering traits on prerequisite traits, for example.

As I mentioned before, be careful to apply these settings in the following order (having some missing in between is no problem though):
ExcludeCultures
NoGoingBackLevel
Hidden
AntiTraits ToDo: confirm this


3. Levels

As you hopefully saw while browsing through edct, each trait consists of multiple sub-entries, the so-called trait levels.
Each trait will successively go through the trait levels when points are assigned to it. How fast it reaches the next level is determined by the Threshold keyword, but you can read more about that below.

The basic skeleton for a trait level is:

Level Unproven_Commander
Description Unproven_Commander_desc
EffectsDescription Unproven_Commander_effects_desc
Threshold 2

Effect Command -1

Now, what do these do?
Before I tell you any more, please have a look again at text/export_VnVs.txt (I will refer to that file as eve from now on).
In this file, you will be able to find all of the above entries, except for Threshold and Effect.
This means that half of what the trait level definition does is to control which text appears in the game for the trait:

Level: What follows this keyword is the internal name of the trait level. This has to have an entry in eve, which is what the player can directly see in the character details scroll.

Description: This is the internal tag for the trait description (or tooltip) - again, this has to match an entry in eve

EffectsDescription: This describes the tag for the effects description in eve. In our example, it is "-1 Command"

Other allowed entries that describe things in eve are:
GainMessage:: When a character gets this trait level, a message is posted to the player via the game's message system (trait gained messages)

LoseMessage: The same as GainMessage, only the other way around

Epithet: This is the tag for the things like "the Mighty" which replace a character's surname. They will be activated when the character gains this trait level and the epithet shown will always be the last one he gained.


Threshold: One of the most important entries for each level. In short, this governs how many cumulative points in this trait a character must have gained to bear this level.
In case you didn't understand this, take an example (the full GoodCommander trait):

Trait GoodCommander
Characters family

Level Promising_Commander
Description Promising_Commander_desc
EffectsDescription Promising_Commander_effects_desc
GainMessage Promising_Commander_gain_desc
Threshold 1

Effect Command 1

Level Aspiring_Commander
Description Aspiring_Commander_desc
EffectsDescription Aspiring_Commander_effects_desc
GainMessage Aspiring_Commander_gain_desc
Threshold 2

Effect Command 2

Level Proven_Commander
Description Proven_Commander_desc
EffectsDescription Proven_Commander_effects_desc
GainMessage Proven_Commander_gain_desc
Threshold 4

Effect Command 3

Level Great_Commander
Description Great_Commander_desc
EffectsDescription Great_Commander_effects_desc
GainMessage Great_Commander_gain_desc
Threshold 8

Effect Command 4

Level Legendary_Commander
Description Legendary_Commander_desc
EffectsDescription Legendary_Commander_effects_desc
GainMessage Legendary_Commander_gain_desc
Epithet Legendary_Commander_epithet_desc
Threshold 16

Effect Command 5
Leaving the effects out of our consideration for now, what do the Threshold values mean?
Well, it goes like this: The character gets one point, then he goes to Promising_Commander. He gets one other point and goes to Aspiring_Commander. The next two points and he advances to Proven_Commander and so forth.
I think you get the idea

Effect: Ah, the all-important effects. This is the other half of what the trait definition does, and, in essence, the more important one.
The quite easy basic idea behind this keyword is, that each accessible character attribute has a numerical value assigned to it. This numerical value is exclusively influenced by traits and ancillaries, through the Effect statement.
Allowed attributes are:
Combat_V_Religion_x, Combat_V_Faction_x, BattleSurgery, TrainingAnimalUnits, HitPoints, BodyguardValour, Looting, Law, Unrest, Squalor, ArtilleryCommand, GunpowderCommand, InfantryCommand, CavalryCommand, Fertility, TaxCollection, Mining, Farming, FootInTheDoor, LocalPopularity, Trading, Construction, TrainingAgents, TrainingUnits, LineOfSight, Electability, BribeResistance, Bribery, PublicSecurity, PersonalSecurity, NightBattle, SiegeEngineering, NavalCommand, Ambush, SiegeDefence, SiegeAttack, Defence, MovementPoints, TroopMorale, Subterfuge, Management, BodyguardSize, Generosity, Boldness, Disposition, Violence, Purity, Eligibility, Sabotage, Assassination, Authority, HeresyImmunity, Unorthodoxy, Piety, Finance, Charm, Influence, Command, Loyalty

Combat_V_Religion_x: Replace "x" with a religion name (christian, muslim, ...) here
Combat_V_Faction_x: Replace "x" with a faction name (england, france, ...) here


4. Text entries

After creating the trait levels, what still remains to do is opening text/export_VnVs.txt and adding the appropriate text entries.
All entries in this file consist of a tag (in curly brackets) and the localized screen text.

The first thing you have to add is a title for each level.
Then you should add all entries that you described for each level, which usually includes the trait description (mouse-over details text) and effects description (the last line in the mouse-over text) and can include an epithet (things like "the Conqueror" displayed after the name), a gain-message and a lose-message. For example, for the LegendaryCommander level (the highest level of the GoodCommander chain), it looks like this:

&#172;--------------------

{Legendary_Commander} Legendary Commander

{Legendary_Commander_desc}
Countless victories have made this man is a legendary commander, respected by both his own troops and those that oppose him.

{Legendary_Commander_gain_desc}
This great field general has earned another Command star, his continued success not going unrecognised.

{Legendary_Commander_epithet_desc} the Mighty

{Legendary_Commander_effects_desc}
+5 Command
This is all fairly straightforward, and I think you can figure the rest out yourself. Just be aware that by setting the same tag in the level description, you can use the same text for different levels. I usually have a tag called
{no_effect}
No effect
I link all trait levels without effect (they can be useful when you just want to show the player something, for example) to this tag by supplying
EffectsDescription no_effect


Well this is it for the tutorial on traits. You know everything you need to know about the trait definition - now please proceed to the trigger tutorial (https://forums.totalwar.org/vb/showthread.php?p=1380385) to get some info about the second part of the file.

pevergreen
01-15-2007, 14:19
Hmmmm, very good, methinks.

Will come in very useful for Warcraft: Total War.

I thank you for such a detailed tutorial.

But with your Anti Traits section


A possible workaround if you don't use NoGoingBackLevel is apparently to have a NoGoingBackLevel that is higher than your highest trait level.
Is that confirmed?

alpaca
01-15-2007, 17:48
Is that confirmed?
Weeelll... more or less. I only tested it for a few minutes and can't really be sure if everything works.
I also discovered a problem with the NoGoingBackLevel I'll have to work into this tutorial when I have time... It only works properly if you go exactly one point below it - if you go further below it, it becomes all bugged.

DrIstvaan
02-06-2007, 22:58
Alpaca, you're a master in these things, thus I seek your help.
I want to create some new traits, which give agents boni to their skill based on the level of the building they came from (p.e. a Merchant from a city with Great Market gains at creation "Experienced Merchant" trait, giving him 2 Finance).
I've created the traits in the "first part", the corrisponding triggers in the "second", and the neccessary entries in export_descr_VnV_enums and EVE. Here comes the problem: when I try to fire up my game, it quits right at the startup (before loading the main menu). Do you happen to know what can that be a "symptom" of?

Roberts
02-06-2007, 23:09
Wonderful stuff, alpaca.
I am sure it will be very helpful for Org's members to get familiar with M2 code language and the whole structure.
You are doing great job here.

DrIstvaan
02-07-2007, 16:54
OK, I've managed to solve the problem, so my previous post is obsolete.

billydilly
02-25-2007, 00:15
@ DrIstvaan

Hi! How did you solve the problem? I have the same problem, I added some titles, Count of Copenhagen etc to a big map, but the game quits just as you said...

Tek Jansen
06-07-2008, 09:04
@ DrIstvaan

Hi! How did you solve the problem? I have the same problem, I added some titles, Count of Copenhagen etc to a big map, but the game quits just as you said...
I know it's a bit lit to help you, but this might be helpful for someone new..

When you add new traits to export_descr_character_traits.txt, don't add new traits at the very bottom of the file. The export_descr_character_traits.txt file contains traits and triggers. The triggers begin around line 10,200. You can add new traits under the last trait but above the lines that say...


;===============================================================
;== TRIGGER DATA STARTS HERE ==
;===============================================================
Then you shouldn't get any errors.

Banzai!
02-10-2009, 19:24
I know it's a bit lit to help you, but this might be helpful for someone new..

When you add new traits to export_descr_character_traits.txt, don't add new traits at the very bottom of the file. The export_descr_character_traits.txt file contains traits and triggers. The triggers begin around line 10,200. You can add new traits under the last trait but above the lines that say...


;===============================================================
;== TRIGGER DATA STARTS HERE ==
;===============================================================
Then you shouldn't get any errors.

Damn so that's what I was doing wrong.

Resurrection
01-26-2012, 17:05
Sorry for necroing this tut but I found out that the trait flags mentioned above are actually in incorrect order and if used as mentioned the game CTDs on campaign start-up.

Correct order is:

Hidden
ExcludeCultures
NoGoingBackLevel
AntiTraits