Modding in Exult the Ultima VII engine part 3: Usecode scripting basics

Previous articles:

In the last two articles, we have learned the basics about shapes, the item data unit in Exult Studio. With the editor alone we can achieve some simple tasks like item editing, face editing and so on, but what we can do until now is still limited to the art model and their basic parameters. Game development and modding could achieve more ambitious goals with scripting. We can add more custom functionalities in game, such as dialogue, new NPC, quests, new scripted event and items with special effects out of editor functionalities.

Ultima VII used a scripting language called Usecode, in Exult this scripting language is wrapped in a C-like variation called Usecode C Complier, for short we still call it Usecode in this article. There are some, but not very detailed documentation and examples for Usecode, and they are scattered around so getting the knowledge of Usecode basics is not extremely easy for someone unfamiliar with Exult scripting. Thus, this article is aimed to introduce the very basic aspects of Usecode. For more information, please refer to the intrinsic function list, UCC documentation, and example mods such as source code of BG Keyring mod.

1. How to create and compile a usecode script

A usecode script is a file with .uc format, but actually the compiler won’t complain if you try to compile with other formats, such as .txt files. We can create a .txt file (or change it to .uc if you like) and write script in any text editors like notepad or Visual Studio Code. When we finish and ready to compile, find ucc.exe in Exult tools, and in command line, run ucc.exe with the file we try to compile. We will get another file with format .ucc, then we delete the .ucc and put it in the \patch folder. By convention the main script file should be named as Usecode.

Without an IDE for Usecode scripting, it’s hard to spot bugs or debug in usecode script. However, some syntax errors would be caught when compiling, so you should pay attention to the errors if it didn’t compile normally.

2. Basics of usecode script

When scripting for a mod, we must understand that just like item editing, scripting is done on top of base game, what we do is adding and overwriting the base game. When reading mod script we need to keep in mind some of the functions and parameters are internal used in the base game. Without decompilation we won’t be knowing what the internal functions look like, but some mod that worked closely with Exult team reveal some of the internal parameters. When we see parameters that looks like magic numbers, sometimes they are how the base game defined. And for internal functions there’s a list for known such functions.

The first line we need to define is the game the script is worked with. If we are making a Black Gate mod, we need to claim this line at the very beginning of the script:

#game "blackgate"

Or if it’s for Serpent Isle, add

#game "serpentisle"

For larger code where you break the script into several files, the notation is similar to C:

#include "scriptName.uc"

Next part is defining variables. Usecode support type keywords such as int and var. We can also define groups of parameters as enum like in C.

Some examples are as below:

const int AVATAR = -356;
var target = UI_click_on_item();
enum events
{
	PROXIMITY		= 0,	
	DOUBLECLICK		= 1,	
	SCRIPTED		= 2,	
	EGG			= 3,	
	WEAPON			= 4
};

Exult Usecode supports many types of common logic blocks, such as if/else, while. The syntax is similar to C where curly braces and semicolons are needed in C style. The difference in Usecode scripting is each function need a hex index for the game and Exult editor to recognize, so every function has several parts:

(return type) (function name) (function hex index) ((parameters)){}

In the next section we will talk about the functions more in detail.

3. Some common functions in Exult modding

In this article we won’t be talking about detailed use of internal functions, but here we talk about two types of function that are very important in Exult modding: one is functions for objects/shapes, the other is converse block.

When writing a function for specific item or NPC, we need to add object(0x***) or shape(0x***) after the function name. Function names can be defined as you like, but the hex needs to correspond to the item you want the function to affect. If it’s an item, the format is shape(the hex of parameter in editor), and for NPC, it’s usually object(the hex of parameter in editor + 0x400). You can’t see NPC index without the game running, and for NPCs already in base game, they have internal parameters which are negative integers, and it’s recommended to use the internal index rather than the calculated values. You can find the full list in BG Keyring source code.

Another useful unique tool in usecode in converse block. It works like switch case blocks in common programming languages, but it’s specifically used for creating a U7 style branched conversation.

