• 🏆 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] Auto Combiner for potions from DOTA Template

Status
Not open for further replies.
Level 1
Joined
Aug 11, 2007
Messages
5
Auto Combiner for potions from DOTA Works!!

It works like a charm now.

JASS:
function Trig_Combine_Items_Conditions takes nothing returns boolean
    if ( not ( GetItemCharges(GetManipulatedItem()) > 0 ) ) then
        return false
    endif
    if ( not ( udg_Combine_Charged_Items == true ) ) 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 = udg_Combine_Charges_Max
    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_Charged_Items takes nothing returns nothing
    set gg_trg_Combine_Charged_Items_3 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Combine_Charged_Items_3, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddCondition( gg_trg_Combine_Charged_Items_3, Condition( function Trig_Combine_Items_Conditions ) )
    call TriggerAddAction( gg_trg_Combine_Charged_Items_3, function Trig_Combine_Items_Actions )
endfunction

Variables:
Combine_Charged_Items needs to be on True

Combine_Charges_Max the number of charges that are maximum (your choise, bot not 0)

This works now for every combinable item
Thanks to DOTA for trigger

BTW Reaper2008 trigger down doesn't work for me, the items just disappear
 
Last edited:
Level 12
Joined
Jul 27, 2008
Messages
1,181
This is really inefficient, plus all caps is :thumbs_down:

Here is a better version:
JASS:
function Trig_Combine_Items_Conditions takes nothing returns boolean
    return GetItemCharges(GetManipulatedItem()) > 0 and udg_Combine_Charged_Items == true
endfunction

function Trig_Combine_Items_Actions takes nothing returns nothing
    local integer itemCount = 0
    local integer itemLoop = 0
    local integer charges = 0
    local item newItem = GetManipulatedItem()
    local unit ourUnit = GetManipulatingUnit()

    loop
        exitwhen itemLoop > 6
        
        if GetItemTypeId(newItem) == GetItemTypeId(UnitItemInSlot(ourUnit, itemLoop)) then
        
            if (GetItemCharges(UnitItemInSlot(ourUnit, itemLoop)) + GetItemCharges(newItem)) <= udg_Combine_Charges_Max then
            
                if UnitItemInSlot(ourUnit, itemLoop) != newItem then
                    set charges = (GetItemCharges(UnitItemInSlot(ourUnit, itemLoop))) + GetItemCharges(newItem)
                    call SetItemCharges(UnitItemInSlotBJ(ourUnit, itemLoop), charges)
                    call RemoveItem(newItem)
                    set itemLoop = 7
                endif
                
            endif
            
        endif
        
        set itemLoop = itemLoop + 1
    endloop
    
    set newItem = null
    set ourUnit = null
endfunction

//===========================================================================
function InitTrig_Combine_Charged_Items takes nothing returns nothing
    local trigger lt_CombineChargedItems = CreateTrigger()
    
    call TriggerRegisterAnyUnitEventBJ(lt_CombineChargedItems, EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerAddCondition(lt_CombineChargedItems, Condition(function Trig_Combine_Items_Conditions))
    call TriggerAddAction(lt_CombineChargedItems, function Trig_Combine_Items_Actions)
endfunction
 
Level 6
Joined
Mar 20, 2008
Messages
208
Having to hit the shift key every time you type a variable is :thumbs_down:

Heres an even better one, building off of reaper (Not sure why item disappears though with his, or if it disappears with revised version) :thumbs_up:

JASS:
function Trig_Combine_Items_Conditions takes nothing returns boolean
    return GetItemCharges(GetManipulatedItem()) > 0 and udg_Combine_Charged_Items
//Shouldn't need the == true if its a boolean variable
//I recommend getting rid of it, who imports a combine system and doesn't plan to use it?
endfunction

function Trig_Combine_Items_Actions takes nothing returns nothing
    local integer itemcount = 0
    local integer itemloop = 0
    local integer charges = 0
    local integer id = GetItemTypeId(newitem)

    local item newitem = GetManipulatedItem()
    local item tempitem
    local unit ourunit = GetManipulatingUnit()

    loop
        exitwhen itemloop > 6
        set tempitem = UnitItemInSlot(ourunit, itemloop)

        if id == GetItemTypeId(tempitem) then
            if tempitem != newitem then                
               set charges = GetItemCharges(tempitem) + GetItemCharges(newitem)
               if (charges) <= udg_Combine_Charges_Max then                            
                    call SetItemCharges(tempitem, charges)
                    call RemoveItem(newitem)
                    set itemloop = 7
                endif
           endif
        endif
        
        set itemloop = itemloop + 1
    endloop
    
    set tempitem = null
    set newitem = null
    set ourunit = null
endfunction

//===========================================================================
function InitTrig_Combine_Charged_Items takes nothing returns nothing
    local trigger lt_CombineChargedItems = CreateTrigger()
    
    call TriggerRegisterAnyUnitEventBJ(lt_CombineChargedItems, EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerAddCondition(lt_CombineChargedItems, Condition(function Trig_Combine_Items_Conditions))
    call TriggerAddAction(lt_CombineChargedItems, function Trig_Combine_Items_Actions)
endfunction
 
Level 12
Joined
Jul 27, 2008
Messages
1,181
It may be disabled for 100 reasons :p.

I always do the == true part, looks nicer.

Plus, camel notation is very nice, better than full smalls. Try to read a 300line code snippet if variable names are like loopintegerfirst. While loopIntegerFirst is easier to read.
 
Level 6
Joined
Mar 20, 2008
Messages
208
It may be disabled for 100 reasons :p.

I always do the == true part, looks nicer.

Plus, camel notation is very nice, better than full smalls. Try to read a 300line code snippet if variable names are like loopintegerfirst. While loopIntegerFirst is easier to read.

I can read all smalls just fine, try typing out 500 variables using camel :grin:
I still don't see why you would build a combine system and turn it on or off.
 
Status
Not open for further replies.
Top