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

How to detect a lose of an item while having another one

Status
Not open for further replies.
Level 7
Joined
Aug 8, 2008
Messages
340
Hello Hive,
I was wondering how one would go about making a trigger, which detects when a unit loses an item, while still having another one of said item in their inventory?

I've tried this and it dosen't seem to work as intentet:
Event: An unit loses an item

Condition: Item being manipulated equal to CustomItem
Unit manipulating item has an item of type CustomItem equal to false

Action: Remove CustomAbility from unit manipulating item

The ability is still being removed, even though the unit still has an item of the CustomItem type in their inventory.
 
Level 9
Joined
Mar 26, 2017
Messages
376
You can loop through all inventory slots of the unit, and check if only one copy of that item id exists in any of the slots.

At the time of execution for a DROP_ITEM trigger, the item is still in the unit's inventory.

This is an example of a code I use in my map for such purpose:

Lua:
local i = 0
for x=0,5 do
    if GetItemTypeId(UnitItemInSlot(u, x)) == 1227895373 then i = i+1 end
end
if i == 1 then other actions
 
Last edited:

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
That does not make much sense to me.

IF the execution is instant the item is indeed removed from the inventory correctly at the time of trigger execution, then the fault has to be the condition itself. And I tend to believe the conditions are all working properly.

edit: wait wait wait
Unit manipulating item has an item of type CustomItem equal to false

Shouldn't it be equal to true??

It's so obvious I kinda assumed it was checking for true
 
Level 9
Joined
Mar 26, 2017
Messages
376
That does not make much sense to me.

IF the execution is instant the item is indeed removed from the inventory correctly at the time of trigger execution, then the fault has to be the condition itself. And I tend to believe the conditions are all working properly.

edit: wait wait wait
Unit manipulating item has an item of type CustomItem equal to false

Shouldn't it be equal to true??

It's so obvious I kinda assumed it was checking for true

Just tested this and I am wrong. The item is still in the unit's inventory at time of execution.
I assumed this behaviour because ITEM_PICKUP works like that: item is added to the inventory at the time of trigger execution. For ITEM_DROP, apparently the item leaves the inventory only after trigger execution.

Sorry for the confusion :p

@Chaosy your solution will work.
Though 0 second wait still adds a slight delay. If this is unwanted, you could check if the number of items carried of a certain type is equal to 1.
 
Last edited:
Level 19
Joined
Feb 27, 2019
Messages
590
I dont think a 0.00 second wait is an issue in this context.

One could do this though but it requires another check so is it even preferable?

  • Untitled Trigger 002
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Unstable Energy
    • 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-type of (Item carried by (Triggering unit) in slot (Integer A))) Equal to Unstable Energy
              • (Item carried by (Triggering unit) in slot (Integer A)) Not equal to (Item being manipulated)
            • Then - Actions
              • Game - Display to (All players) the text: Item owned
              • Skip remaining actions
            • Else - Actions
      • Game - Display to (All players) the text: Item not owned
EDIT:
Unit manipulating item has an item of type CustomItem equal to false

Shouldn't it be equal to true??
If its set to true then the ability will be removed if the hero is carrying 2 of those items which is wrong.
 
Last edited:
Level 7
Joined
Aug 8, 2008
Messages
340
Thanks for your replys everyone.
Chaosys suggestion to add a 0 wait timer and than do a check for the CustomItem worked! - I am a bit worried, that the wait time might provide the owner of the unit losing the item, with a window of oppertunity to use the ability after it is lost? So I am open to try futher suggestions.

How would I go about doing a second check using your suggestion [db]est?
 
Last edited:
Level 19
Joined
Feb 27, 2019
Messages
590
Thanks for your replys everyone.
Chaosys suggestion to add a 0 wait timer and than do a check for the CustomItem worked! - I am a bit worried, that the wait time might provide the owner of the unit losing the item, with a window of oppertunity to use the ability after it is lost? So I am open to try futher suggestions.

How would I go about doing a second check using your suggestion [db]est?
I am confusing you. Theres nothing more to the trigger. I added Display game message to show where the game interprets the unit as having the item and not having the item. So at Item not owned thats where the ability is removed.

Here you leave it blank.
  • Game - Display to (All players) the text: Item owned
Here you Remove Ability.
  • Game - Display to (All players) the text: Item not owned
But I would say a 0.00 second wait works as intended. Theres no way the player manages to use the ability during a 0.00 second wait.
 
Status
Not open for further replies.
Top