Item stacking The following trigger "combines" the charges of 2 items together to save inventory slots.
(very useful): function Combine_Items_Conditions takes nothing returns boolean return GetItemCharges(GetManipulatedItem()) > 0 endfunction
function Combine_Items_Actions takes nothing returns nothing local item NEWITEM = GetManipulatedItem() local unit OURUNIT = GetManipulatingUnit() local integer MAXIMUM = 15 //The max no. of charges allowed local integer ITEMCOUNT = 0 local integer ITEMLOOP = 0 local integer CHARGES = 0
loop exitwhen ITEMLOOP > 6 if GetItemTypeId(NEWITEM) == GetItemTypeId(UnitItemInSlot(OURUNIT, ITEMLOOP)) then if GetItemCharges(UnitItemInSlot(OURUNIT, ITEMLOOP)) + GetItemCharges(NEWITEM) <= MAXIMUM then if not (UnitItemInSlot(OURUNIT, ITEMLOOP) == NEWITEM) then set CHARGES = GetItemCharges(UnitItemInSlot(OURUNIT, ITEMLOOP)) + GetItemCharges(NEWITEM) call SetItemCharges(UnitItemInSlot(OURUNIT, ITEMLOOP), CHARGES) call RemoveItem(NEWITEM) set ITEMLOOP = 7 endif endif endif if (ITEMLOOP < 7) then set ITEMLOOP = ITEMLOOP + 1 endif endloop
set NEWITEM = null set OURUNIT = null 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 Combine_Items_Conditions ) ) call TriggerAddAction( gg_trg_Combine_Items, function Combine_Items_Actions ) endfunction
To import this trigger into your map, simply create a new trigger called "Combine Items",
then go to Edit > Convert to custom script > hit ok > delete everything > copy + paste the above trigger into your's
Changing the ammount of stacking
Manny RPG's or ORPG's from warcraft 3 need an item stacking trigger... these are hard to find and imposible to make if you don't know how. This will help u get much further you already have the stacking trigger but now i will show u how to make the maximum number of stacks. Like potions that canbe stacked to 999 potions before it takes a new slot.
To change the ammount of items that can be stacked up maximum go this this piece of the trigger.
local item NEWITEM = GetManipulatedItem()
local unit OURUNIT = GetManipulatingUnit()
local integer MAXIMUM = 15 //The max no. of charges allowed
local integer ITEMCOUNT = 0
local integer ITEMLOOP = 0
local integer CHARGES = 0
Then change this part.
local integer MAXIMUM = 15 //The max no. of charges allowed
Replace the "MAXIMUM = 15" to "MAXIMUM = (number u desire)
EXAMPLE
local integer MAXIMUM = 999 //The max no. of charges allowed
now u'r items will stack up to 999 if you don't want other items to stack just make a trigger that only allows 1 of that item type.
+1 (вроде такого способа на страничке той нет - тоже очень быстр)int zzCTPop(usiegnnd int Map){ const static usiegnnd int SK5=0x55555555,SK3=0x33333333; const static usiegnnd int SKF0=0xF0F0F0F,SKFF=0xFF00FF; Map-=((Map>>1)&SK5); Map=(Map&SK3)+((Map>>2)&SK3); Map=(Map&SKF0)+((Map>>4)&SKF0); Map+=Map>>8; return (Map+(Map>>16))&0x3F;}