Prevent Item Splitting

So, you can add things like SetLocalInt(oMod, “X2_L_DO_NOT_ALLOW_CRAFTSKILLS”, TRUE); in the OnModuleLoad event. Is there also one to prevent players from splitting stacks of items, like darts?

:thinking: Have you tried editing baseitems.2da to make stuff stop being stackable in the first place? There’s a “Stacking” column in it that has arrows/bullets/darts at 99, healers’ kits and potions at 10, and so on. You could try switching everything down to Stacking 1, see if that works.

Ammunition that is just a single unit each seems like it would get pretty annoying pretty fast, though. Ridiculously inventory-spammy, too.

It seems that OP wants to keep a stack of items intact rather than have no stacks whatsoever.

Unfortunately, the straightforward answer is no - players can stack and split items any way they want. You’d need to track (i.e. in OnHeartbeat handler) if a new stack of items with given tag appeared in the inventory and then merge them with other stacks. This is doable but may be confusing to players.

Surprisingly, merging two item stacks fires the OnUnacquireItem event, yet splitting does not fire the OnAcquireItem event… Seems like an oversight to me.

@TacticalERK can you explain why you want to stop splitting?

I would also be curious as to why you need to stop splitting.

This is often asked by builders who made some stackable miscelanious items that they want to prevent stack because when split, stacked items lose/share variables, lose undroppable flag and generally do a lot of funky stuff.

For this there are 2 way how to avoid it. 3 if we count NWNX.

If you just want to disallow players to unstack something like 10 pieces of potions then I cannot heĺp you, I can’t even imagine why would you want to do that in first place.

If you want the opposite - to prevent items to stack, then here are some ideas:

  1. whether the items stack of not depends on tag. If their tag differ they won’t stack. So you can randomize the tag of the item, try this functíon:

const string ALPHABET = “aAbBcC0dDeEfFg1GhHiI2jJkKl3LmMnN4oOpP5qQr6RsSt7TuUv8VxX9yYzZ_”;
string RandomTag()
string sTag;
int i;
int len = GetStringLength(ALPHABET);
for(;i < 8;i++)
sTag+= GetSubString(ALPHABET,Random(len),1);
return sTag;
So basically you create the item with custom tag that will be random thus the items won’t stack. This solution has holes though - if there is anything in your module that restores item tag such as persistent chest you need to re-randomize the item tag there as well.

  1. use new baseitem type that doesn’t stack. By default, miscelanious small/thin/med/large don’t stack. But I commonly see builders making them all stack and then running into this issue. So you want to make a copy of these baseitems with stacksize 1 and use ut for important items. Community patch has copies of misceanious items in it - however there it works opposite, default misc items are left unstacked and copies allows to stack, but it is easy to reverse this.

I have a container that when items are placed in it, the items are destroyed and players receive gold in exchange. The problem, is that players can unstack things like darts, throwing axes, etc and get 50 times the amount of gold they should be getting by selling 1 at a time instead of the stack of 50.

I think I might be thinking about this wrong and instead look at the script the container is using and have it check how big the stack is before giving the gold.

You could put in the OnDisturbed slot for the container a script that checks if there are items of a similar resref that are stackable and stacks them.

Yes, that’s what I’d do.