• 🏆 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 Stack

Status
Not open for further replies.
Level 39
Joined
Feb 27, 2007
Messages
5,010
  • Untitled Trigger 001
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • ((Triggering unit) has an item of type (Item-type of (Item being manipulated))) Equal to True
      • And - All (Conditions) are true
        • Conditions
          • (Item-type of (Item being manipulated)) Not equal to Potion of Greater Healing
          • (Item-type of (Item being manipulated)) Not equal to Potion of Greater Mana
          • -------- etc. --------
    • Actions
      • Set TempPoint = (Position of (Triggering unit))
      • Unit - Order (Triggering unit) to drop (Item being manipulated) at TempPoint
      • Custom script: call RemoveLocation(udg_TempPoint) //udg_ plus whatever the name of your point variable is in the editor, this cleans leaks
 
Last edited:
  • Untitled Trigger 001
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • ((Triggering unit) has an item of type (Item-type of (Item being manipulated))) Equal to True
      • And - All (Conditions) are true
        • Conditions
          • (Item-type of (Item being manipulated)) Not equal to Potion of Greater Healing
          • (Item-type of (Item being manipulated)) Not equal to Potion of Greater Mana
          • -------- etc. --------
    • Actions
      • Set TempPoint = (Position of (Triggering unit))
      • Unit - Order (Triggering unit) to drop (Item being manipulated) at TempPoint
      • Custom script: call RemoveLocation(udg_TempPoint) //udg_ plus whatever the name of your point variable is in the editor, this cleans leaks

Oh!! Thanks men .. okay ill try it. :infl_thumbs_up: +rep
 
I try your trigger, its okay but something wrong .. i want that for example when a hero pick boots of speed and orb of froze. The hero can afford only one boots of speed while orb of froze he can afford two orb of froze. BTW, thanks ..:oops::oops: need help please !!

9wHv6mOTPdWnu6zsLoudd3g83_JqPxBiMVMh8aeq3wFpoqC_2jNOtDz0376FvhfWj7IxRqNr=w1366-h768-no
 

Attachments

  • Item Test.w3x
    18 KB · Views: 16
Last edited:

EdgeOfChaos

E

EdgeOfChaos

  • Untitled Trigger 001
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • ((Triggering unit) has an item of type (Item-type of (Item being manipulated))) Equal to True
      • And - All (Conditions) are true
        • Conditions
          • (Item-type of (Item being manipulated)) Not equal to Potion of Greater Healing
          • (Item-type of (Item being manipulated)) Not equal to Potion of Greater Mana
          • -------- etc. --------
    • Actions
      • Set TempPoint = (Position of (Triggering unit))
      • Unit - Order (Triggering unit) to drop (Item being manipulated) at TempPoint
      • Custom script: call RemoveLocation(udg_TempPoint) //udg_ plus whatever the name of your point variable is in the editor, this cleans leaks
Sorry but this is not correct.

  • ((Triggering unit) has an item of type (Item-type of (Item being manipulated))) Equal to True
-> This will always evaluate to true, since the event for Acquires an Item fires after pickup. So, the hero always has an item of the type of item he just got.
  • Set TempPoint = (Position of (Triggering unit))
  • Unit - Order (Triggering unit) to drop (Item being manipulated) at TempPoint
  • Custom script: call RemoveLocation(udg_TempPoint) //udg_ plus whatever the name of your point variable is in the editor, this cleans leaks
-> This is not a good place to use orders, instead use
  • Hero - Drop (Item being manipulated) from (Triggering unit)
--------------------
If you want the hero to only be able to use one of each item-type, the approach is basically:
- Loop through every inventory slot (For Integer A from 1 to 6)
- Compare item-type of item in slot to item-type of manipulated
- If it's the same, and the items themselves are not the same, drop the manipulated one

I can write it for you, but I'd probably do it in JASS. Really though, I'd encourage you to try to figure this out yourself. It's not a hard trigger and will help you understand loops.
 
Sorry but this is not correct.

  • ((Triggering unit) has an item of type (Item-type of (Item being manipulated))) Equal to True
-> This will always evaluate to true, since the event for Acquires an Item fires after pickup. So, the hero always has an item of the type of item he just got.
  • Set TempPoint = (Position of (Triggering unit))
  • Unit - Order (Triggering unit) to drop (Item being manipulated) at TempPoint
  • Custom script: call RemoveLocation(udg_TempPoint) //udg_ plus whatever the name of your point variable is in the editor, this cleans leaks
-> This is not a good place to use orders, instead use
  • Hero - Drop (Item being manipulated) from (Triggering unit)
--------------------
If you want the hero to only be able to use one of each item-type, the approach is basically:
- Loop through every inventory slot (For Integer A from 1 to 6)
- Compare item-type of item in slot to item-type of manipulated
- If it's the same, and the items themselves are not the same, drop the manipulated one

