void main()
{
    // Get the player who disturbed the inventory
    object oPlayer = GetLastDisturbed();

    // Get the disturbed item
    object oDisturbedItem = GetInventoryDisturbItem();

    // Check if the disturbed item has the "iCopyMe" variable set to 1
    int iCopyMe = GetLocalInt(oDisturbedItem, "iCopyMe");
    if (iCopyMe != 1)
    {
        SendMessageToPC(oPlayer, "This item cannot be copied.");
        return;
    }

    // Check if the player has a "I_CAS_CASINOHANDLER" item
    object oHandle = GetItemPossessedBy(oPlayer, "I_CAS_CASINOHANDLER");
    if (!GetIsObjectValid(oHandle))
    {
        SendMessageToPC(oPlayer, "You need a Casino Handle to make purchases.");
        return;
    }

    // Get the number of tickets the player has
    int nPlayerTickets = GetLocalInt(oHandle, "nCAS_TICKET");

    // Check if the player has enough tickets
    int iCostTickets = GetLocalInt(oDisturbedItem, "iCostTickets");
    if (nPlayerTickets < iCostTickets)
    {
        SendMessageToPC(oPlayer, "You need " + IntToString(iCostTickets) + " tickets to copy this item.");
        // Destroy the original disturbed item if not enough tickets
        DelayCommand(1.0, DestroyObject(oDisturbedItem));
        return;
    }

    // Deduct the required tickets
    SetLocalInt(oHandle, "nCAS_TICKET", nPlayerTickets - iCostTickets);

    // Get the container of the disturbed item
    object oContainer = GetItemPossessor(oDisturbedItem);

    // Find the nearest chest with the specified tag
    object oChest = GetNearestObjectByTag("CAS_TIER1CHEST", oContainer);

    // Check if the chest is found
    if (!GetIsObjectValid(oChest))
    {
        SendMessageToPC(oPlayer, "Error: Chest not found.");
        return;
    }

    // Copy the item to the chest
    object oNewItem = CopyItem(oDisturbedItem, oChest, TRUE);

    // Optional: Notify the player about the copy
    SendMessageToPC(oPlayer, "Item copied successfully.");
}
