Potion Stacking

General talk about editing, cheating, and deprotecting maps.

Moderator: Cheaters

yeuyo
Newcomer
Posts: 9
Joined: February 3rd, 2008, 7:28 am
Title: Slacker
Location: Malaysia

Potion Stacking

Post by yeuyo »

Can anyone tell me how do you make the potion stacks?
Everytime I don't click me a potion it will use up another inventory slot even if there's only 1 charge there,is there a way to make it so that when you don't click me they all stack up together instead of wasting your inventory slots?
User avatar
weirdone2
Forum Staff
Posts: 926
Joined: June 3rd, 2007, 8:03 pm

Re: Potion Stacking

Post by weirdone2 »

Have a trigger that when you don't click me the pot if theirs already the same pot in inventory then it will remove the one ur buying now and increase the charges of the one already in inventory.
User avatar
Ozzapoo
The Flying Cow!
Posts: 2196
Joined: November 2nd, 2007, 10:34 pm
Location: Melbourne

Re: Potion Stacking

Post by Ozzapoo »

=\ No way to make it automatically stack without triggers?
Visit Ozzapoo.net, my blog and the home of AutoCP and Cheatpack Detector!
AutoCP3 now available for free!
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: Potion Stacking

Post by Aero »

Haha, nope.

I made a block of jass code that stacks all charged items (To a constant limit ie: 50).
Post if interested . . .
User avatar
Ozzapoo
The Flying Cow!
Posts: 2196
Joined: November 2nd, 2007, 10:34 pm
Location: Melbourne

Re: Potion Stacking

Post by Ozzapoo »

Yes please!!! :)
Visit Ozzapoo.net, my blog and the home of AutoCP and Cheatpack Detector!
AutoCP3 now available for free!
User avatar
Hot
Junior Member
Posts: 30
Joined: March 26th, 2008, 2:54 pm

Re: Potion Stacking

Post by Hot »

Here it is, I'm also using this for my map.
Spoiler:
Item Stack
function Trig_Item_Stack_Conditions takes nothing returns boolean
return GetItemCharges(GetManipulatedItem()) > 0
endfunction

function Trig_Item_Stack_Actions takes nothing returns nothing
local integer i = 0
local item iteminslot
loop
set iteminslot = UnitItemInSlot(GetManipulatingUnit(), i)
if ( GetItemTypeId(iteminslot) == GetItemTypeId(GetManipulatedItem()) and iteminslot != GetManipulatedItem()) then
call SetItemCharges( iteminslot, ( GetItemCharges(iteminslot) + GetItemCharges(GetManipulatedItem()) ) )
call RemoveItem( GetManipulatedItem() )
set i = 5
// To end the loop i is increased
endif
set i = i + 1
exitwhen i > 5
endloop
set i = 0
set iteminslot = null
endfunction

// ==================
function InitTrig_Item_Stack takes nothing returns nothing
set gg_trg_Item_Stack = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Item_Stack, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddCondition( gg_trg_Item_Stack, Condition( function Trig_Item_Stack_Conditions ) )
call TriggerAddAction( gg_trg_Item_Stack, function Trig_Item_Stack_Actions )
endfunction
Spoiler:
Item Move
function Trig_Item_Move_Conditions takes nothing returns boolean
return GetIssuedOrderId() > 852001 and GetIssuedOrderId() < 852008
endfunction


function Trig_Item_Move_Actions takes nothing returns nothing
local integer i = GetItemCharges(GetOrderTargetItem())
if GetOrderTargetItem() == UnitItemInSlot(GetOrderedUnit(), GetIssuedOrderId()-852002) then
// Clicked on the same field again



if i > 1 then
set i = i/2
call SetItemCharges(GetOrderTargetItem(), GetItemCharges(GetOrderTargetItem()) - i)
call DisableTrigger(gg_trg_Item_Stack)
call UnitAddItemByIdSwapped(GetItemTypeId(GetOrderTargetItem()), GetTriggerUnit())
call EnableTrigger(gg_trg_Item_Stack)
call SetItemCharges(bj_lastCreatedItem, i)
endif
else
// Clicked on another field



