• 🏆 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!

CombineChargedItem [vJASS]

This bundle is marked as useful / simple. Simplicity is bliss, low effort and/or may contain minor bugs.
simple copy and pste the Trigger to your map, set maximun at line:
set MAXIMUM = 99


function Trig_Combine_Items_Conditions takes nothing returns boolean
if ( not ( GetItemCharges(GetManipulatedItem()) > 0 ) ) then
return false
endif
return true
endfunction

function Trig_Combine_Items_Actions takes nothing returns nothing
local integer ITEMCOUNT
local integer ITEMLOOP
local integer CHARGES
local integer MAXIMUM
local item NEWITEM
local unit OURUNIT

set MAXIMUM = 99
set ITEMCOUNT = 0
set ITEMLOOP = 0
set CHARGES = 0
set NEWITEM = GetManipulatedItem()
set OURUNIT = GetManipulatingUnit()

loop
exitwhen ITEMLOOP > 6
if ((GetItemTypeId(NEWITEM)) == (GetItemTypeId(UnitItemInSlotBJ(OURUNIT, ITEMLOOP)))) then
if ((GetItemCharges(UnitItemInSlotBJ(OURUNIT, ITEMLOOP)) + GetItemCharges(NEWITEM)) <= MAXIMUM) then
if not ( (UnitItemInSlotBJ(OURUNIT, ITEMLOOP)) == (NEWITEM)) then
set CHARGES = (GetItemCharges(UnitItemInSlotBJ(OURUNIT, ITEMLOOP))) + GetItemCharges(NEWITEM)
call SetItemCharges( UnitItemInSlotBJ(OURUNIT, ITEMLOOP), CHARGES )
call RemoveItem( NEWITEM )
set ITEMLOOP=7
endif
endif
endif
if ( ITEMLOOP < 7 ) then
set ITEMLOOP = ITEMLOOP + 1
endif
endloop
endfunction

//===========================================================================
function InitTrig_Combine_Items takes nothing returns nothing
set gg_trg_Combine_Items = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Combine_Items, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddCondition( gg_trg_Combine_Items, Condition( function Trig_Combine_Items_Conditions ) )
call TriggerAddAction( gg_trg_Combine_Items, function Trig_Combine_Items_Actions )
endfunction


Keywords:
Combine, Item, Charge, System, Jass, Fusion,
Contents

CombineChargedItem [vJASS] (Map)

Reviews
14:11, 15th Nov 2009 TriggerHappy187: Even with all of the points below fixed, we don't need another one of these. Sorry. PM me if you felt I reviewed this wrong. This is not vJass. Inline your conditions function. You leak two handle...

Moderator

M

Moderator

14:11, 15th Nov 2009
TriggerHappy187:

Even with all of the points below fixed, we don't need another one of these. Sorry.

PM me if you felt I reviewed this wrong.

  • This is not vJass.
  • Inline your conditions function.
  • You leak two handle pointers (need to null the item and the unit).
  • You should store the item id to avoid so many function calls.
  • Your using lame BJ's.
  • You can directly initialize your locals instead of setting them after their declarations.
  • if ( ITEMLOOP < 7 ) then is completely useless.
 
Top