#include "inc_loot" // Replace with the actual filename of your loot script

#include "your_loot_script" // Replace with the actual filename of your loot script

void main()
{
    object oContainer = OBJECT_SELF;
    object oOpener = GetLastOpenedBy();

    // Check if the player has I_CAS_CASINOHANDLE in their inventory
    if (!GetIsObjectValid(GetItemPossessedBy(oOpener, "I_CAS_CASINOHANDLE")))
    {
        SendMessageToPC(oOpener, "You need a casino handle to loot this area.");
        return;
    }

    // Check if the container has already been looted
    int nLooted = GetLocalInt(oContainer, "I_CHEST_CHRISTENHOLMLOOTX");
    if (nLooted == 1)
        return; // Container already looted

    // Set the container as looted
    SetLocalInt(oContainer, "I_CHEST_CHRISTENHOLMLOOTX", 1);

    // Generate gold with a 33% chance
    if (Random(100) < 33)
    {
        // Gold amount between 5000 and 12000
        int nGoldAmount = Random(7001) + 5000; // 7001 because Random is exclusive
        LOOT_AddGold(oContainer, nGoldAmount);
    }

    // Generate at least one item from the loot table
    LOOT_GenerateFromTable(521, oContainer);

    // Additional items based on Search skill
    int nSearchSkill = GetSkillRank(SKILL_SEARCH, oOpener);
    int i;
    if (nSearchSkill >= 20)
    {
        int nExtraItems = (nSearchSkill - 20) / 20;

        for (i = 0; i <= nExtraItems; i++)
        {
            LOOT_GenerateFromTable(521, oContainer);
        }
    }
}

