Will this remove items script work?

I was trying to make a script called from a conversation where the PC and the party’s whole equipment is being transefered to a chest while they get imprisoned. As it is, a few of the companions will have items that are “cursed” (not really cursed, but they have a curse flag as to not be able to remove them) and those I don’t want transfered to the chest. I haven’t tested this script yet, but at least it compiles. I based this script on one that I found on the NWN Scripts Archive:

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Script by Astaroth. Modified by andgalf.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void main()
{

    object oInvItem;
    
    object oPC = GetFirstPC();
	object oChest = GetObjectByTag("u_chest");
    
 
        // Only clear inventory if we haven't already done it before
        if (GetLocalInt(oPC, "CLEAR_INV_PC") == 0)
        {
            oInvItem = GetFirstItemInInventory(oPC);
            while (oInvItem != OBJECT_INVALID)
            {
                
                CopyItem(oInvItem,oChest,TRUE);
                oInvItem = GetNextItemInInventory(oPC);
            }
            // Since GetNextItemInInvetory() seems to not return equipped items,
            // we need to manually remove them one by one.
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_ARMS, oPC)) )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_ARROWS, oPC))  )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_BELT, oPC))  )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_BOLTS, oPC))  )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_BOOTS, oPC))  )
                CopyItem(oInvItem,oChest,TRUE);
				DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_BULLETS, oPC))  )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_CARMOUR, oPC))  )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_CHEST, oPC))  )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_CLOAK, oPC))  )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_CWEAPON_B, oPC))  )
                CopyItem(oInvItem,oChest,TRUE);
				DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_CWEAPON_L, oPC))  )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_CWEAPON_R, oPC))  )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_HEAD, oPC))  )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oPC))  )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_LEFTRING, oPC))  )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_NECK, oPC))  )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC))  )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_RIGHTRING, oPC))  )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            
            SetLocalInt(oPC, "CLEAR_INV_PC", 1);
        }
		
		if(GetGlobalInt("CLEAR_INV_COMPANIONS") == 0)
		{
			object oFM =  GetFirstFactionMember(oPC, FALSE);
        	while(GetIsObjectValid(oFM))
        	{
            	object oInvItemFM = GetFirstItemInInventory(oFM);
            	while (oInvItem != OBJECT_INVALID  && !GetItemCursedFlag(oInvItem))
            	{
                
                CopyItem(oInvItem,oChest,TRUE);
				DestroyObject(oInvItem,0.5,FALSE);
                oInvItem = GetNextItemInInventory(oFM);
            	}
            // Since GetNextItemInInvetory() seems to not return equipped items,
            // we need to manually remove them one by one.
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_ARMS, oFM))  && !GetItemCursedFlag(oInvItem) )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_ARROWS, oFM))  && !GetItemCursedFlag(oInvItem) )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_BELT, oFM))  && !GetItemCursedFlag(oInvItem) )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_BOLTS, oFM))  && !GetItemCursedFlag(oInvItem) )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_BOOTS, oFM))  && !GetItemCursedFlag(oInvItem) )
                CopyItem(oInvItem,oChest,TRUE);
				DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_BULLETS, oFM))  && !GetItemCursedFlag(oInvItem) )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_CARMOUR, oFM))  && !GetItemCursedFlag(oInvItem) )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_CHEST, oFM))  && !GetItemCursedFlag(oInvItem) )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_CLOAK, oFM))  && !GetItemCursedFlag(oInvItem) )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_CWEAPON_B, oFM))  && !GetItemCursedFlag(oInvItem) )
                CopyItem(oInvItem,oChest,TRUE);
				DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_CWEAPON_L, oFM))  && !GetItemCursedFlag(oInvItem) )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_CWEAPON_R, oFM))  && !GetItemCursedFlag(oInvItem) )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_HEAD, oFM))  && !GetItemCursedFlag(oInvItem) )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oFM))  && !GetItemCursedFlag(oInvItem) )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_LEFTRING, oFM))  && !GetItemCursedFlag(oInvItem) )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_NECK, oFM))  && !GetItemCursedFlag(oInvItem) )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oFM))  && !GetItemCursedFlag(oInvItem) )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_RIGHTRING, oFM))  && !GetItemCursedFlag(oInvItem) )
                 CopyItem(oInvItem,oChest,TRUE);
				 DestroyObject(oInvItem,0.5,FALSE);
            
            SetGlobalInt("CLEAR_INV_COMPANIONS", 1);
            oFM = GetNextFactionMember(oPC, FALSE);
        	}
			
		}
}

Hmm, it seems to work, but I realized I have a problem with this that I didn’t anticipate. The PC and the party (being 4 companions) can have quite a lot of items, and the chest inventory is only 142 items. It got filled up. So how do you get around a thing like that? It doesn’t seem that the Toolset allows that a placeable has an inventory larger than 142…

