Stacking inventory, Party inventory, Conditions/Actions

If I have a condition on a conversation line
gc_item_count with bParty = 1.
This is good, if speaker has none of item, but a companion does, it resolves true. Perfect.

Now on the Action, I have ga_take_item. It does not seem to take the item if the item is on a companion (or anyone who is not the active conversationalist)
I’ve tried putting a 1 in bAllPartyMembers, but 0 or 1 has no effect that I can see.

I decided to save inventory space and change my crafting materials to be a stackable Base type, e.g. Small Crafting Material or Misc Small Object. I tried others, anything with a Max Stack Size > 1
That didn’t help. use ga_take_item to take 1 and it takes the whole stack.

Do I just need to write custom script that, for example, does this:
A. How many in party?
B. How many needed?
C. Destroy all of them
D. Give back A - B

Or is there some dumb obvious thing I’m not doing? :slight_smile:
Is there already a built in function that returns how many of an item the party has across all members?

You could try using the ga_destroy_item script instead.

2 Likes

Thank you Travus, yes, that one works beautifully. Seems like all delete/destroy scripts always seem to work with no issues, doesn’t it?

My issue is getting consistent answer to A, how many of an item in the Party, particularly when it involves stacks of different sizes.

This might be useful to count stacks in the party:

/*
	Checks to see if there is greater than or equal to the nNumber of sItemTag
	in the bWholeParty, equipped or not. Use as a condition in dialog.
	
	sItemTag = Tag of item.
	nNumber = Number of items to meet or exceed.
	bWholeParty	= 0 speaker only, 1 whole party.
*/

#include "nw_i0_plot"

int GetNumEquipped(object oPC, string sItemTag)
{
	int nSlot, iTotal;
	object oItem;
	
    for (nSlot=0; nSlot<NUM_INVENTORY_SLOTS; nSlot++)
    {
		oItem = GetItemInSlot(nSlot, oPC);
	
		if (GetTag(oItem) == sItemTag)
		{
			iTotal += GetNumStackedItems(oItem);			
        }
    }
		
	return iTotal;
}

int StartingConditional(string sItemTag, int nNumber, int bWholeParty)
{
	object oPC = GetPCSpeaker();
	int nTotal;
	
	if (bWholeParty)
	{
		object oFM = GetFirstFactionMember(oPC, FALSE);		
	
		while (GetIsObjectValid(oFM))
		{
			nTotal += GetNumItems(oFM, sItemTag) + GetNumEquipped(oFM, sItemTag);
					
			oFM = GetNextFactionMember(oPC, FALSE);
		}
	}
	
	else nTotal = GetNumItems(oPC, sItemTag) + GetNumEquipped(oPC, sItemTag);

//	SendMessageToPC(oPC, "Total: " + IntToString(nTotal));	
	
	if (nTotal >= nNumber) return TRUE;
	
	return FALSE;
}
2 Likes

@THughes281

Dealing with stacked items can be tricky. Even the OC script has this in it …
“// NLC 9/9/08 - And, after 3 years, this works with stacked items.”

I just wanted to point out that if you have a large party and lots of items, including bags loads of stacked items, that this could result in a very large loop. I believe most of the time the engine can still cope with this, unless we also do another immediate check for another item in the same node.

i.e. If you had three items you wanted to check across all PCs in a party across all their equipment, including bags loads of items, a later loop could fail. For such situations, I ended up writing some dedicated scripts to cater for a selection of items to be checked in a six PC party with a lot of equipment.

Just something to bear in mind.

2 Likes

travus… Destroy is always my weapon of choice with items, all those poor merchants or quest givers never get anything but still have to pay !

3 Likes

ga_take_item uses a function that doesn’t handle stackable items … known bug, fixed in Nwn2Fixes /fwiw

4 Likes

And that solves a problem I was staring at last weekend.
All of you people rock!

4 Likes

Thank you all, I was able to get it working as I wanted it to.

gc_item_count with bParty = 1 works perfect for the condition, checks all party members, as well as bags on party members.

ga_destroy_item also with bPCFaction = 1 works for taking the required quantity off of the group. Tested stackable, tested items half in bag, half in inventory, tested half the requirement on one PC, half on another party member - all worked perfectly.

I had been using ga_take_item, not ever considering ga_destroy until shown me here, thanks. Not sure why I never even looked at destroy, lol.

Now, my tests were just with party of two, with only checking or taking a single item, and with minimal inventory on party members, so with Lance’s warnings, I’ll revisit later when back to full-party play testing. Hopefully not any issues!

Thank you to everyone for input.

4 Likes