• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[General] "A unit Acquires an item" does not work with stacks

Status
Not open for further replies.
Level 2
Joined
Mar 8, 2020
Messages
8
The event "Unit - A unit Acquires an item" does not work when a unit already has same type item with max stacks > 1.
For example a hero has 1 potion, he picks another potion and now he has 2 potions in one slot and the event will not work.

How to make this event work? Or what's the alternative? The only solution I can think of is to periodically check the number of stacks but it's ridiculous.


What exactly I want to do:

When hero acquires an item I want to create a new same type item at exactly same place on the ground. Then I disable possiblity for this hero to get that newly created item again.

Example: 1 potion lies on the ground and all players can get this one potion, but they can't pick it up second time. It does not work when hero already has a potion, because the event works only when a new item appears in the inventory, it does not work when a stack of item is increased.
Not sure if I made it easy to understand, sorry.

Update:
I just tried to disable built-in stacks system and use these:
Item Stacking System
or
Easy Item Stack 'n Split v2.7.4

I can make everything work with those but.

The problem is that to disable built-in stacks system I have to manually set Max Stacks parameter to 0 on ALL items. I don't really like this.

Also 3rd party systems like easy-item-stack-n-split does not allow you to pick up the item if all 6 slots are filled (you can do this with default item stacking) - but this is ok, not a big problem.
 
Last edited:
Level 5
Joined
Jun 12, 2018
Messages
148
The only solution I can think of is to periodically check the number of stacks but it's ridiculous.

Same.

I think you have to create your own custom system storing units and their picked-up items and then use a timer to periodically check if the number of stacks are > 1.

Maybe I'm wrong and someone will give you a simple solution.
 
Level 1
Joined
Aug 22, 2020
Messages
2
Some cool new features have been added to World Editor to do just what you want. Specifically, there's an event to catch item stacking. Check it out:

  • Events
    • Unit - A unit Had an item stack in inventory
  • Conditions
    • (Item-type of (Item getting charges)) Equal to Potion of Healing
  • Actions
    • Item - Create Potion of Healing at (Position of (Item giving charges))
    • Item - Set charges remaining in (Last created item) to ((Charges remaining in (Item getting charges)) - (Previous charges of item getting charges))
    • Item - Set charges remaining in (Item getting charges) to (Previous charges of item getting charges)
If you use this, be sure to remove the location (Position of (Item giving charges)) so it doesn't leak. Also, it might be safer in general to use the location of the unit instead of the item (for example, I'm not sure what the item's position is when one unit gives the item to another unit), but using the position of the item looks nicer.

You could also use the "Item Absorbing Manipulated Item" and "Manipulated Item Was Absorbed" with "A unit Acquires an item" to do what you want (assuming these new things all work correctly; I haven't tested them).

If you prefer to use jass, you can find the new related functions in common.j:
vJASS:
// For EVENT_PLAYER_UNIT_PICKUP_ITEM, returns the item absorbing the picked up item in case it is stacking.
// Returns null if the item was a powerup and not a stacking item.
constant native BlzGetAbsorbingItem takes nothing returns item
constant native BlzGetManipulatedItemWasAbsorbed takes nothing returns boolean

// EVENT_PLAYER_UNIT_STACK_ITEM
// Source is the item that is losing charges, Target is the item getting charges.
constant native BlzGetStackingItemSource takes nothing returns item
constant native BlzGetStackingItemTarget takes nothing returns item
constant native BlzGetStackingItemTargetPreviousCharges takes nothing returns integer

Using jass, you might also be able to change the "max stacks" of certain items to prevent stacking (using things like BlzSetItemIntegerField and the field 'ista') but, again, I can't promise those functions work correctly. The advantage of preventing the stacking from happening is that the handle of the picked up item would stay the same.
 
Status
Not open for further replies.
Top