EDIT: Is there some way to check if the inventory of the chest is full, and if it is, move the rest of the items to another chest that I place nearby?

andgalf… You could just use a chest for each companion, there’s a ga conversation script for this just have different tags for each companion’s chest. That makes it less annoying for the player too as it’s easy to give it back to the right person and doesn’t involve a lot of swapping about.

Unequip the player’s items on one line so you don’t have to do it one by one, then to get around the cursed items, if you know what they are and who has got them then just destroy them first on one line and give them back after the inventory strip.

1 Like

I’m sorry, but I don’t follow you here. This sentence is really strange.

That’s actually quite a good idea. I’ll have to redo the script then though. What is the ga script’s name, do you remember?

/*
	Make a chest for each party member and tag them chest1, chest2, chest3...
	This will unequip all party members and place all of their equipment into their
	respective chest.
*/

void GiveAll(object oFM, int nChest)
{
	object oContainer = GetNearestObjectByTag("chest" + IntToString(nChest));
	object oItem = GetFirstItemInInventory(oFM);

	while (GetIsObjectValid(oItem))
	{
        AssignCommand(oFM, ActionGiveItem(oItem, oContainer));
		oItem = GetNextItemInInventory(oFM);
	}
}

void UnequipAll(object oFM)
{
	int n;
	
	for (n = INVENTORY_SLOT_HEAD; n < INVENTORY_SLOT_CWEAPON_L; n++)
	{
		AssignCommand(oFM, ActionUnequipItem(GetItemInSlot(n)));
	}
}
				
void main()
{
	object oPC = GetFirstPC();
	object oFM = GetFirstFactionMember(oPC, FALSE);
	int nChest;
	 
	while(GetIsObjectValid(oFM))
   	{
		if (!GetAssociateType(oFM))
		{
			nChest++;	
			DelayCommand(0.0f, UnequipAll(oFM));
			DelayCommand(0.2f, GiveAll(oFM, nChest));
		}
			
		oFM =  GetNextFactionMember(oPC, FALSE);
	}
}
2 Likes

angalf… To clarify what confused you…

  1. Strip the PC and companions on the first conversation line so everything’s in the inventory.
  2. Use ga_destroy on the “cursed” items on the next line.
  3. Use ga inventory remove ( something like that ) to put each character’s inventory in a different chest on the next line,
  4. use ga_give item to return the “cursed” items on the last line.

If you want to do it without the player seeing just set up a camera and film something while it happens.

That way you have stripped the whole inventory minus the cursed items, which were destroyed, and the players still has the cursed items because you remade them. So the cursed items aren’t in the chest and they wont have a double curse.

1 Like

@Tsongo - Thanks for clarifying.

@travus - I had a feeling you would show up with a super effecient script. :grinning: However, I still need to modify it, it seems, since I need the companions to keep their cursed items.

@travus - Would this work?

/*
	Make a chest for each party member and tag them chest1, chest2, chest3...
	This will unequip all party members and place all of their equipment into their
	respective chest. Script by travus. Small modification by andgalf.
*/

void GiveAll(object oFM, int nChest)
{
	object oContainer = GetNearestObjectByTag("chest" + IntToString(nChest));
	object oItem = GetFirstItemInInventory(oFM);

	while (GetIsObjectValid(oItem) && !GetItemCursedFlag(oItem))
	{
        AssignCommand(oFM, ActionGiveItem(oItem, oContainer));
		oItem = GetNextItemInInventory(oFM);
	}
}

void UnequipAll(object oFM)
{
	int n;
	
	for (n = INVENTORY_SLOT_HEAD; n < INVENTORY_SLOT_CWEAPON_L; n++)
	{
		AssignCommand(oFM, ActionUnequipItem(GetItemInSlot(n)));
	}
}
				
void main()
{
	object oPC = GetFirstPC();
	object oFM = GetFirstFactionMember(oPC, FALSE);
	int nChest;
	 
	while(GetIsObjectValid(oFM))
   	{
		if (!GetAssociateType(oFM))
		{
			nChest++;	
			DelayCommand(0.0f, UnequipAll(oFM));
			DelayCommand(0.2f, GiveAll(oFM, nChest));
		}
			
		oFM =  GetNextFactionMember(oPC, FALSE);
	}
}

EDIT: I’m not quite sure I understand the unequip all function you made. Does it only unequip a helmet and a weapon then or…how does that function work?

EDIT2: And the GetAssociateType…why do we need that? Is it so the script only removes items from the companions if they are companions and not henchmen perhaps?

