I need a store randomization script


#1

I want to run it on area load and delete a small number of items from a store I will identify by tag. Essentially it will simulate other customers making purchases since the last time the player visited. That will increase pressure on the players to pick up whatever gear they need asap before it gets sold. It would help if the store gold increased by the correct amount as well but I can work around that.

Any takers?


#2

I did something like that once in the new NWN2 icons scripts. Possibly you can modify those to your needs.


#3

I’ll take a look rj. Thanks!


#4

you could also try this (untested) code

    object oStore = GetObjectByTag("store_tag"); // tag of Store
    if (GetIsObjectValid(oStore))
    {
        object oItem = GetFirstItemInInventory(oStore);
        while (GetIsObjectValid(oItem))
        {
            if (!Random(100)) // 1 pct to delete item from Store
            {
                int iStack = GetItemStackSize(oItem);
                if (iStack == 1)
                {
                    DestroyObject(oItem);
                }
                else
                {
                    int iSize = Random(iStack) + 1;
                    if (iSize == iStack)
                    {
                        DestroyObject(oItem);
                    }
                    else
                        SetItemStackSize(oItem, iSize, FALSE);
                }
            }
            oItem = GetNextItemInInventory(oStore);
        }
    }

technote: the iterator should not go funky 'cause DestroyObject() gets delayed till the script completes.


#5

Cool!

Heading out of town in the morning. Will test this next weekend.

Thanks kev!