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

[Solved] How to increase item's number of charges by Trigger?

Status
Not open for further replies.
Level 4
Joined
Dec 12, 2012
Messages
96
Let's say my hero has a potion of healing in his inventory and he picks up another potion of healing on the ground. Normally the potions will occupy two slots in the hero's inventory. How can i combine two items of the same type and add their charges so i can save a slot in inventory?
 
Level 4
Joined
May 18, 2011
Messages
67
Let's say my hero has a potion of healing in his inventory and he picks up another potion of healing on the ground. Normally the potions will occupy two slots in the hero's inventory. How can i combine two items of the same type and add their charges so i can save a slot in inventory?

JASS:
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_charges takes nothing returns nothing
    set gg_trg_Combine_Items_charges = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Combine_Items_charges, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddCondition( gg_trg_Combine_Items_charges, Condition( function Trig_Combine_Items_Conditions ) )
    call TriggerAddAction( gg_trg_Combine_Items_charges, function Trig_Combine_Items_Actions )
endfunction

this?... TO CHANGE THE MAXIMUM, Change this line.

set MAXIMUM = 3

This will combine ANY items that have charges, REGARDLESS of 'item class'. hope this help...
 
Status
Not open for further replies.
Top