Author Topic: Create CRE Example please?  (Read 1556 times)

Offline Bill Bisco

  • Planewalker
  • *****
  • Posts: 30
Create CRE Example please?
« on: April 23, 2016, 04:44:42 PM »
Could someone kindly create some sample code using Create Cre?  I am intrigued at the possibilities and ease of editing code values directly but I don't know how to proceed with no examples.

Specifically,  I'd like to create joinable NPC CRE from scratch and then make modified copies of that Cre to account for various level up choices.

Sincerely,

Bill

« Last Edit: April 23, 2016, 07:17:49 PM by Bill Bisco »

Offline Wisp

  • Moderator
  • Planewalker
  • *****
  • Posts: 1176
Re: Create CRE Example please?
« Reply #1 on: April 23, 2016, 06:11:29 PM »
CREATE by itself is not much of a time-saver when dealing with CREs. Making the creature is easy compared to configuring it.

Code: [Select]
  CREATE CRE mycre
would create the file mycre.cre in the override. However, while mycre.cre is a structurally valid CRE, it lacks everything else: class, race, HP, animation, you name it. To give mycre.cre these properties, you would have to apply one or more patches.

Code: [Select]
  CREATE CRE mycre
    SAY NAME1 ~Jill~
    SAY NAME2 ~Jill~
    ADD_CRE_ITEM ~sw1h04~ #0 #0 #0 identified weapon EQUIP
would create mycre.cre and patch it to have the name "Jill" and to have a longsword equipped in its weapon slot. SAY and ADD_CRE_ITEM are examples of a patches one might apply to a newly CREATEd creature. Several other aspects can fairly easily configured, such as gender, race, scripts and dialogue file. But there is a lot more to creating a viable CRE than this, and many of these aspects are quite less easily dealt with. I have an older project I should perhaps dust off for this.

Offline Bill Bisco

  • Planewalker
  • *****
  • Posts: 30
Re: Create CRE Example please?
« Reply #2 on: April 23, 2016, 07:31:02 PM »
I'm aware of ADD_CRE_ITEM  as there is documentation for that.

But yes, how would you patch all of the other cre file information?

Str, Dex, Con, etc. Save vs. Breath Gender, Kit, Race, Gold, XP value, Script, Dialogue, Animation, Colors, etc.  There's a lot!

Sincerely,

Bill

Offline Mike1072

  • Planewalker
  • *****
  • Posts: 298
  • Gender: Male
Re: Create CRE Example please?
« Reply #3 on: April 23, 2016, 09:49:15 PM »
Check the IESDP CRE v1 page to see the offsets those values are defined at.

Dexterity is at offset 0x023c and is 1 byte long, so you could set it to 18 like this:
Code: [Select]
WRITE_BYTE  0x23c 18
Dialog is at offset 0x02cc and is 8 bytes of text, so you could set it to BILLB like this:
Code: [Select]
WRITE_ASCII 0x2cc ~BILLB~ #8
Animation is at offset 0x0028 and is 4 bytes long, so you could set it to THIEF_MALE_HUMAN like this:
Code: [Select]
WRITE_LONG  0x028 0x6300
Setting the kit is a little trickier - you want to set the value to match the entry in KIT.IDS (in BGEE, KITLIST.2DA also shows the value in the the KITIDS column of KITLIST.2DA).  So long as you're not dealing with one of the mage specialist kits, wild mages, or barbarians, the pattern is straightforward.  The entry for Swashbuckler is 0x0000400C.  In the .CRE file, however, that value has to be written with the two halves swapped and the position of the two bytes in each half swapped, so it looks like 00 00 0C 40.

Kit is at offset 0x0244, so you could set it to Swashbuckler (0x0000400C) like this:

Code: [Select]
WRITE_SHORT 0x244 0
WRITE_BYTE  0x246 0x0C
WRITE_BYTE  0x247 0x40

Offline Bill Bisco

  • Planewalker
  • *****
  • Posts: 30
