- Joined
- May 23, 2011
- Messages
- 179
How to combine charged items??
Prefer dropping the item first, then setting its life to 0, then remove it.
That trigger completely doesnt work ;o.
Your turning the trigger off at the very start forcing the trigger to not finish the remaining actions, as in it wont turn on again.
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 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Combine_Charged_Items, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddCondition( gg_trg_Combine_Charged_Items, Condition( function Trig_Combine_Items_Conditions ) )
call TriggerAddAction( gg_trg_Combine_Charged_Items, function Trig_Combine_Items_Actions )
endfunction
What does that do?
library Charges requires RegisterPlayerUnitEvent
globals
private constant integer MAX = 30
endglobals
private module Init
private static method onInit takes nothing returns nothing
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_PICKUP_ITEM, function thistype.run)
endmethod
endmodule
struct CombineCharges extends array
static boolean enabled = true
static method enable takes nothing returns nothing
set thistype.enabled = true
endmethod
static method disable takes nothing returns nothing
set thistype.enabled = false
endmethod
private static method run takes nothing returns nothing
local integer il = 0
local item in = GetManipulatedItem()
local integer cnew = GetItemCharges(in)
local item i
local unit u
local integer id
local integer ic
if enabled and cnew > 0 then
set u = GetManipulatingUnit()
set id = GetItemTypeId(in)
loop
exitwhen il > 6
set i = UnitItemInSlot(u,il)
set ic = GetItemCharges(i)
if id == GetItemTypeId(i) and ic + cnew <= MAX and i != in then
call SetItemCharges(i,ic + cnew)
call SetWidgetLife(in, 0.406)
call RemoveItem(in)
exitwhen true
endif
set il = il + 1
endloop
endif
set in=null
set i=null
set u=null
endmethod
implement Init
endstruct
endlibrary