Skip to content

XEH adapter guide

commy2 edited this page Feb 14, 2016 · 5 revisions

This guide is outdated. Please refer to this guide instead!

Addon authors do not have to choose between offering either a standalone addon with no extra dependencies, or to create an addon that uses the extended event handler system but then requires players to load CBA along with it. It is possible to create a kind of "adapter addon" which adds XEH compatibility. The author can then offer the addon/mod in two variations:

  1. The original, standalone addon, with no extra dependencies.
  2. The original addon and an optional XEH adapter addon that players can load if they need XEH compatibility.

In order to demonstrate how to create an adapter addon, we take the original config from the native XEH guide and create a new addon that will connect that with the extended event handler system. The basic principle for an adapter addon is:

  1. It depends on the original addon and cba_xeh
  2. We then remove all the event handlers that the original addon defines for each unit/vehicle.
  3. Finally, the original addon's event handlers are moved into Extended_<event>_Eventhandlers definitions.

When the player wants to use XEH together with the original addon, all they need to do is to load the adapter addon along with the original.

The original addon

/*
 * TAG_MyAddon - the original addon with a simple init event handler.
 *
 */
class CfgPatches
{
    class TAG_MyAddon
    {
        units[] = {"TAG_B_Soldier_F"};
        weapons[]={};
        requiredAddons[] = {"A3_Characters_F"};
        requiredVersion = 1.0;
    };
};

class CfgVehicles
{
    class B_Soldier_base_F;
    class B_Soldier_F: B_Soldier_base_F
    {
        class Eventhandlers;
    };

    class TAG_B_Soldier_F: B_Soldier_F
    {
        displayName = "TAG soldier (happy)";

        class Eventhandlers: Eventhandlers
        {
            init = "(_this select 0) setVariable ['TAG_isHappy', true]";
        };
    };
};

The adapter addon config

/*
 * TAG_MyAddon_XEH, the XEH adapter addon
 *
 * This addon should be loaded together with the original addon, "TAG_MyAddon.pbo"
 * 
 */
class CfgPatches
{
	class TAG_MyAddon_XEH
	{
		units[] = {"TAG_B_Soldier_F"};
		weapons[]={};
		requiredAddons[] = {"A3_Characters_F", "TAG_MyAddon", "cba_xeh"};
		requiredVersion = 1.0;
	};
};

class CfgVehicles
{
	class B_Soldier_base_F;
	class B_Soldier_F: B_Soldier_base_F
	{
		class Eventhandlers;
	};
	
	class TAG_B_Soldier_F: B_Soldier_F
	{
		class Eventhandlers: Eventhandlers
		{
			delete init;	// Remove the init EH from TAG_MyAddon.pbo
		};
	};
};

class Extended_Init_Eventhandlers
{
	class TAG_B_Soldier_F
	{
		TAG_MyAddon_init = "(_this select 0) setVariable ['TAG_isHappy', true]";
	};
};