• 0

    posted a message on Inventories and item stacks/stacking?

    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.

    Item Stacking
        Events
            Unit - Any Unit Picks Up Any Item
        Local Variables
            item's max charge = 0 <Integer>
            new item's current charge = 0 <Integer>
            existing item's current charge = 0 <Integer>
            charge link = "" <String>
        Conditions
            ((Triggering inventory item) has Stackable Item) == true
        Actions
            Variable - Set charge link = (Value of Items (String((Unit type of (Triggering inventory item)))) "EffectCost.Charge.Link" for player Any Player)
            Variable - Set item's max charge = (Integer((Value of Items (String((Unit type of (Triggering inventory item)))) "EffectCost.Charge.CountMax" for player Any Player)))
            Variable - Set new item's current charge = (item's max charge - (Integer((Charges used of charge charge link on unit (Triggering inventory item)))))
            Unit Group - Pick each unit in (All items carried by (Triggering unit)) and do (Actions)
                Actions
                    Variable - Set existing item's current charge = (item's max charge - (Integer((Charges used of charge charge link on unit (Picked unit)))))
                    General - If (Conditions) then do (Actions) else do (Actions)
                        If
                            (Unit type of (Picked unit)) == (Unit type of (Triggering inventory item))
                            (Picked unit) != (Triggering inventory item)
                            existing item's current charge < item's max charge
                        Then
                            General - While (Conditions) are true, do (Actions)
                                Conditions
                                    existing item's current charge < item's max charge
                                    new item's current charge > 0
                                Actions
                                    ------- Negative charges adds items, positive charges remove items
                                    Unit - Add -1.0 charges used for charge charge link on unit (Picked unit)
                                    Unit - Add 1.0 charges used for charge charge link on unit (Triggering inventory item)
                                    Variable - Modify existing item's current charge: + 1
                                    Variable - Modify new item's current charge: - 1
                                    General - If (Conditions) then do (Actions) else do (Actions)
                                        If
                                            new item's current charge <= 0
                                        Then
                                            Unit - Remove (Triggering inventory item) from the game
                                        Else
                        Else
    
    Posted in: Miscellaneous Development
  • 0

    posted a message on [Outdated] SC2Layout Files: How to adjust them

    Thanks for the tutorial, very helpful.

    Posted in: Tutorials
  • To post a comment, please or register a new account.