The UnequipAll function in the below script will cycle through all slots except creature slots (i.e. claws, teeth, hide). The first slot being slot 0 (INVENTORY_SLOT_HEAD) and the last slot being less than 14 (INVENTORY_SLOT_CWEAPON_L).
Yes, the GetAssociateType function is there to ensure henchmen, familiars, summons, animal companions, and dominated aren’t checked.
Here’s a new script that does not transfer cursed items:

/*
	Make a chest for each party member and tag them chest1, chest2, chest3...
	This will unequip all party members and place all of their equipment into their
	respective chest. Cursed items not included.
*/

void GiveAll(object oFM, int nChest)
{
	object oContainer = GetNearestObjectByTag("chest" + IntToString(nChest));
	object oItem = GetFirstItemInInventory(oFM);

	while (GetIsObjectValid(oItem))
	{
        if (!GetItemCursedFlag(oItem)) AssignCommand(oFM, ActionGiveItem(oItem, oContainer));
		oItem = GetNextItemInInventory(oFM);
	}
}

void UnequipAll(object oFM)
{
	object o;
	int n;
	
	for (n = INVENTORY_SLOT_HEAD; n < INVENTORY_SLOT_CWEAPON_L; n++)
	{
		o = GetItemInSlot(n, oFM);
		if (!GetItemCursedFlag(o)) AssignCommand(oFM, ActionUnequipItem(o));
	}
}
				
void main()
{
	object oPC = GetFirstPC();
	object oFM = GetFirstFactionMember(oPC, FALSE);
	int nChest;
	 
	while (GetIsObjectValid(oFM))
   	{
		if (!GetAssociateType(oFM))
		{
			nChest++;	
			DelayCommand(0.0f, UnequipAll(oFM));
			DelayCommand(0.2f, GiveAll(oFM, nChest));
		}
			
		oFM = GetNextFactionMember(oPC, FALSE);
	}
}
2 Likes

I’ll try your new version then. Oddly enough my modified version of your script didn’t quite work as intended. Maybe I put the !GetItemCursedFlag(oItem) in the wrong place? As it was now all the PCs items were stripped and put in the right container and also one of the companions. The other two companions didn’t transfer any of their items to the chests. They both had cursed items though, so I guess I made a mistake, though I don’t see how. My version was this:

while (GetIsObjectValid(oItem) && !GetItemCursedFlag(oItem))
	{
        AssignCommand(oFM, ActionGiveItem(oItem, oContainer));
		oItem = GetNextItemInInventory(oFM);
	}

while yours

while (GetIsObjectValid(oItem))
	{
        if (!GetItemCursedFlag(oItem)) AssignCommand(oFM, ActionGiveItem(oItem, oContainer));
		oItem = GetNextItemInInventory(oFM);
	}

I don’t quite understand the difference here. I think they both should have worked. @travus I’ll try your version ingame now.

EDIT: I think I’ve found what’s wrong (not 100% sure though). Part of the problem is I only did 4 chests when there were supposed to be 5.

  • Minor Spoilers in the script for my upcoming module

I got a suggestion on the Discord forum, since I posted this question there too. Sve suggested that I’d make 5 bags and then put all the bags in one chest. I actually like that solution even better. I’ll see if I can tweak @travus script to make that work.

I reworked the script completely. I hope this works.

const string sROSTER_WINYEMA = "winyema2"; // note: this needs to be the *roster* string-id
const string sROSTER_THENUEH = "thenueh"; // note: this needs to be the *roster* string-id
const string sROSTER_QURFASA = "qurfasa2"; // note: this needs to be the *roster* string-id
const string sROSTER_EFELGOR = "efelgor"; // note: this needs to be the *roster* string-id


void GiveAll(object oFM, string sBag)
{
	object oContainer = GetObjectByTag(sBag);
	object oItem = GetFirstItemInInventory(oFM);

	while (GetIsObjectValid(oItem))
	{
        if (!GetItemCursedFlag(oItem)) AssignCommand(oFM, ActionGiveItem(oItem, oContainer));
		oItem = GetNextItemInInventory(oFM);
	}
}

void UnequipAll(object oFM)
{
	object o;
	int n;
	
	for (n = INVENTORY_SLOT_HEAD; n < INVENTORY_SLOT_CWEAPON_L; n++)
	{
		o = GetItemInSlot(n, oFM);
		if (!GetItemCursedFlag(o)) AssignCommand(oFM, ActionUnequipItem(o));
	}
}

void CreateBags()
{

	object oPC = GetFirstPC();

	object oWinyema = GetObjectFromRosterName(sROSTER_WINYEMA);
	object oThenueh = GetObjectFromRosterName(sROSTER_THENUEH);
	object oQurfasa = GetObjectFromRosterName(sROSTER_QURFASA);
	object oEfelgor = GetObjectFromRosterName(sROSTER_EFELGOR);

	CreateItemOnObject("bag1",oPC,1,"bag1",0);
	CreateItemOnObject("bag2",oWinyema,1,"bag2",0);
	CreateItemOnObject("bag3",oThenueh,1,"bag3",0);
	CreateItemOnObject("bag4",oQurfasa,1,"bag4",0);
	CreateItemOnObject("bag5",oEfelgor,1,"bag5",0);
		
	
}