The structure of the blocks is like:

converse (["initialOption1", "initialOption2", "Bye"]) 
{ 
case "Bye": 
  say("something");
  break; // if the converse ends here
case "initialOption1" (remove): //if the option doesn't appear next, add (remove)
  say("something something"); 
  add("option3"); // new option appear
...
} 

By using case, say, add, remove keywords, we can control the structure of a conversation freely just like in U7. Note that a useful syntax in conversation is the double quote mark in conversation is noted as a pair of @…@ symbol.

4. Case study: talking Guardian puppet

This is actually simpler than you might think. Usecode has an event for double clicking an item, we can take advantage of it and enter a converse when we trigger the event double click. The internal parameter for double click event is 1, for convenience I didn’t use the full parameter list for event, and only state the event DOUBLECLICK as 1.

We will be double-clicking the shape of Guardian puppet glove, so this is a function of the puppet shape. From Exult Studio we can find the index of this shape and turn it into hex number (here it is 0x40c), and write a block that if we double click on the shape, we trigger a converse.

Here’s the final script that made the Guardian puppet alive:

#game "serpentisle"
const int DOUBLECLICK = 1;
const int GUARDIAN_PUPPET_FACE = 315;
void GuardianPuppet shape#(0x40c) ()
{
GUARDIAN_PUPPET_FACE->show_npc_face(0);
if (event == DOUBLECLICK)
{
item.say("You used the puppet and imitate Guardian voice. @Avatar!@");
converse (["Name", "Job", "Bye"])
{
case "Bye":
say("@I'm not going anywhere, Avatar!@");
break;
case "Name" (remove):
say("@Avatar! Thou shall know your Lord Guardian! Hahahaha!@");
add("Guardian");
add("Puppet");
case "Guardian" (remove):
say("@Do you really know where you're going, Avatar?@");
case "Puppet" (remove):
say("@Hahahaha!!!@");
case "Job":
say("@I am helping you, my friend.@");
}
item.hide();
}
}

5. Scripted animation

Scripted animation is another important tool for making your own original plot or spice up the environment. It’s also an important part of scripted events. It’s also straightforward but with some unique syntax that need to pay attention.

Usually the animation frames will be contained in the frames of a shape. Then the scripted animation is basically controlling the flow and timing of showing different frames.

The syntax for a script block looks like:

script itemThatDoTheThing  
{  
sfx 100; // play sound effect No.100
next frame; // show frame number +1
previous frame; // show frame number -1 
frame 4; // show frame No.4 
wait 1; // wait for 1 tick; The unit of the number is the game frame/tick of U7   
say("something"); // say that not in converse block will show on top of the target item  
repeat 3{ }; // repeat 3 times of the commands in brace 
... 
} 

For the full list of script commands please refer to http://exult.sourceforge.net/seventowers/code.php?TITLE_IMAGE=usecodetitle.png&DATAFILE=ucc_scripting.dat

With the combination of the different options in script block, it’s possible to control the animation of items as well as NPCs when we needed.

These are only the basics of Usecode scripting, but with this knowledge you are already being able to do a lot more in Exult modding. At this point I’m not sure if there will be more of the tutorials for now, but if people want to know more, there might be topics on barges, egg events or more detailed Usecode scripting. If you are interested in more about Exult modding, please tell me and I will see what else I can do to help the community!

Modding in Exult the Ultima VII engine part 2: item editing and creation

In the last post, we learned how to make custom portraits, and here in this article, we expand our modification to in-game items. While the shape dealing procedures are similar, there are extra steps and other aspects need to be taken care of, since items — especially usable items, have a lot of properties that we need to set for them.

This part we mainly focus on editing SHAPES.VGA, as well as have a basic understanding of shape editor in Exult Studio. Some, but not much map editing will be also mentioned. Since the Serpent Isle paperdoll has much more complexity, I will demonstrate it in SI, and it will naturally cover BG modding of items.

Case study 2: tutorial mod of items — Treasures of Wonder

