Majesty Gold HD

Majesty Gold HD

50 ratings
Modding Tutorial for Beginners
By amantalado
This guide will cover the basics of modding and content creation/editing for Majesty.
   
Award
Favorite
Favorited
Unfavorite
Introduction
So you want to learn how to mod the game? Well, depending on your familiarity with bare-bones text editing and lack of user interface, this might be a piece of cake or a harrowing and terrifying experience. Hopefully, I'll be able to ease those who fall into the latter category into learning how to at least do some basic modification to the game without too much trouble. Let's get started then, shall we?
The Basics
The best place to start would likely be the best place any modder should start: A text editor!
This is basically what we'll have to use to mod since there is no tool for it like there is with designing scenarios or creating maps with, and there doesn't look to be one on the horizon either.
There are quite a few free ones out there that are serviceable, you can even stick with Notepad if that's your preference, though it might cause quite a bit of clutter when your dealing with thousands of lines of code, but to each his own. I personally use Notepad++[notepad-plus-plus.org]. There's also EditPad Lite[www.editpadlite.com] if you're looking for something a little different, but I would recommend you get some kind of text editor for this if you plan on doing any kind of heavy modding.

You'll want to locate the Steam directory of Majesty to find the relevant folders containing the files you'll want to use as a template to begin editing. These are typically located in Steam\SteamApps\common\Majesty HD\SDK\OriginalQuests. The Data folders hold .xml files while the GPL folders contain .dat and .gpl files for the base game, with expansion files designated with an Mx after the folder and file name. These are the files that you'll be creating your mod from, so you should learn a bit more about them.

Let's cover the types of files you'll be opening, editing, and possibly creating: .xml, .dat, and .gpl files. I'll go over these one by one: .xml files are ones that contain the code that create or modify game objects such as buildings, units, spells, sounds and everything in between and they are loaded in the Game Object Definitions field of a mod. The .dat and .gpl files are a bit more complicated as they encompass everything that makes Majesty a fantasy kingdom simulator, with .dat files containing the code used for the initial generation and attribute setting of new game objects as it applies for that object's prototype parameters. I'll cover that more in depth in later sections of this guide, for now just knows that .dat files control the initial attributes of a generated object. The main focus of this tutorial will be the .gpl files as they hold the meat of the game in them, everything from AI Behavior to Building functions to Spell effects are detailed in these files. The .gpl and .dat files can't be loaded into a Mod the same way as .xml files can, as these files must be first converted to a bytecode (.bcd) files first then added to the mod before their changes can take effect. The MakeGPL.bat file contained in the SDK is what facilitates the conversion of the .gpl and .dat files into a .bcd file by using a path.gplproj file to locate the relevant files to be converted. The .gplproj file can be opened and modified with a text editor, just keep in mind that the paths to the .dat and .gpl files should be relative to where ever the path.gplproj file is located. Keep in mind that for path.gplproj that .dat files are always data files and .gpl files are always source files, so make sure that's reflected in their addition to your path file.

Modding the game will require the modification/creation of these all of these file types to some degree, but the main focus of this guide will be to expand upon .gpl editing since .xml and .dat files are simpler to grasp the concept of.
GPL: Simple Modifications
We'll start with how to do simple modifications to the game. The GPL Reference.pdf is a good resource to have as it contains parameter definitions as well as some basic information on GPL editing. It should be located in Steam\SteamApps\common\Majesty HD\SDK\Documentation. The main use of the pdf for this guide is to give us a list of built-in functions to use when creating and editing the game's code.

One thing to note about coding in Majesty is that capitalization and spacing almost never matters as there is no case-sensitivity or relevant space detection.

Every function that is not native to Majesty has a structure that must be followed if you ever decide to create your own function, so I will briefly cover what their genereal composition should ultimately consist of in order for them to actually work.
The general layout of a function is basically this:
function Name(<variables>) declare begin end
From the top, a function begins by stating function and then the function's name followed immediately by any variables the function needs to accept. The declare section is where you would put in your variable types and variable names. Finally, begin and end signify the space in which your function will implement its actions. So for example, if we wanted a function that would give a unit Magic Resistance equal to 35% of it's current HP, we can do that with this basic structural setup.

First we input our function's name and the variables that it needs to pass. We'll call this function MagRes and give it the only variable it should need, which is an Agent variable that we'll name thisagent since it's relatively common practice to give the first agent variable in a function's parameters that name. You can name it whatever you desire, but if you're following along, then your function should look like this for the first line:
function MagRes(agent thisagent)

Now we reach the second part, in which we declare any variables we wish to utilize. While a function this simple can be done without variables, it can still serve to illustrate their usefulness in place of constantly repeating a function over and over again when it comes to integer calculations. We'll use two integer variables, one for the creature's Current HP, and one for its calculated additional Magic Resistance. We'll name them CurrentHP and AddResistance, leaving us with the following code:
declare integer CurrentHP, AddResistance;

Always remember to end your final variable name with a semi-colon as it acts to close off the chain of variables for that particular type. This is not the only way to declare variables, as sometimes a single variable type has so many that it may be more helpful to separate them out into two individual lines like so:

declare integer CurrentHP; integer AddResistance;

Both instances work just fine, it really depends on what you feel is better. We are now at the final part of a function which consists of the actions. When possible, set up as many of your variables as are necessary at the beginning to be used for later in the code. For this particular function, it's fairly straightforward. First we get the unit's current HP by using the native function $GetAttribute with the #ATTRIB_HP expression for the attribute being used. It should look like this:

