Here is my upgraded version of Doubotis's code, it's dynamic enough that you don't need to create specific ones for different items or items that has different max charge. It also finish stacking the existing stacks before create a new one (ie. 7, 7 + 10 = 10, 10, 4)
It also doesn't annoyly moving the stacks everytime when you pick up something, like the one from the item utility library I saw here.
The only thing you need to worry when using this code is make sure you create a behaviour for tracking which items are stackable. I have all my stackable items a behaviour buff called stackable item.
Just bare in mind I only started making map 2 weeks ago, so this obviously won't be the best way to do it. Bugs is also a possibility, but so far I haven't detect any.
ItemStackingEventsUnit-AnyUnitPicksUpAnyItemLocalVariablesitem's max charge = 0 <Integer>newitem's current charge = 0 <Integer>existingitem's current charge = 0 <Integer>chargelink=""<String>Conditions((Triggeringinventoryitem)hasStackableItem)==trueActionsVariable-Setchargelink=(ValueofItems(String((Unittypeof(Triggeringinventoryitem))))"EffectCost.Charge.Link"forplayerAnyPlayer)Variable-Setitem's max charge = (Integer((Value of Items (String((Unit type of (Triggering inventory item)))) "EffectCost.Charge.CountMax" for player Any Player)))Variable-Setnewitem's current charge = (item'smaxcharge-(Integer((Chargesusedofchargechargelinkonunit(Triggeringinventoryitem)))))UnitGroup-Pickeachunitin(Allitemscarriedby(Triggeringunit))anddo(Actions)ActionsVariable-Setexistingitem's current charge = (item'smaxcharge-(Integer((Chargesusedofchargechargelinkonunit(Pickedunit)))))General-If(Conditions)thendo(Actions)elsedo(Actions)If(Unittypeof(Pickedunit))==(Unittypeof(Triggeringinventoryitem))(Pickedunit)!=(Triggeringinventoryitem)existingitem's current charge < item'smaxchargeThenGeneral-While(Conditions)aretrue,do(Actions)Conditionsexistingitem's current charge < item'smaxchargenewitem's current charge > 0Actions------- Negative charges adds items, positive charges remove itemsUnit-Add-1.0chargesusedforchargechargelinkonunit(Pickedunit)Unit-Add1.0chargesusedforchargechargelinkonunit(Triggeringinventoryitem)Variable-Modifyexistingitem's current charge: + 1Variable-Modifynewitem's current charge: - 1General-If(Conditions)thendo(Actions)elsedo(Actions)Ifnewitem's current charge <= 0ThenUnit-Remove(Triggeringinventoryitem)fromthegameElseElse
0
Here is my upgraded version of Doubotis's code, it's dynamic enough that you don't need to create specific ones for different items or items that has different max charge. It also finish stacking the existing stacks before create a new one (ie. 7, 7 + 10 = 10, 10, 4)
It also doesn't annoyly moving the stacks everytime when you pick up something, like the one from the item utility library I saw here.
The only thing you need to worry when using this code is make sure you create a behaviour for tracking which items are stackable. I have all my stackable items a behaviour buff called stackable item.
Just bare in mind I only started making map 2 weeks ago, so this obviously won't be the best way to do it. Bugs is also a possibility, but so far I haven't detect any.
0
Thanks for the tutorial, very helpful.