How to brew a stack of potions?

I’m not sure where to begin with this. I want to start with a stack of empty potions and end with an equal stack of brewed potions. I have increased the stack size of both empty potion bottles and brewed potions in baseitems.2da, but it still only brews one potion at a time. Salvation used to have a system like this in place. Is this done via scripting or 2DAs?

Update:

I modified the X2_pc_craft script and now it brews a whole stack but it doesn’t restack them

#include “x2_inc_spellhook”
void main()
{
object oTarget = GetSpellTargetObject();
int nStack = GetItemStackSize(oTarget);

int nRet = (CIGetSpellWasUsedForItemCreation(oTarget));

SetExecutedScriptReturnValue (nRet);

if (nRet == TRUE)
{   int nCount = 1;
    while (nCount < nStack)
        { CIGetSpellWasUsedForItemCreation(oTarget);
        nCount++;
        }
}

}

I tried making another loop in the acquire item script to find an existing potion with a matching name in my inventory, delete it, and increase the stack size of the entering potion by the existing stack size. It just deletes all incoming potions : /

object oItem = GetModuleItemAcquired();
object oPlayer=GetItemPossessor(oItem);

if ( GetBaseItemType(oItem) == BASE_ITEM_ENCHANTED_POTION)
{ string sPotion = GetName(oItem, FALSE);
object oExistPotion = GetFirstItemInInventory(oPlayer);

             while (GetIsObjectValid(oExistPotion)==TRUE)
                    {
                   if (GetName(oExistPotion,FALSE)==sPotion)
                        {int nExistPotion = GetItemStackSize(oExistPotion);
                       DestroyObject(oExistPotion,0.0);
                        SetItemStackSize(oItem, nExistPotion+1);
               
                        }
                   
                      oExistPotion =  GetNextItemInInventory(oPlayer);
                     }
     }

Hi
as far as i can see, your script will delete any potion with a certain name. The new aquired item is not separated from the inventory, the loop will kill it as well.

I would try the following strategy:
Save the blueprint ID of the item to a variable
Use the loop to count all the items with that name (Adding the stacksizes)
delete the items
** End of the the loop**

Create a new item with the correct stacksize

Edit: After some thinking I’ve change the suggested strategy. It does only covers the On_Aquire event.

@bumblebee12

You need to keep the “count” and “set stack size” apart. So, it will be a combination of your two scripts.

i.e. Do a count to determine how many you want to create. Then use something like …

SetItemStackSize(oItem, nCount);

after you have created the single oItem. (Do not place this function inside the loop.)

I hope that makes sense … Ask if not.

Basically, once you know how many you need, just run SetItemStackSize(oItem, nCount); on the oItem to set its stack size.

EDIT: Handling stacked items (and consolidating them upon acquisition) was an exceedingly difficult piece of code I had to work with when I looked at something like this. The problem is, NWN semi-automatically does its own thing when handling stacked items, which means such item objects may not be what you think they are (due to the way stacking works) and so requires careful checking and timing. EDIT: My own consolidation code was done in NWN2. I did not do anything like this when I coded NWN1.

Thanks, Lance.

/ This script goes in the “Actions Taken” tab of a
// conversation. It will reward the PC 10 gold and
// 10 XP for every item they possess with the tag
// “goblin_ear”.
void main()
{
// First, get the PC being spoken to
object oPC = GetPCSpeaker();
// Now, find the first item in that PC’s inventory
object oItem = GetFirstItemInInventory(oPC);
// Start the loop. The next statement says to
// stay in the loop until “oItem” no longer points
// to a valid object. This will happen as soon as
// we’ve looped through every one of the PC’s items.
while (GetIsObjectValid(oItem))
{
// Check the tag on the current item
if (GetTag(oItem) == “goblin_ear”)
{
// Statements within these brackets will
// be run for each item that matches the
// “goblin_ear” tag.
// The next two lines give the rewards:
// 10 gold and 10 XP.
GiveGoldToCreature(oPC, 10);
GiveXPToCreature(oPC, 10);
// Now take the ear from the PC. Note that
// this doesn’t really take the ear and give
// it to the NPC; it just destroys it. Why
// do NPCs give money for these things,
// anyway? Who wants a bunch of rotting ears
// in their pockets?
DestroyObject(oItem);
}
// Now move on to the next item
oItem = GetNextItemInInventory(oPC);
} // End while loop
} // End script

May be it help you, just change give_gold for give_item

See this pinned thread for instructions on how to post code in these threads. It is essential that you use one of the three (preferably either [code] [/code] or ```) as Discourse automatically converts your code’s " into the 66/99 style. This means that your code throws syntax errors when you try to compile it.

Here is your code in a code box -

/ This script goes in the "Actions Taken" tab of a
// conversation. It will reward the PC 10 gold and
// 10 XP for every item they possess with the tag
// "goblin_ear".
void main()
{
    // First, get the PC being spoken to
    object oPC = GetPCSpeaker();

    // Now, find the first item in that PC’s inventory
    object oItem = GetFirstItemInInventory(oPC);

    // Start the loop. The next statement says to
    // stay in the loop until "oItem" no longer points
    // to a valid object. This will happen as soon as
    // we’ve looped through every one of the PC’s items.

    while (GetIsObjectValid(oItem))
    {
        // Check the tag on the current item

        if (GetTag(oItem) == "goblin_ear")
        {
            // Statements within these brackets will
            // be run for each item that matches the
            // "goblin_ear" tag.
            // The next two lines give the rewards:
            // 10 gold and 10 XP.

            GiveGoldToCreature(oPC, 10);
            GiveXPToCreature(oPC, 10);

            // Now take the ear from the PC. Note that
            // this doesn’t really take the ear and give
            // it to the NPC; it just destroys it. Why
            // do NPCs give money for these things,
            // anyway? Who wants a bunch of rotting ears
            // in their pockets?

            DestroyObject(oItem);
        }
        // Now move on to the next item
        oItem = GetNextItemInInventory(oPC);
    }
}

This has the added advantage that you get a copy button when you hover the mouse pointer over the code.

TR