• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Items] How do I make items stackable.

Status
Not open for further replies.
Level 5
Joined
Dec 3, 2012
Messages
117
Title says it all, how in the world do I make items stack :/

Need to stack random crappy items that can be sold and items needed for my gear upgrading system (See: [url="http://www.hiveworkshop.com/forums/world-editor-help-zone-98/triggers-upgrading-system-gear-233071/index2.html]Upgrade system[/url])
 
Level 18
Joined
May 11, 2012
Messages
2,103
JASS:
function Increasing_Item_Charges_Conditions takes nothing returns boolean
    return GetItemCharges(GetManipulatedItem()) > 0 
endfunction

function Increasing_Item_Charges_Actions takes nothing returns nothing
    local item NEWITEM = GetManipulatedItem()
    local unit OURUNIT = GetManipulatingUnit()
    local integer MAXIMUM = 30  //The max no. of charges allowed
    local integer ITEMCOUNT = 0
    local integer ITEMLOOP = 0
    local integer CHARGES = 0
    
    loop
        exitwhen ITEMLOOP > 6
        if GetItemTypeId(NEWITEM) == GetItemTypeId(UnitItemInSlot(OURUNIT, ITEMLOOP)) then
            if GetItemCharges(UnitItemInSlot(OURUNIT, ITEMLOOP)) + GetItemCharges(NEWITEM) <= MAXIMUM then
                if not (UnitItemInSlot(OURUNIT, ITEMLOOP) == NEWITEM) then                
                    set CHARGES = GetItemCharges(UnitItemInSlot(OURUNIT, ITEMLOOP)) + GetItemCharges(NEWITEM)
                    call SetItemCharges(UnitItemInSlot(OURUNIT, ITEMLOOP), CHARGES)
                    call RemoveItem(NEWITEM)
                    set ITEMLOOP = 7
                endif
            endif
        endif
        if (ITEMLOOP < 7) then
            set ITEMLOOP = ITEMLOOP + 1
        endif
    endloop

    set NEWITEM = null
    set OURUNIT = null
endfunction

function InitTrig_Increasing_Item_Charges takes nothing returns nothing
    set gg_trg_Increasing_Item_Charges = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Increasing_Item_Charges, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddCondition( gg_trg_Increasing_Item_Charges, Condition( function Increasing_Item_Charges_Conditions ) )
    call TriggerAddAction( gg_trg_Increasing_Item_Charges, function Increasing_Item_Charges_Actions )
endfunction

Create new trigger, name it Increasing Item Charges, convert it into custom script, delete everything in it and paste the code.

You're done
 
Last edited:
Level 30
Joined
Nov 29, 2012
Messages
6,637
Title says it all, how in the world do I make items stack :/

Need to stack random crappy items that can be sold and items needed for my gear upgrading system (See: [url="http://www.hiveworkshop.com/forums/world-editor-help-zone-98/triggers-upgrading-system-gear-233071/index2.html]Upgrade system[/url])

Here is some information on how to make Item Stacks: Item Stack. It is really a long trigger..... so you should follow everything. By the way, this is not by me just showing you a link on how to it.:thumbs_up:

Also, this trigger might not work. I suggest making your item into a Charged and adding number of charges so the trigger will work.
 
Level 14
Joined
Dec 29, 2009
Messages
931
I've had trouble getting the one linked in that tutorial to work.
It may stack some items, but others it may not.

If you have trouble with it as well, try this.
  • IS Run
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item level of (Item being manipulated)) Equal to 0
      • (Charges remaining in (Item being manipulated)) Greater than 0
      • (Item being manipulated) Not equal to (Item carried by (Triggering unit) of type (Item-type of (Item being manipulated)))
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) has an item of type (Item-type of (Item being manipulated))) Equal to True
        • Then - Actions
          • Item - Set charges remaining in (Item carried by (Triggering unit) of type (Item-type of (Item being manipulated))) to ((Charges remaining in (Item carried by (Triggering unit) of type (Item-type of (Item being manipulated)))) + (Charges remaining in (Item being manipulated)))
          • Hero - Drop (Item being manipulated) from (Triggering unit)
          • Item - Remove (Item being manipulated)
        • Else - Actions
It's just an edited version, but I haven't had any problems thus far.
 
Status
Not open for further replies.
Top