#include "fcb_inc_vars"
#include "fcb_inc_cvgen"
#include "fcb_inc_array"
#include "x2_inc_switches"

//==========================================/
void main()
//==========================================/
    {
    SetListening(FCB_LIS, 1);
    SetListenPattern(FCB_LIS, "**", LISTEN_NUMBER_STANDARD);

    //--------------------------------------/
    array_main();

    //--------------------------------------/
    // Tag-based scripting is used for PGC3 Configurator, and possibily other things...

    // * Item Event Scripts: The game's default event scripts allow routing of all item related events
    // * into a single file, based on the tag of that item. If an item's tag is "test", it will fire a
    // * script called "test" when an item based event (equip, unequip, acquire, unacquire, activate,...)
    // * is triggered. Check "x2_it_example.nss" for an example.
    // * This feature is disabled by default.
    SetModuleSwitch (MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS, TRUE);

    if (GetModuleSwitchValue (MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS) == TRUE)
        {
        // * If Tagbased scripts are enabled, and you are running a Local Vault Server
        // * you should use the line below to add a layer of security to your server, preventing
        // * people to execute script you don't want them to. If you use the feature below,
        // * all called item scrips will be the prefix + the Tag of the item you want to execute, up to a
        // * maximum of 16 chars, instead of the pure tag of the object.
        // * i.e. without the line below a user activating an item with the tag "test",
        // * will result in the execution of a script called "test". If you uncomment the line below
        // * the script called will be "1_test.nss"
        // SetUserDefinedItemEventPrefix("1_");
        }

    //--------------------------------------/
    // styzygy added this to load items for the persistant chest object
    if (GetLocalInt(OBJECT_SELF, "iAllowPChest") == TRUE)
        {
        object oChest = GetObjectByTag("CS_PCHEST");
        string sDB = GetTag(GetModule())+"_PCHEST";
        string sTag = "";
        int iCount = 0;

        //AssignCommand(oChest, SpeakString("Attempting to load items from campaign database."));

        int iMax = GetCampaignInt(sDB, "iCount");
        if (iMax > 0)
            {
            for (iCount = 0; iCount < iMax;  iCount++)
                {
                sTag = "PITEM_" + IntToString(iCount);
                RetrieveCampaignObject(sDB, sTag, GetLocation(oChest), oChest);
                //DeleteCampaignVariable(sDB, sTag);
                }
            }
        }

    //--------------------------------------/
    }
