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

Replacing Item Same Slot

Status
Not open for further replies.
Level 33
Joined
Mar 27, 2008
Messages
8,035
How to actually replace (basically, I remove the item and create a new one) an item in the exact same slot after it was created ?

Situation:
I used an ability (via Item) and when it detects, it changes that item (Item A) to new item (Item B) and I want Item B to be moved in the exact location as Item A position in the inventory.

Basically I found this function:
  • Unit - Order (Triggering unit) to move (Last created item) to inventory slot 1
But what Integer should I put there ?
Is there any function that GetLastRemovedItemSlot or something ?

EDIT:
This system is meant for more than 1 items on a single unit.
Meaning that a unit can possess Item A more than 1.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
That's just basically... what the GUI function above did.

I need to know what Integer should I put in order for me to replace the item with the same exact inventory slot as Item A.

Example:
You have Item A at slot 4, and when this item is activated, I will remove Item A and create Item B and will move Item B to the same slot as Item A (which in this case, is slot 4).

How do I know which slot is the last removed/etc item ?
 
Level 8
Joined
Sep 7, 2008
Messages
320
That's just basically... what the GUI function above did.

I need to know what Integer should I put in order for me to replace the item with the same exact inventory slot as Item A.

Example:
You have Item A at slot 4, and when this item is activated, I will remove Item A and create Item B and will move Item B to the same slot as Item A (which in this case, is slot 4).

How do I know which slot is the last removed/etc item ?

GUI doesnt got that function :vw_sad:
In gui, you need 2 actions to do that, 1. Create item. 2. Order unit move to A slot

  • (Item-type of (Item carried by Unit in slot 1)) Equal to Tome of Experience // Run loop
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
I made the edit.

NOTE: This system allows you to have more than 1 same item.

I already know how to tackle the problem if the item is unique, meaning that you can only have 1 item of that type per unit.

But since it allows more than 1 same item per unit, you can't really use that.

Because if I have 2 Item A (slot 1 | slot 4)
The condition will evaluate slot 1 first before going to slot 4 (therefore the item replaced occurs at slot 1, while I activated it at slot 4)

Therefore, you can't really use that method/approach.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
That condition seems to solve the problem, yipeee :)
How can I miss that small condition...

Anyway, the function in post #2 really not in GUI, because I overlooked it, that function is 2 in 1, right ?
Create and Move, whereas if in GUI, that's a pain ass, 2 lines of actions.

Okay, here's the trigger code if you want to see it:
  • CR Event
    • Events
      • Unit - A unit Uses an item
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to RingOfHealth
        • Then - Actions
          • For each (Integer LoopingInteger) from 1 to 6, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item being manipulated) Equal to (Item carried by (Triggering unit) in slot LoopingInteger)
                • Then - Actions
                  • Item - Remove (Item being manipulated)
                  • Custom script: call UnitAddItemToSlotById(GetTriggerUnit(), 'I000', udg_LoopingInteger)
                  • Skip remaining actions
                • Else - Actions
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item being manipulated)) Equal to RingOfMana
            • Then - Actions
              • For each (Integer LoopingInteger) from 1 to 6, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Item being manipulated) Equal to (Item carried by (Triggering unit) in slot LoopingInteger)
                    • Then - Actions
                      • Item - Remove (Item being manipulated)
                      • Custom script: call UnitAddItemToSlotById(GetTriggerUnit(), 'I001', udg_LoopingInteger)
                      • Skip remaining actions
                    • Else - Actions
            • Else - Actions
 
Level 8
Joined
Sep 7, 2008
Messages
320
That condition seems to solve the problem, yipeee :)
How can I miss that small condition...

Anyway, the function in post #2 really not in GUI, because I overlooked it, that function is 2 in 1, right ?
Create and Move, whereas if in GUI, that's a pain ass, 2 lines of actions.

Okay, here's the trigger code if you want to see it :

or you can use

  • CR Event - EGUI
    • Events
      • Unit - A unit Uses an item
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to RingOfHealth
        • Then - Actions
          • For each (Integer LoopingInteger) from 1 to 6, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item being manipulated) Equal to (Item carried by (Triggering unit) in slot LoopingInteger)
                • Then - Actions
                  • Item - Remove (Item being manipulated)
                  • Hero - Give (Triggering unit) a Tome of Experience in slot LoopingInteger
                  • Skip remaining actions
                • Else - Actions
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item being manipulated)) Equal to RingOfMana
            • Then - Actions
              • For each (Integer LoopingInteger) from 1 to 6, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Item being manipulated) Equal to (Item carried by (Triggering unit) in slot LoopingInteger)
                    • Then - Actions
                      • Item - Remove (Item being manipulated)
                      • Hero - Give (Triggering unit) a Tome of Experience in slot LoopingInteger
                      • Skip remaining actions
                    • Else - Actions
            • Else - Actions
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
(Triggering unit) never leak before, where do you find this information saying that native is leak ?
If you are using local variable of unit, well, yes it will leak because we have to null it, but this is native function, it won't leak.
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
I got fool by people in native forum :ogre_icwydt: :ogre_icwydt:

And where is this "native forum"?

@defskull

I'll try to search with you for usefull natives. Can't gaurantee you that I'll find it though :/

EDIT: when you remove an item from the unit can't you save the slot the item was in?
Hashtables perhaps?

EDIT2: Might this native be of any use?:
JASS:
native UnitItemInSlot takes unit whichUnit, integer itemSlot returns item

EDIT3: How did you remove the item? with UnitRemoveItem? What about using UnitRemoveItemFromSlot?

EDIT4: lol I overlooked this thread big time, I see you've already solved it. I should really learn to read before posting...
 
Last edited:
Status
Not open for further replies.
Top