Re: Create CRE Example please?
« Reply #4 on: April 27, 2016, 09:33:20 PM »
Thank you Mike1072,  I used that webpage as a starting point for understanding.  A couple of questions to help me understand:

8 (resref)  should be coded as WRITE_ASCII
1 (byte) should be coded as WRITE_BYTE
4 (dword) should be coded as WRITE_LONG

How would you code the below?

4 (char array)
1 (signed byte)
2 (signed word)
32 (char array)
4*100 (Strref*100)
2 (word)

I wrote the following code so far:

CREATE CRE Erevain
    WRITE_SHORT 0x0004 ~~ // Signature ('CRE')  (I assume this can be left blank?) 4 (char array)
    WRITE_SHORT 0x0004 ~V1.0~ // Version ('V1.0') 4 (char array)
    SAY NAME1 ~Erevain~ // Name 4 (strref)
    SAY NAME2 ~Erevain~ // Tooltip 4 (strref)
    WRITE_LONG 0x0010 ~~ // Flags (I assume blank is no flag?  How would I choose Permanent Corpse (Flag 2)? 4 (dword)
    WRITE_LONG 0x0014 ~90~ // XP Gained for Killing Creature 4 (dword)
    WRITE_LONG 0x0018 ~3~ // Creature Power Level (for summoning spells) / XP of the creature (for party members) 4 (dword)
    WRITE_LONG 0x001c ~81~ // Gold Carried 4 (dword)

I assume that a Created CRE goes to the Override?

Offline Mike1072

  • Planewalker
  • *****
  • Posts: 298
  • Gender: Male
Re: Create CRE Example please?
« Reply #5 on: April 27, 2016, 10:18:48 PM »
Most data is numerical.  For that, use WRITE_BYTE if the size of the field is 1, WRITE_SHORT if the size of the field is 2, and WRITE_LONG if the size of the field is 4.

Strrefs are numerical and can be written with WRITE_LONG, but that's only if the text you want is already in the game and you know its strref.  Using SAY to insert the strref of text you provide is much more common.

For bit fields (like flags), that's a single number comprised of a number of bits used to store multiple pieces of information at once.  You write to that the same as to other numbers, but there are special commands to help you set and retrieve individual bits.  If no bits are set, the value of the number is 0.  If you want to set just bit 2, you can use the built-in WeiDU variable BIT2 (e.g. WRITE_LONG 0x10 BIT2).  If you want to set multiple bits, you can perform a bitwise OR, so to set bits 2 and 3, you would use WRITE_LONG 0x10 (BIT2 | BIT3) or the longer WRITE_LONG 0x10 (BIT2 BOR BIT3).  For more information on bitwise operations, check out this tutorial.

For textual data (like 'CRE ' or 'V1.0'), use WRITE_ASCII.  The signature field might be read by something to determine what sort of file it is, so I would not leave that blank.

For the types you listed, "char array" is text.  There are some places where "char" is used to mean single bytes of numerical data, so don't get confused by that.  The 4*100 (strref*100) is not a single field, it's 100 different fields, all of which are strrefs.  If a byte/word is signed, it means it accepts negative values.

