Skip to content

Automatic item stack bugging

Hello,
I am fairly new to the scripting in NWN, but I am not new to the programming (ASM,C++,COBOL).
My friend recently revived very old module where we began to play nwn 20 years back.

The problem is that when PC acquire item, that item does not stack into the item stack.
It is possible to stack the item manually after.
This does not happen and stacking work correcly ONLY when players are trading between each other.

I found out script attached to module event OnAcquireItem:
void main ()
{
    // WPS - Událost Module OnAcquire (Lootovatelná PW mrtvola)
    if(GetIsDM(GetModuleItemAcquiredBy()) || GetIsPC(GetModuleItemAcquiredBy()))
        SetLocalInt(GetModuleItemAcquired(), "PCItem", 1);
}

This is used to distinguish if the item was PC owned or not, for various reasons like cleaning shops from player items.


Can anybody point me to the right directions please?

Comments

  • ProlericProleric Member Posts: 1,316
    The game stores a stack as a single object, with properties including resref and stack size.

    Consequently, local variables can only be assigned to the stack, not to the items in the stack.

    When you assign a local variable to an acquired item, the game puts it in a new stack, because that property makes it different from any existing stack.

    Arguably, it is a bug that you can then merge the stacks manually.

    Depending which stack is on top, the local variable may disappear or apply to the whole stack.

    For this reason, it's better to avoid local variables on stackable items.

    Depending on how and when the script uses the flag, it could be set on the module, PC or a specially-created unstackable dummy item.

  • iXtremistiXtremist Member Posts: 13
    Many thanks for the comment and explanation - i will try to remove the variable assign.
    Any idea how to solve cluttering of the mechants invetories by player-sold items?
  • iXtremistiXtremist Member Posts: 13
    Fixed by:

    NWNX_TWEAKS_COMPARE_VARIABLES_WHEN_MERGING = FALSE
    When trying to merge items, local variables are also considered.
  • MelkiorMelkior Member Posts: 204
    iXtremist wrote: »
    Many thanks for the comment and explanation - i will try to remove the variable assign.
    Any idea how to solve cluttering of the mechants invetories by player-sold items?

    There are several ways to declutter merchant inventories of player-sold items. Most of them involve using some kind of timer.

    You can just make a script which runs on store close, and which removes all items in the store and then replaces them with a "standard set" of equipment for that shop, but players might not like this if they accidentally sell something and then have to get more money to buy it back but discover that it's been destroyed before they can return.

    Another possiblity is to use a module heartbeat which keeps a counter running and periodically cleans out shops and replaces their contents, but this still has the possibility of PCs losing items which they intended to buy back. However, solving this problem becomes progressively more complicated the more "player safe" you try to make it.
Sign In or Register to comment.