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

1 item of type in inventory only

Status
Not open for further replies.
Level 6
Joined
Sep 24, 2015
Messages
174
searching for that trigger:

if one hero has in inventory a specific item then he is not able to get more of this item type.

I tried several time to do this on World editor but i can't found the correct trigger...

e.g : hero has 1 boot in inventory then he cant wear more than 1 boot.
 
Level 28
Joined
Feb 18, 2014
Messages
3,579
I guess you can try using this :
  • Pick Item
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Boots of Quel'Thalas +6
    • Actions
      • Set ITEM = (Item being manipulated)
Then
  • Remove Item
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (ITEM is owned) Equal to TRUE
      • (Item-type of (Item being manipulated)) Equal to (Item-type of ITEM)
    • Actions
      • Objet - Remove (Item being manipulated)
You can either remove it or drop it when manipulated.
 
Level 13
Joined
May 10, 2009
Messages
868
You need a function that counts the amount of a item type a unit owns. I believe Blizzard didn't make such function. So, here's one:
JASS:
function GetNumberOfItemType takes unit whichUnit, integer itemId returns integer
    local integer inventorySlot = 0
    local integer itemCounter = 0

    loop
        if GetItemTypeId(UnitItemInSlot(whichUnit, inventorySlot)) == itemId then
            set itemCounter = itemCounter + 1
        endif
        set inventorySlot = inventorySlot + 1
        exitwhen inventorySlot == bj_MAX_INVENTORY
    endloop
 
    return itemCounter
endfunction
First, copy the code above and paste it in your map header.
Untitled-1.png

All you have to do now is check if the amount of a specific item type is above 1. If that's true, remove the picked up item from the unit.

There's a small problem. You need to specify which items are going to be dropped, and which ones won't. I suggest that you use those functions related to object editor. For example: the item level.

If a unit picks up a level 8 item, we drop it. I believe this is better than using a table or arrays, because it would be boring to register every single item in one of those.

Of course, use item level if you're not using it for anything else.

Here's the code:
  • Check Item
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item level of (Item being manipulated)) Equal to 8
    • Actions
      • Set tmp_point = (Position of (Triggering unit))
      • -------- Check if hero owns more than 1 of this type of item. --------
      • Custom script: if GetNumberOfItemType(GetTriggerUnit(), GetItemTypeId(GetManipulatedItem())) > 1 then
      • -------- Warn player --------
      • Custom script: call DisplayTextToPlayer(GetOwningPlayer(GetTriggerUnit()), 0, 0, "|cffffcc00WARNING:|r You cannot carry more than 1 of this item.")
      • -------- I'm not a fan of destroying queued orders. Just move the item, and the hero will lose it. --------
      • Item - Move (Item being manipulated) to tmp_point
      • Custom script: endif
      • -------- Get rid of leaks --------
      • Custom script: call RemoveLocation(udg_tmp_point)
EDIT: Fixed a mistake related to the custom function.
 

Attachments

  • countItemType.w3x
    17.5 KB · Views: 65
Last edited:
Level 6
Joined
Sep 24, 2015
Messages
174
I took bloodsouls trigger it's what i researched, thanks to others for helping :)
 
Status
Not open for further replies.
Top