//This script creates a bag filled with items void main() { // Get the item that triggered the ondisturbed event object oItem = GetItemActivated(); // Retrieve the total number of rows in the "cas_reagents" 2DA int nRowCount = Get2DARowCount("cas_reagents"); // Set the desired row number (e.g., 0 for the first row) int i2DAROW = 0; // Check if the specified row is valid if (i2DAROW >= 0 && i2DAROW < nRowCount) { string sBagResRef = "cas_reagentbag"; // Replace with the actual resref of the bag int nQuantity = StringToInt(Get2DAStringByColumnIndex("cas_reagents", 2, i2DAROW)); string sItemResRef = Get2DAStringByColumnIndex("cas_reagents", 3, i2DAROW); string sItemName = Get2DAStringByColumnIndex("cas_reagents", 0, i2DAROW); // Check if the player has enough tickets object oPlayer = GetItemActivator(); int nPlayerTickets = GetLocalInt(oPlayer, "nCAS_TICKET"); if (nPlayerTickets < nQuantity) { SendMessageToPC(oPlayer, "You have " + IntToString(nPlayerTickets) + " tickets, but you need " + IntToString(nQuantity) + " to buy the reagents."); return; } // Deduct the required tickets SetLocalInt(oPlayer, "nCAS_TICKET", nPlayerTickets - nQuantity); // Create the bag inside the player's inventory object oBag = CreateItemOnObject(sBagResRef, oPlayer, nQuantity); // Optional: You can give the bag a name or description here SetName(oBag, sItemName + " (" + IntToString(nQuantity) + ")"); int i; // Declare the loop variable outside the loop // Loop to create and add items to the bag for (i = 0; i < nQuantity; i++) { // Create the item and add it to the bag object oItemToAdd = CreateItemOnObject(sItemResRef, oBag); } // Destroy the original item that triggered the event DestroyObject(oItem); } else { // Handle the case where the specified row in the 2DA is invalid SendMessageToPC(GetItemActivator(), "Error: Invalid 2DA row specified."); } }