As a stylistic choice, I avoid using string delimiters for numerical data (e.g. I'd use WRITE_LONG 0x14 90 instead of WRITE_LONG 0x14 ~90~), but either way is fine.
« Last Edit: April 27, 2016, 10:21:09 PM by Mike1072 »

Offline Bill Bisco

  • Planewalker
  • *****
  • Posts: 30
Re: Create CRE Example please?
« Reply #6 on: May 01, 2016, 08:03:46 AM »
Thank you Mike1072 for your helpful notes.  Using the website link you provided I wrote the following code to try to fill in every category:

Code: [Select]
CREATE CRE Erevain // Cre File format found at http://gibberlings3.net/iesdp/file_formats/ie_formats/cre_v1.htm
    WRITE_ASCII 0x0004 ~CRE~ // Signature ('CRE') 4 (char array)
    WRITE_ASCII 0x0004 ~V1.0~ // Version ('V1.0') 4 (char array)
    SAY NAME1 ~Erevain~ // Name 4 (strref)
    SAY NAME2 ~Erevain~ // Tooltip 4 (strref)
    WRITE_LONG 0x0010 ~~ // Flags 4 (dword) (Use 0x0010 BIT2 for Flag2 (Permanent Corpse).  Use WRITE_LONG 0x10 (BIT2 | BIT3) for 2 flags  See http://gibberlings3.net/forums/index.php?showtopic=314
    WRITE_LONG 0x0014 90 // XP Gained for Killing Creature 4 (dword)
    WRITE_LONG 0x0018 3 // Creature Power Level (for summoning spells) / XP of the creature (for party members) 4 (dword)
    WRITE_LONG 0x001c 81 // Gold Carried 4 (dword)
    WRITE_LONG 0x0020 ~~ // Permanent status flags (STATE.IDS) 4 (dword)
    WRITE_SHORT 0x0024 21 // Current Hit Points 2 (word)
    WRITE_SHORT 0x0026 21 // Maximum Hit Points 2 (word)
    WRITE_LONG 00x0028 0x6101 // Animation ID (ANIMATE.IDS) 4 (dword) Find these at http://gibberlings3.net/iesdp/files/ids/bg2/animate.htm or IWD Equivalent
    WRITE_BYTE 0x002c 30 // Metal Color Index 1 (byte)
    WRITE_BYTE 0x002d 66 // Minor Color Index 1 (byte)
    WRITE_BYTE 0x002e 57 // Major Co1or Index 1 (byte)
    WRITE_BYTE 0x002f 17 // Skin Color Index 1 (byte)
    WRITE_BYTE 0x0030 58 // Leather Color Index 1 (byte)
    WRITE_BYTE 0x0031 31 // Armor Color Index 1 (byte)
    WRITE_BYTE 0x0032 25 // Hair Color Index 1 (byte)
    WRITE_BYTE 0x0033 0 // Effect Flag 1 (byte)
    WRITE_ASCII 0x0034  // Small Portrait (BMP) 8 (resref)
    WRITE_ASCII 0x003c  // Large Portrait (BMP) 8 (resref)
    WRITE_BYTE 0x0044 0 // Reputation (minimum value: 0)  1 (signed byte)
    WRITE_BYTE 0x0045 0 // Hide in Shadows 1 (byte)
    WRITE_BYTE 0x0046 2 // Armor Class (Natural) 1 (signed byte)
    WRITE_SHORT 0x0048 2 // Armor Class (Effective) 2 (signed word)
    WRITE_SHORT 0x004a 4 // Armor Class (Crushing Attacks Modifier) 2 (signed word)
    WRITE_SHORT 0x004c 0 // Armor Class (Missile Attacks Modifier) 2 (signed word)
    WRITE_SHORT 0x004e 0 // Armor Class (Piercing Attacks Modifier) 2 (signed word)
    WRITE_BYTE 0x0050 -2 // Armor Class (Slashing Attacks Modifier) 1 (signed byte)
    WRITE_BYTE 0x0052 18 // THAC0 (1-25)  1 (byte)
    WRITE_BYTE 0x0053 2 // Number of attacks (0-10) 1 (byte)
    WRITE_BYTE 0x0054 13 // Save versus death (0-20) 1 (byte)
    WRITE_BYTE 0x0055 15 // Save versus wands (0-20) 1 (byte)
    WRITE_BYTE 0x0056 14 // Save versus polymorph (0-20) 1 (byte)
    WRITE_BYTE 0x0057 16 // Save versus breath attacks (0-20) 1 (byte)
    WRITE_BYTE 0x0058 16 // Save versus spells (0-20) 1 (byte)
    WRITE_BYTE 0x0059 0 // Resist fire (0-100) 1 (byte)
    WRITE_BYTE 0x005a 0 // Resist cold (0-100) 1 (byte)
    WRITE_BYTE 0x005b 0 // Resist electricity (0-100) 1 (byte)
    WRITE_BYTE 0x005c 0 // Resist acid (0-100) 1 (byte)
    WRITE_BYTE 0x005d 0 // Resist magic (0-100) 1 (byte)
    WRITE_BYTE 0x005e 0 // Resist magic fire (0-100) 1 (byte)
    WRITE_BYTE 0x005f 0 // Resist magic cold (0-100) 1 (byte)
    WRITE_BYTE 0x0060 0 // Resist slashing (0-100) 1 (byte)
    WRITE_BYTE 0x0061 0 // Resist crushing (0-100) 1 (byte)
    WRITE_BYTE 0x0062 0 // Resist piercing (0-100) 1 (byte)
    WRITE_BYTE 0x0063 0 // Resist missile (0-100) 1 (byte)
    WRITE_BYTE 0x0064 0 // Detect illusion (minimum value: 0) 1 (byte)
    WRITE_BYTE 0x0065 0 // Set Traps 1 (byte)
    WRITE_BYTE 0x0066 0 // Lore (0-100)* 1 (byte)
    WRITE_BYTE 0x0067 0 // Lockpicking (minimum value: 0) 1 (byte)
    WRITE_BYTE 0x0068 0 // Stealth (minimum value: 0) 1 (byte)
    WRITE_BYTE 0x0069 0 // Find/disarm traps (minimum value: 0) 1 (byte)
    WRITE_BYTE 0x006a 0 // Pick pockets (minimum value: 0) 1 (byte)
    WRITE_BYTE 0x006b 0 // Fatigue (0-100) 1 (byte)
    WRITE_BYTE 0x006c 0 // Intoxication (0-100) 1 (byte)
    WRITE_BYTE 0x006d 0 // Luck 1 (byte)
    WRITE_BYTE 0x006e 3 // (unused in BG2) Large swords proficiency (Proficiencies maybe be packed into 3-bit chunks for the primary and secondary classes) 1 (byte)
    WRITE_BYTE 0x006f 0 // (unused in BG2) Small swords proficiency (Proficiencies maybe be packed into 3-bit chunks for the primary and secondary classes) 1 (byte)
    WRITE_BYTE 0x0070 1 // (unused in BG2) Bows proficiency (Proficiencies maybe be packed into 3-bit chunks for the primary and secondary classes) 1 (byte)
    WRITE_BYTE 0x0071 0 // (unused in BG2) Spears proficiency (Proficiencies maybe be packed into 3-bit chunks for the primary and secondary classes) 1 (byte)
    WRITE_BYTE 0x0072 0 // (unused in BG2) Blunt proficiency (Proficiencies maybe be packed into 3-bit chunks for the primary and secondary classes) 1 (byte)
    WRITE_BYTE 0x0073 0 // (unused in BG2) Spiked proficiency (Proficiencies maybe be packed into 3-bit chunks for the primary and secondary classes) 1 (byte)
    WRITE_BYTE 0x0074 0 // (unused in BG2) Axe proficiency (Proficiencies maybe be packed into 3-bit chunks for the primary and secondary classes) 1 (byte)
    WRITE_BYTE 0x0075 0 // (unused in BG2) Missile proficiency (Proficiencies maybe be packed into 3-bit chunks for the primary and secondary classes) 1 (byte)
    WRITE_BYTE 0x0076 3 // (unused in BG2) Unknown proficiency (Proficiencies maybe be packed into 3-bit chunks for the primary and secondary classes) 1 (byte)
    WRITE_BYTE 0x0077 0 // (unused in BG2) Unknown proficiency (Proficiencies maybe be packed into 3-bit chunks for the primary and secondary classes) 1 (byte)
    WRITE_BYTE 0x0078 0 // (unused in BG2) Unknown proficiency (Proficiencies maybe be packed into 3-bit chunks for the primary and secondary classes) 1 (byte)
    WRITE_BYTE 0x0079 0 // (unused in BG2) Unknown proficiency (Proficiencies maybe be packed into 3-bit chunks for the primary and secondary classes) 1 (byte)
    WRITE_BYTE 0x007a 0 // (unused in BG2) Unknown proficiency (Proficiencies maybe be packed into 3-bit chunks for the primary and secondary classes) 1 (byte)
    WRITE_BYTE 0x007b 0 // (unused in BG2) Unknown proficiency (Proficiencies maybe be packed into 3-bit chunks for the primary and secondary classes) 1 (byte)
    WRITE_BYTE 0x007c 0 // (unused in BG2) Unknown proficiency (Proficiencies maybe be packed into 3-bit chunks for the primary and secondary classes) 1 (byte)
    WRITE_BYTE 0x007d 0 // (unused in BG2) Unknown proficiency (Proficiencies maybe be packed into 3-bit chunks for the primary and secondary classes) 1 (byte)
    WRITE_BYTE 0x007e 0 // (unused in BG2) Unknown proficiency (Proficiencies maybe be packed into 3-bit chunks for the primary and secondary classes) 1 (byte)
    WRITE_BYTE 0x007f 0 // (unused in BG2) Unknown proficiency (Proficiencies maybe be packed into 3-bit chunks for the primary and secondary classes) 1 (byte)
    WRITE_BYTE 0x0080 0 // (unused in BG2) Unknown proficiency (Proficiencies maybe be packed into 3-bit chunks for the primary and secondary classes) 1 (byte)
    WRITE_BYTE 0x0081 0 // (unused in BG2) Unknown proficiency (Proficiencies maybe be packed into 3-bit chunks for the primary and secondary classes) 1 (byte)
    WRITE_BYTE 0x0082 0 // Turn undead level 1 (byte)
    WRITE_BYTE 0x0083 0 // Tracking skill (0-100) 1 (byte)
    WRITE_BYTE 0x0084  // Tracking target 32 (char array)
    WRITE_BYTE 0x00a4  // Strrefs pertaining to the character. Most are connected with the sound-set (see SOUNDOFF.IDS (BG1) http://gibberlings3.net/iesdp/files/ids/bg1/soundoff.htm and SNDSLOT.IDS for (BG2) http://gibberlings3.net/iesdp/files/ids/bg2/sndslot.htm). 4*100 (Strref*100)
    WRITE_BYTE 0x0234 3 // Highest attained level in class (0-100). For dual/multi class characters, the levels for each class are split between 0x0234, 0x0235 and 0x0236 according to the internal class name, i.e. for a FIGHTER_THIEF 0x0234 will hold the fighter level, 0x0235 will hold the thief level and 0x0236 will be 0. 1 (byte)
    WRITE_BYTE 0x0235 1 // Highest attained level in class (0-100) 1 (byte)
    WRITE_BYTE 0x0236 1 // Highest attained level in class (0-100) 1 (byte)
    WRITE_BYTE 0x0237 1 // Sex (from gender.ids) - checkable via the sex stat 1 (byte)
    WRITE_BYTE 0x0238 17 // Strength (1-25) 1 (byte)
    WRITE_BYTE 0x0239 0 // Strength % Bonus (0-100)  1 (byte)
    WRITE_BYTE 0x023a 11 // Intelligence (1-25) 1 (byte)
    WRITE_BYTE 0x023b 12 // Wisdom (1-25) 1 (byte)
    WRITE_BYTE 0x023c 16 // Dexterity (1-25) 1 (byte)
    WRITE_BYTE 0x023d 8 // Constitution (1-25) 1 (byte)
    WRITE_BYTE 0x023e 11 // Charisma (1-25) 1 (byte)
    WRITE_BYTE 0x023f 15 // Morale 1 (byte)
    WRITE_BYTE 0x0240 5 // Morale Break 1 (byte)
    WRITE_BYTE 0x0241 255 // Racial enemy (RACE.IDS) 1 (byte)
    WRITE_BYTE 0x0242 60 // Morale Recovery Time 2 (word)
    WRITE_LONG 0x0244  // Kit Information 4 (dword)
    WRITE_ASCII 0x0248  // Creature script - Override 8 (resref)
    WRITE_ASCII 0x0250  // Creature script - Class 8 (resref)
    WRITE_ASCII 0x0258  // Creature script - Race 8 (resref)
    WRITE_ASCII 0x0260  // Creature script - General 8 (resref)
    WRITE_ASCII 0x0268  // Creature script - Default 8 (resref)
    WRITE_BYTE 0x0270 128 // Enemy-Ally (EA.IDS) 1 (byte)
    WRITE_BYTE 0x0271 1 // General (GENERAL.IDS) 1 (byte)
    WRITE_BYTE 0x0272 2 // Race (RACE.IDS) 1 (byte)
    WRITE_BYTE 0x0273 2 // Class (CLASS.IDS) 1 (byte)
    WRITE_BYTE 0x0274 0 // Specific (SPECIFIC.IDS) 1 (byte)
    WRITE_BYTE 0x0275 1 // Gender (GENDER.IDS). Dictates the casting voice, and checked for the summoning cap. 1 (byte)
    WRITE_BYTE 0x0276  // OBJECT.IDS references 5 (bytes)
    WRITE_BYTE 0x027b 49 // Alignment (ALIGNMEN.IDS) 1 (byte)
    WRITE_SHORT 0x027c  // Global actor enumeration value 2 (word)
    WRITE_SHORT 0x027e  // Local (area) actor enumeration value 2 (word)
    WRITE_BYTE 0x0280  // Death Variable (set SPRITE_IS_DEAD variable on death) 32 (char array)
    WRITE_LONG 0x02a0  // Known spells offset 4 (dword)
    WRITE_LONG 0x02a4  // Known spells count 4 (dword)
    WRITE_LONG 0x02a8  // Spell memorization info offset 4 (dword)
    WRITE_LONG 0x02ac  // Spell memorization info entries count 4 (dword)
    WRITE_LONG 0x02b0  // Memorized spells offset 4 (dword)
    WRITE_LONG 0x02b4  // Memorized spells count 4 (dword)
    WRITE_LONG 0x02b8  // Offset to Item slots 4 (dword)
    WRITE_LONG 0x02bc  // Offset to Items 4 (dword)
    WRITE_LONG 0x02c0  // Count of Items 4 (dword)
    WRITE_LONG 0x02c4  // Offset to effects 4 (dword)
    WRITE_LONG 0x02c8  // Count of effects 4 (dword)
    WRITE_ASCII 0x02cc DEREVAIN.DLG // Dialog file 8 (resref)

I have some questions related to the above.

1. What happens if I leave an entry blank?  Does it become a 0?
2. How do you write the 32 CHAR Array for tracking target? (Long, Short, ASCII?)
3. Are any of these values automatically created or updated?  For example.  If I leave the saving throw categories blank and I say the CRE is a Level 3 Fighter, will the saving throws update to the values that a Level 3 Fighter should have?  If the Level 3 Fighter, levels up ingame to level 4, will the saving throws be appropriate to a level 4 Fighter?
4. There appears to be some discrepancy in NearInfinity as a couple other categories are present such as Deity, Mage type, Death Variable Increment, set extra death variable, etc.  How do I get coordinates for these categories that aren't listed at: http://gibberlings3.net/iesdp/file_formats/ie_formats/cre_v1.htm or http://gibberlings3.net/iesdp/file_formats/ie_formats/cre_v9.htm
5. How would I write to the sound files that I see in NearInfinity?
6. If I changed the Colors for Armor or Leather and then put took off and put on the same currently worn Armor?  Would the colors revert to the item default colors?
7.  How would I create a copy of an existing CRE and change some of the category attributes (such as changing xp and level)?

Apologies for the long list of questions.

Thanks for your help,

Bill

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: