• 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.

[Trigger] Item stack charges help

Status
Not open for further replies.
Level 13
Joined
Sep 29, 2008
Messages
672
Noob here,
I was wondering how I can make items stack charges
when acquired, bought etc...

  • Events
    • Unit - A unit Acquires an item
  • Conditions
    • (Item-class of (Item being manipulated)) Equal to Charged
    • ((Hero manipulating item) has an item of type (Item-type of (Item being manipulated))) Equal to True
  • Actions
    • Set ItemManip = (Item being manipulated)
    • Set ItemAquiring = (Charges remaining in (Item being manipulated))
    • Set ItemType = (Item-type of ItemManip)
    • Item - Set charges remaining in (Item carried by (Hero manipulating item) of type ItemType) to ((Charges remaining in (Item carried by (Hero manipulating item) of type ItemType)) + ItemAquiring)
    • Item - Remove ItemManip
I think I'm already wrong in the condition
  • ((Hero manipulating item) has an item of type (Item-type of (Item being manipulated))) Equal to True
But atleast I tried. ^^

Sorry for being a noob. Just wanted my map to get done. This is the only thing that bothers.
 
Level 13
Joined
Sep 14, 2008
Messages
1,408
Where did you find the "Hero has an item of type"???
Never knew that that exists...

But I made it like this once:

  • Stack Items
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Item-type of (Item being manipulated)) Equal to YourItem
    • Actions
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item carried by (Triggering unit) in slot (Integer A)) Equal to (Item being manipulated)
            • Then - Actions
              • Set SlotNumber = (Integer A)
            • Else - Actions
      • For each (Integer B) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • (Integer B) Not equal to SlotNumber
                  • (Item-type of (Item carried by (Triggering unit) in slot SlotNumber)) Equal to (Item-type of (Item carried by (Triggering unit) in slot (Integer B)))
            • Then - Actions
              • Item - Set charges remaining in (Item carried by (Triggering unit) in slot (Integer B)) to ((Charges remaining in (Item carried by (Triggering unit) in slot (Integer B))) + (Charges remaining in (Item being manipulated)))
            • Else - Actions
 
Level 13
Joined
Sep 29, 2008
Messages
672
Do you know how to do Jass?
I found this script and It works but when it stacks uncharged items the item acquired disappears. How can you make this work only on charged class items? I don't know anything about this codes. I understand a little though.

JASS:
function Trig_Stacking_Actions takes nothing returns nothing
    local unit u = GetManipulatingUnit()
    local item i = GetManipulatedItem()
    local integer id = GetItemTypeId( GetManipulatedItem() )
    local item t = GetItemOfTypeFromUnitBJ( u, id )
    if ( UnitHasItemOfTypeBJ( u, id ) ) then
        if ( t != i ) then
            call SetItemCharges( t, ( GetItemCharges(t) + GetItemCharges(i) ) )
            call RemoveItem( i )
        endif
    endif
    set u = null
    set i = null
    set t = null
endfunction

//===========================================================================
function InitTrig_Stacking takes nothing returns nothing
    set gg_trg_Stacking = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Stacking, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( gg_trg_Stacking, function Trig_Stacking_Actions )
endfunction
 
JASS:
function Trig_Stacking_Conditions takes nothing returns boolean
    return GetItemType( GetManipulatedItem() ) == ITEM_TYPE_CHARGED
endfunction

function Trig_Stacking_Actions takes nothing returns nothing
    local unit u = GetManipulatingUnit()
    local item i = GetManipulatedItem()
    local integer id = GetItemTypeId( GetManipulatedItem() )
    local item t = GetItemOfTypeFromUnitBJ( u, id )
if ( UnitHasItemOfTypeBJ( u, id ) ) then
        if ( t != i ) then
            call SetItemCharges( t, ( GetItemCharges(t) + GetItemCharges(i) ) )
            call RemoveItem( i )
        endif
    endif
    set u = null
    set i = null
    set t = null
endfunction

//===========================================================================
function InitTrig_Stacking takes nothing returns nothing
    set gg_trg_Stacking = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Stacking, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( gg_trg_Stacking, function Trig_Stacking_Actions )
    call TriggerAddCondition( gg_trg_Stacking, Condition( function Trig_Stacking_Conditions ) )
endfunction

use this code and it should work.
If you want a brief explanation, the core of the code is those three lines (after the /=== )
JASS:
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Stacking, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( gg_trg_Stacking, function Trig_Stacking_Actions )
    call TriggerAddCondition( gg_trg_Stacking, Condition( function Trig_Stacking_Conditions ) )
The first one adds the event to the trigger.
The second onde adds the actions.
The third (which I added) adds the condition.

The event is equivalent to Unit - A unit acquires an item
The actions are all the lines in the function Trig_Stacking_Actions.
The condition is the first function (Trig_Stacking_Conditions). It will return true if the item type of the manipulated item is equal to Charged.
 
Last edited:
Status
Not open for further replies.
Top