begin CurrentHP = $GetAttribute(thisagent, #ATTRIB_HP); end

Again, always end with a semi-colon in this section unless it's one of the keywords in the GPL Reference. Keywords meaning things like If/Then, Loop, Begin/End, etc. Now that we have our agent's HP, next we need to get the amount the becomes Magic Resistance. Since we are dealing with integers, using decimals such as simply multiplying the CurrentHP by 0.35 won't work, so we have to use fractions instead. For Majesty, you will want to strive to multiply first and divide last since you'll end up with numbers being shaved off otherwise. In this case, we want to multiply by 7 first, then divide by 20, rather than the other way around. If we divide by 20 first from a unit that has, say, 10 HP, then Majesty will calculate the output as a 0 for when you multiply it by 7 immediately afterwards. The code should look something like this now:
begin CurrentHP = $GetAttribute(thisagent, #ATTRIB_HP); AddResistance = ((CurrentHP * 7) / 20); end

Now that we have our Resistance amount, we can now use the #AdjustAttribute function to modify the unit in the way we desire using #ATTRIB_MagicResistance for the qualifying expression in the function with the result being:

begin CurrentHP = $GetAttribute(thisagent, #ATTRIB_HP); AddResistance = ((CurrentHP * 7) / 20); $AdjustAttribute(thisagent, #ATTRIB_MagicResistance, AddResistance);; end

With everything combined we should have a basic function looking like this:

function MagRes(agent thisagent) declare integer CurrentHP, AddResistance; begin CurrentHP = $GetAttribute(thisagent, #ATTRIB_HP); AddResistance = ((CurrentHP * 7) / 20); $AdjustAttribute(thisagent, #ATTRIB_MagicResistance, AddResistance);; end

This function can be called into action like a native function once the mod containing it is activated. It need not look exactly like this, as I said earlier the game doesn't actually care about spaces or capitalization, so it's more about your preference. For instance, you can have it look like this:
fuNCtiOn MAgRes(aGeNt tHisageNt) declarE integer CURRENThp,AddRESISTANCE; BEgin CuRRentHP=$GETaTTriBute(thISagENt,#AtTrib_hP);AdDResisTance=((currentHP*7)/20);$AdjustAttribute(tHISagent,#attrib_MAGICRESISTANCE,addresistance);; END

And it will compile and rune just as well as the previous version. There is no difference other than potentially ruining the day of anyone who ends up taking a look at your work.

Editing existing functions shouldn't be too difficult now that you know what one consists of from the ground up, but none of that matters if you can't even get the mod into the game in the first place. Wherever you've created or modified a function, whether it be in an existing .gpl file or one that you made yourself, you'll need to save the file somewhere that you're path.gplproj file can point to so that it will compile. Typically, you'll want everything you've created/modified to be in their own folder so that everything is in place for compiling the bytecode.
Compile & Add to Mod
Before it can be compiled, the file(s) have to be pointed to by a path.gplproj file. You can find the one that the base game uses in C:\Program Files (x86)\Steam\SteamApps\common\Majesty HD\SDK\OriginalQuests\GPL. It's fairly straightforward as it is basically a text file that you can open up and insert the location of your mod file relative to wherever path.gplproj is located. You can copy and modify the original or make one from scratch. Once that is done, copy and paste the MakeGPL.bat file into the same folder as your path.gplproj file and open MakeGPL.bat. Your code should compile and you'll be left with a bytecode.bcd file in the same folder assuming everything went according to plan. The bytecode file goes into the GPL Bytecode field for Mods in the RGSEditor.

Once you have all relevant .xml and .bcd files referenced for your mod in the RGSEditor, you can save it and try it out.
Conclusion
That's really as basic as it gets when it comes to modding Majesty. There are some other topics that would be entire guides in and of themselves such as creating custom spells, but for now this guide should serve as a good platform to start modding from. It also was a case of not wanting to front-load too much information in a Beginner's guide, so any topics concerning specific things about modding will have their own guides.
62 Comments
haseorod Jul 3, 2022 @ 7:49am 
Very nice:steamthumbsup::steamthumbsup:
BILLYREDNECK Jan 26, 2021 @ 3:12am 
Thank you.
BILLYREDNECK Jan 21, 2021 @ 6:08pm 
I've watched the first video. And thank you for making an additional tutorial.
Matkatamiba Jan 11, 2021 @ 1:22pm 
After work today, I'll throw a more succinct version with some simple changes and compiling with the editor.
Matkatamiba Jan 11, 2021 @ 1:16pm 
After about the 20 minute mark is when he goes into GPL files, which is one of the main things you'll use for modding.
Matkatamiba Jan 11, 2021 @ 1:15pm 
@BILLY https://www.youtube.com/watch?v=Pb-gY88_fOw another community member made this. Mods and quests are essentially the same thing for the most part.
BILLYREDNECK Jan 11, 2021 @ 4:47am 
Guaranic that would be awesome.
Matkatamiba May 26, 2020 @ 8:50pm 
I can make a demo video making a fake mod from scratch if you want. Once you do it once, you'll get it.
Matkatamiba May 26, 2020 @ 8:43pm 
I've always had to use the editor and manually type in the target: filename.bcd in manually. It creates the file when it has a path for it, but you aren't selecting an existing file for it until it's already been compiled once. I don't know if that makes sense.

Here's what mine looks like. https://i.imgur.com/s3wdtX8.png