The sample patch “Treasures of Wonder” is published here: https://github.com/yulotomorrow/Treasures-of-Wonder. If you are interested you can also download it and try it yourself, or open it in Exult Studio to observe what I have done in this patch about item modifying. Next I will explain step by step what I did and how you can do the similar things.

(Note that the patch might change in the future, and content might not matching this article after changes.)

Step 1: editing existing item

This is considered easy because we don’t need to fill out the whole form of item for it to work, instead we can adjust step by step to achieve what we want.

For example, the first item we try to modify is the pitchfork. Fellowship Candelabra is missed by the Avatar since the Fellowship has been destroyed, so Avatar secretly bring one to Serpent Isle. As we learned from last article, we export the shape, paint over each frame (make sure EACH FRAME should be modified if it’s the same item), then import back and save. Now we try to increase the damage by finding the damage of weapon, then we can also choose a flag of light source. Now we have a powerful battle Candelabra instead of the boring pitchforks!

Here we just replace the .shp file of picthfork, and without much change, this item is already working in game.

In Serpent Isle, we need to take care of the paperdoll too. We do the same of modifying and changing shp file of corresponding paperdoll. Usually you will be recognizing which paperdoll shape is a pitchfork since paperdoll sprites are much larger. But paperdoll files are not named so it’s impossible to search, if you cannot recognize, you need to go to the shape tag again, find info-Obj Paperdoll tag, then find the corresponding number of paperdoll and edit.

Battle candelabra in game. The Guardian Puppet in the picture is also a part of the patch, but it contains scripting so it’s out of the scope of this part of tutorial.

Note that if we modify item like this, every pitchfork in the game will be a candelabra. It’s fortunate that we are modding SI, if it’s in BG, the murder candelabra will have another meaning… In the final patch, I didn’t use direct item modifying to avoid unexpected game environment changes.

Step 2: add a frame of a group of items

In the base game, the different types of treasure chests are counted as the same item in different frames. There are very good reasons for doing this: On one hand the number of shapes we need to handle will decrease, on the other hand we don’t need to set mostly the same parameters over and over in different items. So if we want to add a different kind of chest, we better put it under the same shape too, by adding extra frames.

Adding single frame directly is possible in Exult Studio, but I still suggest export the group of .shp file first, add new layers and import. By doing this you will be having a reference of how large the items and their positions are, to limit the possible inconsistency in position and size. Here we add 2 layers to the chest shp file, one for facing front and one for facing sideways. The same shape shares the same set of parameters, but it’s still possible to change some of them individually, for example the frame name. Frame name is not only convenient for searching in Exult Studio, when you click an item in game, the name it shows is the frame name.

Frame name properties of different frames

Step 3: Adding new items

New items are a bit not so straightforward as it requires you to understand the different properties in the editor more, or the item will not work properly in game. Luckily, we have so many existing items for us as references, so we can imitate the settings of similar items to create ours.

Placeable items are usually the easy kind. First you need to create new shape in SHAPES, then import the shape, a usual map object mainly falls into Quality/Quality Flags, breakable and building categories, set the name of shape, dimensions, weight and volume, then it’s almost done. The tiles (dimensions) need to set according to the sprite size, or it will look weird or work unexpected in game. This usually can be spotted in map editing. Also need to note that the Weight is in unit of 0.1 Stones, so an item of 1 Stone should be set as 10.

A simple example of environmental item creation.

Weapons and armors should be taken care of their other properties. One is related to weapon attack, we tick “Weapon” (or “Armor”) in Extra checkboxes, a new tab will appear next to Object tab. Under weapon, we choose the damage value and type, as well as other details. You can listen to different SFX in game and choose, or alternately, just find a similar weapon and follow how they choose. Then for weapons and armors we need to create paperdoll model too. We create new shape in PAPERDOLL file, and remember the corresponding shape index. We will be using it in another tab in the shape info: Obj Paperdoll.

