• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] Item Stacking

Status
Not open for further replies.
Level 17
Joined
Jun 12, 2007
Messages
1,261
Oke, I'm going strait to the point.

Either:
I need somebody to either make me a trigger that will stack healing potions, mana potions, lesser healing potions etc.
Well, I ain't stupid so just make one only for let's say healing potions and I can CnP and edit values.
Be sure to make it for multiple players at the same time, so that the trigger works for player 1, 2, 3 etc. (So make it MPI, not MUI!)

Or:
Translate this tutorial for me and do the following:
- Instead of using the event: "player red gains a item", make the trigger work for any player.
- The guy forgot to add the trigger in it's total. He only separated it, it's because of that, that I don't get the tutorial... xD

Why? Because I give u rep if u do so, and because I'm to lazy to translate his mess. =)

Tutorial: Click me!
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
I made a map which contains a trigger that stacks everything that can be stacked.
Works for all units with inventory.
Remember to copy the stuff in the header.
 

Attachments

  • Stacking.w3x
    17 KB · Views: 82
Level 22
Joined
Dec 31, 2006
Messages
2,216
That was weird... I tested it myself and it worked perfectly.


attachment.php


attachment.php


attachment.php


attachment.php

 

Attachments

  • One.png
    One.png
    1.5 MB · Views: 439
  • Two.png
    Two.png
    1.5 MB · Views: 410
  • Three.png
    Three.png
    1.4 MB · Views: 377
  • Four.png
    Four.png
    1.5 MB · Views: 393
Level 9
Joined
Apr 3, 2008
Messages
700
Mistake is here. You need local integer for the number of charges in the item. Because when you remove item all data about it deletes, including charges.

JASS:
        call RemoveItem(it)
        set it = GetItemOfType(u, id)
        call SetItemCharges(it, GetItemCharges(it) + 1)

And you need a condition that will check item type of item being manipulated.
 
Level 13
Joined
Sep 14, 2008
Messages
1,408
This SHOULD work...


  • Stack Items
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Item-type of (Item being manipulated)) Equal to YourItem
    • 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 being manipulated)
            • Then - Actions
              • Set SlotNumber = (Integer A)
            • Else - Actions
      • For each (Integer B) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • (Integer B) Not equal to SlotNumber
                  • (Item-type of (Item carried by (Triggering unit) in slot SlotNumber)) Equal to (Item-type of (Item carried by (Triggering unit) in slot (Integer B)))
            • Then - Actions
              • Item - Set charges remaining in (Item carried by (Triggering unit) in slot (Integer B)) to ((Charges remaining in (Item carried by (Triggering unit) in slot (Integer B))) + (Charges remaining in (Item being manipulated)))
              • Item - Remove (Item being manipulated)
            • Else - Actions
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
Mistake is here. You need local integer for the number of charges in the item. Because when you remove item all data about it deletes, including charges.

JASS:
        call RemoveItem(it)
        set it = GetItemOfType(u, id)
        call SetItemCharges(it, GetItemCharges(it) + 1)

And you need a condition that will check item type of item being manipulated.

Why did the script work perfectly for me then?

EDIT: Nothing is wrong in the script. I don't need to store the number of charges in an integer, because of this: set it = GetItemOfType(u, id) which is a little function I made to find the same kind of item as the one I removed.

EDIT2: Here's an image of my script in action:

attachment.php


EDIT3: I've made a little improvement to the script. It now adds the charges of the item you picked up, instead of just adding 1.
Stacking.w3x
 

Attachments

  • Stacking.png
    Stacking.png
    2.4 MB · Views: 358
  • Stacking.w3x
    17.1 KB · Views: 91
Last edited:
Level 17
Joined
Jun 12, 2007
Messages
1,261
Though, u only use the regular editor right? No fancy tools for me.
Oh btw DarkAngel, that's what I made before (tried) but I it was an epic fail... xD
If this system of The Reborn Evil don't work I'm going to try that again.

