Weird question perhaps - Can you spawn an item to a store?

I’m sorry, but I’m not following what you’re saying here. You’re talking about a chest that has items, and then a random item from that chest should be available at a store? Why…? Are you saying I should to that? Again I don’t understand why? Or are you asking if that’s doable? I’m really confused.

The quest is that the smith says to bring him a book from a master. When you complete the quest he rewards you with gold but he also has a store in which for completing the quest several random masterwork weapons will be added to the inventory of the store. I have a chest that has a masterwork weapon of each kind in a place that is off-limits during game play. I was wondering if there is a script that would select one of the items from that chest and add it to the store’s inventory. If I can get it to work even once then I can just have the conversation run the script 4 times and that part of the story is complete.

// This will grab a random item out of a chest and create it in a store.
// The random item in the chest will then be destroyed so it isn't used again.

void main()
{
	object oChest = GetObjectByTag("chest_tag");
	object oStore = GetObjectByTag("store_tag");
	int n;
	
	// get total items in chest
	object oItem = GetFirstItemInInventory(oChest);
	while (GetIsObjectValid(oItem))
	{
		n++;
		oItem = GetNextItemInInventory(oChest);
	}
	
	// pick random item in chest and transfer it to the store
	int nRandom = Random(n) + 1;
	n = 0;
	oItem = GetFirstItemInInventory(oChest);
	while (GetIsObjectValid(oItem))
	{
		n++;
		if (n == nRandom)
		{
			CopyItem(oItem, oStore);
			DestroyObject(oItem);
			return;
		}
		
		oItem = GetNextItemInInventory(oChest);
	}
}
2 Likes

Thanks.

I just did something and I don’t know if it works with stores but it’s pretty simple and doesn’t involve writing scripts, which is why I managed it.

Put items that you want to appear after a quest happens in an npc’s inventory, then during the conversation using the ga_give_inventory script in the conversation editor steal them all off him/ her and put it in the container of your choice. Don’t forget to select all inventory items only with a 1 in the last box.

As I said I’m not sure about stores but they have a tag so it might work.

4 Likes