Moving to the Obj Paperdoll tab, we need to choose both weapon slot and paperdoll shape index. Weapon slot might be multiple, like holding in hand and on back, we need to add them separately, and choose the correct paperdoll frame in each slot. Usually for weapons and armors, we need to tick “all frame” and “translucent”. When finish adding all needed slots, apply the changes and save in editor.

There is one tricky thing for holding weapons. By default, the weapon will not show on the Avatar in game model, that’s because when “In hand offset” is set to (255, 255), it means suppress showing on model, so it’s default not showing. In a weapon shape the first frame is by convention the shape how it looks like on map, so frame 0 should keep (255, 255) but other frames should change to some small numbers. You can imitate how other weapons fill out the offset, but eventually you still need to adjust after seeing how it performs on in-game model.

Although the Exult studio suggest you doing all the modification while the game is running, for pure item editing, you can do it without game running. This is to avoid any unexpected changes made in game while testing, and if you save the unexpected changes, there’s no way to revert. If you only do them in editor, then you can save your changes by clicking save all without concern of unexpected map changes, or you would like to choose save -> shape info. But these items are just on the lists for now, they are not in game yet. So next we need to move forward and put them on map, thus some basic map editing.

Step 4: Put them on map!

Map editing is tricky. Everything you do to the game will be saved when you are doing map editing and saved the map, including individual item positions, chunks, inventory info, and so on. So when editing on map, we need to make sure we don’t accidentally change other unrelated things or pick up unrelated items.

How the map edit mode looks like

Usually you would turn on the cheat mode and press ctrl-alt-M to edit map, but it’s suggested to use a clean save, aka start from the beginning. Run Exult from command line using –edit command, the game will start from the very beginning with map edit mode. If the Exult Studio editor didn’t appear simultaneously, you need to open one manually. Use F3 teleport cheat to navigate on map, go to where you want to put the items. Then drag items from editor to the map, it will be on the map with tile dimension indicator. If a shape has multiple frames and the default isn’t what we want, just double click it and select another frame. If we want to put items in containers, we need to press the same to exit map edit mode, put them manually, and save map. Before we finish we make sure we didn’t do unexpected changes to the map, then teleport Avatar to the original place where it begins. In Exult Studio, we save the map, and the item patch is done!

Congratulations, now you know how to add or edit items in Exult, and you can do it yourself too! Don’t worry of breaking the game, all the changes will go to \patch folder, so the worst situation you just need to delete the whole patch folder. But since there’s no revert functionality in Exult Studio, doing your own version control is important in making larger mods!

Thanks to Dominus Dragon for his huge help in making the patch and tutorial! Next part of this tutorial series we will be learning basic Usecode scripting in Exult modding. Please stay tuned!

Modding in Exult the Ultima VII engine part 1: portrait editing

Exult, the Ultima VII fan-made engine for porting and running Ultima VII (including The Black Gate and Serpent Isle) to modern systems, is also coming with a convenient tool for modding Ultima VII both parts, and even make new games in the similar style. Throughout the years, Ultima fans might be interested in changing part of the game or make own mods, but might not know how to begin with, which is the motivation of this guide.

Most of the basic contents of how to use the modding tool, Exult Studio, can be found in the official Exult Studio documentation (please refer to the documentation and make sure to install and run Exult properly), but here I try to go directly into how to modify some of the things fans might care about the most and give a bit of insight of how Exult Studio works.

Custom Avatar mod, made by yulotomorrow (author)

What can we do, and how easy or difficult are they?

Exult Studio allowed you to modify a lot of things, and with some additional scripting, you can edit something more complicated. Here we assume you have already prepared your assets that you want to work with, and from easy to difficult, you can do including but not limited to:

  • Only need to modify in Exult Studio:
    • Modifying the looking of people or items
    • Modifying the combat data, character attributes, item attributes etc.
    • Adding new items, weapons, etc.
    • Adding your own monster
  • Need to also modify in running game
    • Placing and editing the place of items (when they first generate) in map
    • Editing the map environment, building your house that look like what provided in-game
  • Need scripting
    • Adding not existing NPCs with dialogues
    • Adding trigger points of events on map
    • Modifying existing NPCs and dialogues
    • New game features