Question:
What if a player drops a stack of 22 health potions... And a other player picks it up, will it gain 1 or 22 health potions? xD
Stacking is a real pain in the ass when you're called airandius...
 
Level 17
Joined
Jun 12, 2007
Messages
1,261
Indeed, I would understand it if he just entered the 'complicated' trigger in one big go before he decided to cut it in smaller parts...
I have a hard time to understand simplified things (I fail).

Item's still disappear for me.. =S

-------------

Dark Angel, could u create that spell for me in a map.
Make sure:
- It also stacks different numbers, for example when a player picks up a item with 32 charges he gets 32 charges.
- Could u edit it so it works for both runic and non-runic (not needed though.)

It's really odd that I can create harder triggers.. but I can't seem to do this..
 
Level 13
Joined
Sep 14, 2008
Messages
1,408
  • Item - Set charges remaining in (Item carried by (Triggering unit) in slot (Integer B)) to ((Charges remaining in (Item carried by (Triggering unit) in slot (Integer B))) + (Charges remaining in (Item being manipulated)))
It already adds the charges...

for the runic thing -.- It might be because I am german and normaly use the german we but I have no idea what runic is^^

I can put it in a map for you but at the moment I am using my laptop which has no wc3 on it... tomorrow I think...

Or maybe any other guy can put the trigger posted into a map for you.. I am sure you give him rep^^ But I will do it tomorrow
 
Level 5
Joined
Jan 6, 2006
Messages
106
JASS:
function Trig_Charged_Item_Stacks_Actions takes nothing returns nothing
    local unit u = GetManipulatingUnit()
    local item i = GetManipulatedItem()
    local integer a = 1
    local integer b = 6
    loop
        exitwhen a > b
        if ( GetItemTypeId(UnitItemInSlotBJ(u, a)) == GetItemTypeId(i) ) then
            if ( UnitItemInSlotBJ(u, a) != i ) then
                call SetItemCharges( UnitItemInSlotBJ(u, a), (GetItemCharges(UnitItemInSlotBJ(u, a)) + GetItemCharges(i) ) )
                call RemoveItem( i )
                set u = null
                set i = null
                set a = 0
                set b = 0
                return
            endif
        endif
        set a = a + 1
    endloop
    set u = null
    set i = null
    set a = 0
    set b = 0
endfunction

Here you go. No editor modifications needed.

EDIT: Use "A unit picks up an item" as an event.
 
Level 17
Joined
Jun 12, 2007
Messages
1,261
JASS:
function Trig_Charged_Item_Stacks_Actions takes nothing returns nothing
    local unit u = GetManipulatingUnit()
    local item i = GetManipulatedItem()
    local integer a = 1
    local integer b = 6
    loop
        exitwhen a > b
        if ( GetItemTypeId(UnitItemInSlotBJ(u, a)) == GetItemTypeId(i) ) then
            if ( UnitItemInSlotBJ(u, a) != i ) then
                call SetItemCharges( UnitItemInSlotBJ(u, a), (GetItemCharges(UnitItemInSlotBJ(u, a)) + GetItemCharges(i) ) )
                call RemoveItem( i )
                set u = null
                set i = null
                set a = 0
                set b = 0
                return
            endif
        endif
        set a = a + 1
    endloop
    set u = null
    set i = null
    set a = 0
    set b = 0
endfunction

Here you go. No editor modifications needed.

EDIT: Use "A unit picks up an item" as an event.

So how do I change the event for that? And where should I add this, just in a empty trigger converted to jass?
I hate working with jass, it's so freaking complicated.. xD

(It would be best just to give a sample map, the winner gains reputation. xD)
 
Level 3
Joined
May 6, 2007
Messages
32
I have this system u might be interested in.
Earlier u mentioned for pots n sorts.. this system-
works only for purchasable- but is changable
But i recommend stacking for consumable items only.
This is really a no brainer- so u should understand it.

Umm enjoy...

EDIT-Oops forgot to check dates, but it might still be useful.
 

Attachments

  • Item Stack.w3x
    8.3 KB · Views: 50
Status
Not open for further replies.
Top