• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

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.
 
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.
 
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

Last edited:
Status
Not open for further replies.
Back
Top