Item stocks and stacking

Jolly chap*

New Member
Reaction score
34
Happy New Year everyone!

I'd like to request some help. I want this shop to sell say, a potion. The maximum stock of potions for that shop is 3. So ...

Shop has 3 potions.
Hero buys one potion. 1 potion appears in inventory.
Hero buys another potion. On that same slot from the first potion, I want 2 potions. So, like, there's that small number 2 in the corner of the potion icon.

What field in the Object Editor should I change to get that? I might have missed it. I've tried messing with it but it got completely screwed up. One time the potions disappeared from the inventory. :p

Thanks in advance! :D
 

FireBladesX

Eating my wings!
Reaction score
123
A way to do it is to sell a "tome version" of the item, with the "use when acquired" field checked off. Remove the item when purchased, and then check if the triggering unit has a copy of the potion you want.
If it does, then add 1 to the charges. If it doesn't, then give the triggering unit the item.

(This uses two different items, by the way.)
 

Genyuumaru

New Member
Reaction score
15
No. Absolutely no way to do this without triggers (it is possible to do it without tomes though, but you'll basicaly have to use something else ^^).
 

Jolly chap*

New Member
Reaction score
34
I'm going to ask another question here. Since the Item - Add charges only works for items such as Last Created Item, I want to find a way to add charges to items of a certain type. Here's the trigger I have so far, but I have no idea how to add charges to the potion of that type.

Trigger:
  • Potion Tome
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Item - Remove (Item being manipulated)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to Potion <-- this is the tome version
          • ((Hero manipulating item) has an item of type Potion) Equal to False <-- this is the real version
        • Then - Actions
          • Hero - Create Potion and give it to (Hero manipulating item)
        • Else - Actions
 

vypur85

Hibernate
Reaction score
803
Code:
Item Stack
    Events
        Unit - A unit Acquires an item
    Conditions
        (Charges remaining in (Item being manipulated)) Greater than 0
        ((Triggering unit) has an item of type (Item-type of (Item being manipulated))) Equal to True
        (Item being manipulated) Not equal to (Item carried by (Triggering unit) of type (Item-type of (Item being manipulated)))
    Actions
        For each (Integer A) from 1 to 6, do (Actions)
            Loop - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        (Item carried by (Triggering unit) in slot (Integer A)) Equal to (Item carried by (Triggering unit) of type (Item-type of (Item being manipulated)))
                    Then - Actions
                        Item - Set charges remaining in (Item carried by (Triggering unit) in slot (Integer A)) to ((Charges remaining in (Item carried by (Triggering unit) in slot (Integer A))) + 1)
                        [del]Item - Remove (Item being manipulated)[/del]
                    Else - Actions
        Item - Remove (Item being manipulated)

Something like the above. If I'm not mistaken, Sfilip made a tutorial or something. I can't really remember who and where. But the above trigger is something similar.
 

Akolyt0r

New Member
Reaction score
33
yes SFilip made a GUI Item Stacking System ..somewhere here on this page...
if you can use vJass you could use following script of me (based on SFilips Gui-version):
JASS:
scope ItemMerge initializer Init

private function Conditions takes nothing returns boolean
    return (GetItemCharges(GetManipulatedItem()) != 0)
endfunction

private function Actions takes nothing returns nothing
local item it=GetManipulatedItem() //item picked up
local item iis
local unit u=GetManipulatingUnit()
local integer i=0
loop
    exitwhen i > 5 //loop trough inventory
    set iis=UnitItemInSlot(u, i) //item in slot i
    //ItemLevel of an Item determines the max ammount of items, which can be in one stack
    if ( ( GetItemTypeId(iis) == GetItemTypeId(it) )and ( GetItemCharges(iis) < GetItemLevel(iis) )and( iis != it ) ) then
        if ( GetItemCharges(iis) + GetItemCharges(it) ) > GetItemLevel(it) then
            call SetItemCharges( it, ( ( GetItemCharges(iis) + GetItemCharges(it) ) - GetItemLevel(it) ) )
            call SetItemCharges( iis, GetItemLevel(it) )
        else
            call SetItemCharges( iis, ( GetItemCharges(iis) + GetItemCharges(it) ) )
            call RemoveItem( it)
        endif
    else
    endif
    set i = i + 1
endloop
set iis=null
set it=null
set u=null
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddCondition(t, Condition( function Conditions ) )
    call TriggerAddAction(t, function Actions )
    set t=null
endfunction
endscope

however both versions dont work with full inventory yet, but i will work on that some day perhaps :)
 

Jolly chap*

New Member
Reaction score
34
I have used it, but it doesn't work with full inventory. I used tomes and now I have another problem.

Trigger:
  • Potion Tome
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-class of (Item being manipulated)) Equal to Powerup
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • And - All (Conditions) are true
            • Conditions
              • (Item-type of (Item being manipulated)) Equal to Healing Serum (Tome)
              • ((Triggering unit) has an item of type Healing Serum) Equal to False
        • Then - Actions
          • Hero - Create Healing Serum and give it to (Hero manipulating item)
        • Else - Actions
          • Item - Set charges remaining in (Item carried by (Triggering unit) of type Healing Serum) to ((Charges remaining in (Item carried by (Triggering unit) of type Healing Serum)) + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • And - All (Conditions) are true
            • Conditions
              • (Item-type of (Item being manipulated)) Equal to Wonder Sap (Tome)
              • ((Triggering unit) has an item of type Wonder Sap) Equal to False
        • Then - Actions
          • Hero - Create Wonder Sap and give it to (Hero manipulating item)
        • Else - Actions
          • Item - Set charges remaining in (Item carried by (Triggering unit) of type Wonder Sap) to ((Charges remaining in (Item carried by (Triggering unit) of type Wonder Sap)) + 1)


The problem is, if I buy Healing Serum, I somehow get a Wonder Sap. And if I already had a Wonder Sap item, it gives it another charge instead. I don't know what's wrong. :(
 

Anteo

Active Member
Reaction score
3
Trigger:
  • Potion Tome
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • And - All (Conditions) are true
            • Conditions
              • (Item-type of (Item being manipulated)) Equal to Healing Serum (Tome)
              • ((Triggering unit) has an item of type Healing Serum) Equal to False
        • Then - Actions
          • Hero - Create Healing Serum and give it to (Hero manipulating item)
        • Else - Actions
          • Item - Set charges remaining in (Item carried by (Triggering unit) of type Healing Serum) to ((Charges remaining in (Item carried by (Triggering unit) of type Healing Serum)) + 1)

IF the Item being manipulated is Healig Serum, and the unit doesn't have that item, it will work;
ELSE... I'm sure you know that ELSE actions will run only if conditions in IF are false, that means
In any other case (if item being manipulated is not Healing Serum or unit has an item of type Healing Serum) it will do ELSE actions

Trigger:
  • Potion Tome
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-class of (Item being manipulated)) Equal to Powerup
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • And - All (Conditions) are true
            • Conditions
              • (Item-type of (Item being manipulated)) Equal to Healing Serum (Tome)
        • Then - Actions
          • If - Conditions
            • ((Triggering unit) has an item of type Healing Serum) Equal to True
          • Then - Actions
            • Item - Set charges remaining in (Item carried by (Triggering unit) of type Healing Serum) to ((Charges remaining in(Item carried by (Triggering unit) of type Healing Serum)) + 1)
          • Else - Actions
            • Hero - Create Healing Serum and give it to (Hero manipulating item)
        • Else - Actions
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top