if i > 0 and GetItemTypeId(GetOrderTargetItem()) == GetItemTypeId(UnitItemInSlot(GetOrderedUnit(), GetIssuedOrderId()-852002)) then
call SetItemCharges(GetOrderTargetItem(), GetItemCharges(GetOrderTargetItem()) + GetItemCharges(UnitItemInSlot(GetOrderedUnit(), GetIssuedOrderId()-852002)))
call RemoveItem(UnitItemInSlot(GetOrderedUnit(), GetIssuedOrderId()-852002))
endif
endif
set i = 0
endfunction

//==============



function InitTrig_Item_Move takes nothing returns nothing
set gg_trg_Item_Move = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Item_Move, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
call TriggerAddCondition( gg_trg_Item_Move, Condition( function Trig_Item_Move_Conditions ) )
call TriggerAddAction( gg_trg_Item_Move, function Trig_Item_Move_Actions )
endfunction
Once here was something.
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: Potion Stacking

Post by Aero »

Optimized the code a bit for you and added 'max-stack' functionality.
Also added multi-distribution.

For example: Item a has 37 charges, Item b has 40 charges, MAX_STACK is 50. I pick up item c that has 23 charges. It will distribute to a and b--the resultant will be item c is gone, a and b have 50 charges. If you were to pick up item c with 26 charges, a and b would have 50 charges and c would have 3. Enjoy.
Spoiler:

Code: Select all

function Trig_Item_Stack_Conditions takes nothing returns boolean
return GetItemCharges(GetManipulatedItem())>0
endfunction

function Trig_Item_Stack_Actions takes nothing returns nothing
local integer MAX_STACK=50
local integer i=0
local integer a=0
local unit u=GetTriggerUnit()
local item manip=GetManipulatedItem()
local integer iid=GetItemTypeId(manip)
local integer charges=GetItemCharges(manip)
local item curr
loop
exitwhen i>5
set curr=UnitItemInSlot(u,i)
set a=GetItemCharges(curr)
if(GetItemTypeId(curr)==iid)and(curr!=manip)and(a<MAX_STACK)then
if charges<=MAX_STACK-a then
call SetItemCharges(curr,a+charges)
call RemoveItem(manip)
exitwhen true
else
call SetItemCharges(curr,MAX_STACK)
set charges=charges-MAX_STACK+a
call SetItemCharges(manip,charges)
endif
endif
set i=i+1
endloop
set curr=null
set manip=null
set u=null
endfunction

// ==================
function InitTrig_Item_Stack takes nothing returns nothing
set gg_trg_Item_Stack = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Item_Stack, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddCondition( gg_trg_Item_Stack, Condition( function Trig_Item_Stack_Conditions ) )
call TriggerAddAction( gg_trg_Item_Stack, function Trig_Item_Stack_Actions )
endfunction
As a note: When looking to optimize, look at what you call more than necessary. If you see 5 "GetManipulatedItem()" calls, store GetManipulatedItem into a variable and just use the variable. Also, to exit a loop without the condition being true (i>5), use "exitwhen true".
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: Potion Stacking

Post by Aero »

God, nothing worse than people who ask for help and not even comment when they get it, let alone give thanks.
Makes me wonder why I bother :roll:
User avatar
Ozzapoo
The Flying Cow!
Posts: 2196
Joined: November 2nd, 2007, 10:34 pm
Location: Melbourne

Re: Potion Stacking

Post by Ozzapoo »

I was at school -.- No need to get so down....
And dont double-post :P :P :P :P
Visit Ozzapoo.net, my blog and the home of AutoCP and Cheatpack Detector!
AutoCP3 now available for free!
yeuyo
Newcomer
Posts: 9
Joined: February 3rd, 2008, 7:28 am
Title: Slacker
Location: Malaysia

Re: Potion Stacking

Post by yeuyo »

Er...actually I'm still figuring what all those means. :(