• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[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