I can write it for you, but I'd probably do it in JASS. Really though, I'd encourage you to try to figure this out yourself. It's not a hard trigger and will help you understand loops.

EdgeOfChaos thanks for your help but how could i read the jass script i didn't know about jass. it is possible to convert it to GUI so that i can easily understand. Once again thank you for helping me +rep :oops:
 
Level 4
Joined
Dec 24, 2010
Messages
67
Nope, unfortunately there's no GUI of removing memory leaks.
You don't have to memorize it right now. Just copy and paste it for the time being. You'll eventually memorize it automatically in no time. That's what I did.
Just make a GUI Custom script, type in: call RemoveLocation(udg_TempPoint)

BTW, The TempPoint is an example name of Point variable. You just add "udg_" before the actual name if you're using it in jass.


So if the name of the Point is "aschenzkimutech", you type:
call RemoveLocation(udg_aschenzkimutech)

  • Set aschenzkimutech = (Position of (Triggering unit))
  • Custom script: call RemoveLocation(udg_aschenzkimutech)
 
Last edited:

Deleted member 219079

D

Deleted member 219079

This is in vJASS; make empty trigger then convert it into custom script via Edit menu in Trigger Editor, then paste this:
JASS:
library NoStacks
  
    // Prevent multiple occurences of same item
  
    // by jondrean
  
    // CREDITS: http://www.wc3c.net/showthread.php?t=84044
  
    private struct S extends array
  
        static unit shop
        static unit buyer
  
        static method onSell takes nothing returns boolean
            local item it = GetSoldItem()
            local item temp
            local integer id = GetItemTypeId(it)
            local unit u = GetBuyingUnit()
            local integer i = 5
            local player owner
            loop
                set temp = UnitItemInSlot(u, i)
                if temp!=null and GetItemTypeId(temp)==id then
                    call SetPlayerState(Player(15), PLAYER_STATE_RESOURCE_GOLD,   50000)
                    call SetPlayerState(Player(15), PLAYER_STATE_RESOURCE_LUMBER, 50000)
                    call AddItemToStock(shop, id, 1, 1)
                    call IssueNeutralImmediateOrderById(Player(15), shop, id)
                    call RemoveItem(UnitItemInSlot(buyer, 0))
                    call RemoveItemFromStock(shop, id)
                    set owner = GetOwningPlayer(u)
                    call SetPlayerState(owner, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(owner, PLAYER_STATE_RESOURCE_GOLD)+50000-GetPlayerState(Player(15), PLAYER_STATE_RESOURCE_GOLD))
                    call SetPlayerState(owner, PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState(owner, PLAYER_STATE_RESOURCE_LUMBER)+50000-GetPlayerState(Player(15), PLAYER_STATE_RESOURCE_LUMBER))
                    call RemoveItem(it)
                    set owner = null
                    exitwhen true
                endif
                exitwhen i == 0
                set i = i-1
            endloop
            set temp = null
            set it = null
            set u = null
            return false
        endmethod
      
        static method onPickup takes nothing returns boolean
            local item it = GetManipulatedItem()
            local item temp
            local integer id = GetItemTypeId(it)
            local unit u = GetTriggerUnit()
            local boolean hasOne = false
            local integer i = 5
            loop
                set temp = UnitItemInSlot(u, i)
                if temp!=null and GetItemTypeId(temp)==id then
                    if hasOne then
                        call SetItemPosition(it, GetUnitX(u), GetUnitY(u))
                        exitwhen true
                    else
                        set hasOne = true
                    endif
                endif
                exitwhen i == 0
                set i = i-1
            endloop
            set temp = null
            set it = null
            set u = null
            return false
        endmethod
  
        static method onInit takes nothing returns nothing
            local trigger t = CreateTrigger()
            local rect r = GetWorldBounds()

            set buyer = CreateUnit(Player(15), 'hpal', 0, 0, 0)
            call SetUnitX(buyer, GetRectMaxX(r))
            call SetUnitY(buyer, GetRectMaxY(r))

            set shop = CreateUnit(Player(15), 'nshe', 0, 0, 0)
            call SetUnitX(shop,GetRectMaxX(r))
            call SetUnitY(shop,GetRectMaxY(r))

            call UnitAddAbility(shop, 'Asid')
            call UnitRemoveAbility(shop, 'Awan')
            call UnitAddAbility(shop, 'Aloc')

            call RemoveRect(r)
          
            call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SELL_ITEM)
            call TriggerAddCondition(t, Condition(function thistype.onSell))
          
            set t = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM)
            call TriggerAddCondition(t, Condition(function thistype.onPickup))
          
            set t = null
            set r = null
        endmethod
  
    endstruct
  
endlibrary
You need JNGP: Jass New Gen Pack
 
Status
Not open for further replies.
Top