Note that, contrary to common beliefs, dialogue modify is actually harder than adding new dialogue. This is due to the original game data script is packed and cannot access source script directly. You need to override the whole original dialogue if you want to change a line, but it’s still doable.

In most case you cannot simply “copy” something and make a similar individual item. Modify an existing item is easy, but it will lead to everything that mark as this item in game changed. So you need to understand what the data are for when you create a new item.

Lastly, once you hit save, the modifications you did is not revertible, you need to manually change back or clear the whole mod if things go wrong. Make sure to do your source control if you’re aiming for complex modification that affect multiple in-game objects.

As to the scope of this tutorial, we will do 3 case studies that covers sprite change, item modification and new NPC creation. We won’t be covering map and eggs (triggers) as of the current version of tutorial. Please find the corresponding chapters in Exult Studio documentation.

Case study 1: Custom Avatar

This probably is a quite common request because it can greatly increase immersion. Here I assume you have prepared your Avatar avatar, either by scaling a photo or draw your own character.

In short, the procedure is pretty straightforward: Find the target to replace -> Export target shape -> Make modification -> Import new shape to target -> Save and check in game.

In Exult Studio, first choose File -> Load game -> the game we want to modify (such as The Black Gate). Note that the two parts of Ultima VII are mostly separated, and modifying one cannot affect another. Next we need to find the target shape, for portraits, they are located in FACES.VGA, click it in the Exult Studio, and it shows all the portraits. Then right click -> export shape, save it at the directory you want. Technically if you have the .shp file ready, you can skip this step, but I strongly suggest you edit your art based on an existing shape in Exult, to avoid any palette mismatch problem.

Exult Studio interface

Any art assets should be in .shp file format. There’s a plug-in provided by Exult that let you edit and export .shp file in free 2D graphic editing software gimp. When you export shape from exult studio, you will see it shows like ordinary layered graphic in gimp. The different layer is corresponding to “frame”, a concept in Exult that marks different shapes in one item. So if you have some art that is under the same person/item/concept and share same logic, you probably would want them as frames instead of separate items.

For example, if we want to make a mod of the female Avatar in U7-Black Gate (BG), we load the game “black gate” in exult studio, the find the Avatar in the tag FACES.VGA. Avatar should be the first one, but here we only see the male Avatar. We need to right click -> info and inspect different frames, and here we found Female Avatar is at frame 1. In Gimp we simply replace this layer with your pixel portrait prepared, save and export as .shp, and choose “import shape” to import back to the slot. Now we inspect in editor and see indeed the frame 1 is the new Avatar.

Exult Studio shape inspection

If you want to FULLY edit the Avatar, you need to change the paperdoll and sprite too. The NPC sprite contains 32 frame, it’s a lot of work to edit all the frames, but make sure they’re all edited if you decide to edit, or it will look strange. The sprite is in the SHAPES.VGA file, but there are over 1000 items and they’re very small, it’s hard to find target item. In this case search is suggested to use. Enter “Avatar” in the “Find” textbox below, and click the arrows to find the Avatar shape. Note that this name is the display name in game, so there might be multiple items sharing the same name, and in Serpent Isle some of the Avatar sprites didn’t have names, you might still need some manual search sometimes. For paperdoll modification, since BG and SI have different paperdoll, the ones in BG is under GUMPS.VGA, and in SI under PAPERDOLL.VGA.

This simple mod can do in Exult studio alone, the modification will be saved in patch folder in the Ultima 7 game folder (for example, if you have GOG version, the Ultima 7 file will be in the GOG game folder), and the change will immediately show in game, even in an existing save.

Now you have your own custom Avatar! If you are interested in having your custom Avatar, you can also try and show off your Exult modding result!

(To be continued in part 2)

Blog at WordPress.com.

Up ↑

Design a site like this with WordPress.com
Get started