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

[JASS] Stack charged items

Status
Not open for further replies.
Level 2
Joined
Apr 6, 2005
Messages
4
K, so I have the following, but it crashes the game, I cannot see a single thing wrong with it. Any help here would be much appreciated!

Trigger Name:
"Stack Items"

Initialize:
Unit acquires item

Conditions:
Unit needs to be a hero
Item needs to be charged

Action:
Combine all items of type acquired in one inventory slot

Code:
function Trig_Stack_Items_Conditions takes nothing returns boolean
    if ( not ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true ) ) then
        return false
    endif
    if ( not ( GetItemType(GetManipulatedItem()) == ITEM_TYPE_CHARGED ) ) then
        return false
    endif
    return true
endfunction

function HasItemtype takes unit whichUnit, item this returns item  
  local integer i = 0 
  local item whichItem = null  
  local integer itemType = GetItemTypeId(this)  
    if whichUnit != null then  
      loop  
        exitwhen i > 6 
        set whichItem = UnitItemInSlot(whichUnit, i)  
        if GetItemTypeId(whichItem) == itemType and whichItem != this then  
          return whichItem 
        endif  
        set i = i + 1 
      endloop  
    endif  
  return null 
endfunction   

function StackItem takes unit whichHero, item whichItem returns nothing  
  local item stack = HasItemtype(whichHero,whichItem)  
  local integer itemCharges = GetItemCharges(stack)  
  if stack != null and stack != whichItem and itemCharges > 0 then  
    call SetItemCharges( stack, itemCharges+ GetItemCharges(whichItem))  
    call RemoveItem( whichItem)  
  endif 
endfunction 

//===========================================================================
function InitTrig_Stack_Items takes nothing returns nothing
    set gg_trg_Stack_Items = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Stack_Items, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddCondition( gg_trg_Stack_Items, Condition( function Trig_Stack_Items_Conditions ) )
    call TriggerAddAction( gg_trg_Stack_Items, function StackItem )
endfunction
 
Status
Not open for further replies.
Top