• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Item Stacking Glich

Status
Not open for further replies.
Level 17
Joined
Jun 17, 2010
Messages
2,275
I made a item stacking system for 1 item. The problem is, Once somone buys the potion, no one else can or it removes it from their inventory, the one who originally bought it has to keep atleast 1 charge or they can never get the item again, And if the person who has 1 charge buys another one it makes it 4 charges. But its only supposed to be 3.

  • Potion of Regen
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Potion of Regeneration
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Triggering unit)) Equal to Hero of Blade
          • Potion_Of_Regen[2] Equal to 1
        • Then - Actions
          • Item - Remove (Item carried by (Triggering unit) of type Potion of Regeneration)
          • Item - Set charges remaining in (Item carried by (Triggering unit) of type Potion of Regeneration) to ((Charges remaining in (Item carried by (Triggering unit) in slot 1)) + 2)
        • Else - Actions
          • Set Potion_Of_Regen[2] = 1
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Triggering unit)) Equal to Hero of Shield
          • Potion_Of_Regen[1] Equal to 1
        • Then - Actions
          • Item - Remove (Item carried by (Triggering unit) of type Potion of Regeneration)
          • Item - Set charges remaining in (Item carried by (Triggering unit) of type Potion of Regeneration) to ((Charges remaining in (Item carried by (Triggering unit) in slot 1)) + 2)
        • Else - Actions
          • Set Potion_Of_Regen[1] = 1
 
I made a item stacking system for 1 item. The problem is, Once somone buys the potion, no one else can or it removes it from their inventory, the one who originally bought it has to keep atleast 1 charge or they can never get the item again, And if the person who has 1 charge buys another one it makes it 4 charges. But its only supposed to be 3.

  • Potion of Regen
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Potion of Regeneration
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Triggering unit)) Equal to Hero of Blade
          • Potion_Of_Regen[2] Equal to 1
        • Then - Actions
          • Item - Remove (Item carried by (Triggering unit) of type Potion of Regeneration)
          • Item - Set charges remaining in (Item carried by (Triggering unit) of type Potion of Regeneration) to ((Charges remaining in (Item carried by (Triggering unit) in slot 1)) + 2)
        • Else - Actions
          • Set Potion_Of_Regen[2] = 1
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Triggering unit)) Equal to Hero of Shield
          • Potion_Of_Regen[1] Equal to 1
        • Then - Actions
          • Item - Remove (Item carried by (Triggering unit) of type Potion of Regeneration)
          • Item - Set charges remaining in (Item carried by (Triggering unit) of type Potion of Regeneration) to ((Charges remaining in (Item carried by (Triggering unit) in slot 1)) + 2)
        • Else - Actions
          • Set Potion_Of_Regen[1] = 1


Its because you're only using 1 variable for all heroes of that type...

ex. All hero of Blade will use Potion_Of_Regen[2] so if there are two HOB then if one picks a potionofRegen then the other one will not really be alble to pick because the Potion_Of_Regen[2] is already set to 1...
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
  • Item - Remove (Item carried by (Triggering unit) of type Potion of Regeneration)
  • Item - Set charges remaining in (Item carried by (Triggering unit) of type Potion of Regeneration) to ((Charges remaining in (Item carried by (Triggering unit) in slot 1)) + 2)
You remove the item from the unit's inventory and then you add to it's charges. Not to mention you completely abuse Item carried by unit of type - in reality that function is:

JASS:
function GetItemOfTypeFromUnitBJ takes unit whichUnit, integer itemId returns item
    local integer index = GetInventoryIndexOfItemTypeBJ(whichUnit, itemId)

    if (index == 0) then
        return null
    else
        return UnitItemInSlot(whichUnit, index - 1)
    endif
endfunction

Which in turn uses:

JASS:
function GetInventoryIndexOfItemTypeBJ takes unit whichUnit, integer itemId returns integer
    local integer index
    local item    indexItem

    set index = 0
    loop
        set indexItem = UnitItemInSlot(whichUnit, index)
        if (indexItem != null) and (GetItemTypeId(indexItem) == itemId) then
            return index + 1
        endif

        set index = index + 1
        exitwhen index >= bj_MAX_INVENTORY
    endloop
    return 0
endfunction

You're better off just using a trigger like this:

  • Untitled Trigger 001
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Potion of Greater Healing
    • Actions
      • For each (Integer A) from 1 to (Size of inventory for (Triggering unit)), do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item carried by (Triggering unit) in slot (Integer A))) Equal to (Item-type of (Item being manipulated))
              • (Item being manipulated) Not equal to (Item carried by (Triggering unit) in slot (Integer A))
            • 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))) + (Charges remaining in (Item being manipulated)))
              • Item - Remove (Item being manipulated)
            • Else - Actions
This way you can be sure that you're not removing the item that is being added to the inventory via acquiring it (which you don't check for), and you improve the performance greatly as you're not running a loop each time you try to reference the item you're looking for, instead you do it all in one loop.

The above trigger will only use this function:

JASS:
function UnitItemInSlotBJ takes unit whichUnit, integer itemSlot returns item
    return UnitItemInSlot(whichUnit, itemSlot-1)
endfunction

Which is much faster, though if you were to use JASS you could just use UnitItemInSlot directly to make things even more efficient - but that is the cripple that GUI users put themselves through.
 
Status
Not open for further replies.
Top