void MoveBagsToChest()
{

	object oBag1 = GetObjectByTag("bag1");
	object oBag2 = GetObjectByTag("bag2");
	object oBag3 = GetObjectByTag("bag3");
	object oBag4 = GetObjectByTag("bag4");
	object oBag5 = GetObjectByTag("bag5");
	
	object oChest = GetObjectByTag("chest1");
	
	ActionGiveItem(oBag1,oChest,FALSE);
	ActionGiveItem(oBag2,oChest,FALSE);
	ActionGiveItem(oBag3,oChest,FALSE);
	ActionGiveItem(oBag4,oChest,FALSE);
	ActionGiveItem(oBag5,oChest,FALSE);
	

}

				
void main()
{
	object oPC = GetFirstPC();

	object oWinyema = GetObjectFromRosterName(sROSTER_WINYEMA);
	object oThenueh = GetObjectFromRosterName(sROSTER_THENUEH);
	object oQurfasa = GetObjectFromRosterName(sROSTER_QURFASA);
	object oEfelgor = GetObjectFromRosterName(sROSTER_EFELGOR);

	UnequipAll(oWinyema);
	UnequipAll(oThenueh);
	UnequipAll(oQurfasa);
	UnequipAll(oEfelgor);
	
	CreateBags();	 

	DelayCommand(0.2f, GiveAll(oPC,"bag1"));
	DelayCommand(0.2f, GiveAll(oWinyema,"bag2"));
	DelayCommand(0.2f, GiveAll(oThenueh,"bag3"));
	DelayCommand(0.2f, GiveAll(oQurfasa,"bag4"));
	DelayCommand(0.2f, GiveAll(oEfelgor,"bag5"));
	
	DelayCommand(1.0, MoveBagsToChest());
	
}

@andgalf,

Do you allow players to use “containers” with their PCs? E.g. Bags. (You cannot place containers within containers.)

How are you handling items inside containers if so?

Also, if PCs have many items, you may wish to consider adding a gradually increasing delay between each iteration of a PC within the loop.

Moving items into chests can actually be quite involved, especially with multiple PCs and many items within various containers and states. (If I recall correctly, when I needed something like this, I ended up using the PCs heartbeats to help move all items when it was their heartbeat turn … although careful delays should also work.))

Just tested this out and it didn’t work. Probably because containers can’t contain containers. Alright, I give up. I’ll go back to travus’ version with 5 chests instead.

EDIT: I just remembered that you may get hold of a bag of holding at one point earlier in the module. Sigh Why can’t things ever be easy with NWN2.

See my previous post … and you may still encounter issues as I express in the post above. I can speak from experience, as sometimes such scripts may work fine until:-

a) The party has more items than a previous test.
b) Containers become involved.

Just saying …

That’s what I meant. You pointed it out, and I think that might have been the case.

EDIT: If you looked at my script you saw that I created containers to move to a container.

Yeah … They can be a pain to deal with … as can a lot of items that cause the script to simply stop working half way through the loops.

As an example, I had a script that was designed to check items on a party as they entered my second module (to remove old stuff), and I ended up spending a lot of time to make that work correctly. i.e. Just looping through many items was difficult for the script, let alone asking it to give the item to something else. i.e. Looping a couple of items on a couple of PCs may work OK, but when it comes to 50 plus items on a party of 5-6 (I don’t know how many you intend to loop), then it may struggle.

1 Like

Is there perhaps a script to empty a bag first, that’s in a companion’s inventory, before moving it to a chest?

There are the PC and 4 companions, so 5 in total. You don’t have that much money in this module, but you can still pick up quite a lot of things, so there might be issues…maybe. With my test ingame I’m using a PC that has quite a lot of stuff, but as I said you can’t afford to buy that many items, so I think it might be ok.

Still there is the bag of holding that might become a problem.

The easiest way is to check if the current object being tested is a “container” and then use CopyObject (I believe), which can be used to move an entire container (with contents) to a placeable object. HOWEVER, you need to do this test before you then move individual items to the placeable object. Therefore, it is a two-part function, which when also trying to determine which items may or may not be in containers that may or may not be moved, gets very confusing very fast.

I ended up rewriting my own such scripts about four times (between updates) before it finally worked … I hope. :cold_face:

All I can do at this stage is point out potential pitfalls for you, but individual and specific requirements to suit your specific needs, you will need to identify and check for in each loop.

You mean ActionGiveItem perhaps? travus’ already used that function and I did too in my reworked (non-working) version of the script.