MPak uses what's called a utility, or MUtils, in order to achieve a lot of its control over the game as a whole. However, MUtils is also designed for others in mind. As a developer, you can actually use MUtils to gain access to hundreds of documented essential functions for programming!
To add MUtils into any given Class, you must add the following code:
var MUtils U;
U will be your main access-point into all of the functions that MUtils has. You can rename this to anything you want, but U is very convenient to type.
Here are some helpful optional variables that you may want to add in ahead of time:
var KWHeroController PC;
var Pawn HP, ICP;
var KWHud HUD;
var array<KWHudItem> HudItems;
var BaseCam Cam;
These variables will help with simplifying some core access-points, but they are not technically required. All these variables should be used for temporarily storing a pointer.
In regards to the optional variable declarations: do not add HudItems if you're working from within the context of an Object, since this will cause a crash after a save-load-save. Use local HudItems variables to not crash. The reason for this crash is mostly unknown, and almost nobody will experience it.
Next, you will need a way to gain access to this utility actor. Here's the most straightforward way of obtaining a reference to it:
event PostBeginPlay()
{
U = GetUtils();
}
Since we're referencing the function GetUtils(), you'll need to provide that function in the class you're modifying:
function MUtils GetUtils()
{
local MUtils Ut;
foreach DynamicActors(class'MUtils', Ut)
{
return Ut;
}
return Spawn(class'MUtils');
}
This simple function is responsible for giving your class access to MUtils. When the function is called, it checks the entire map to see if any class has spawned in MUtils. If MUtils has not been spawned in by any other class, then our class will spawn it in first. Once obtained, it sets the value of U to equal the new or found MUtils.
It's important to mention that, depending on the context of your class, you may need to adjust these functions so that you can locate and/or spawn in the utility.
You must understand that while MUtils is incredibly powerful, you also need to understand that MUtils has some important tradeoffs.
Most functions are not static, because they require instancing of some sort. The functions that are static can be accessed without the necessary above code. For instance, if you wanted to run the Ceiling() function, you could simply type class'MUtils'.static.Ceiling() in order to access the function.
Any class that uses MUtils needs to have the code above added into it to be able to properly access MUtils.
After adding this into your class, you'll have access to all of MUtils functions! If you need to know which functions are available, or what functions do what, check out the various sections seen below.