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

Item restriction system

Status
Not open for further replies.
Level 5
Joined
Dec 21, 2012
Messages
89
Does someone know good item restriction system which limit to have just one item of the same type, like only one armor per hero and is automatically dropping another armor if the hero pick him up. Preferable is Jass but can be Mui
 
I couldn't find a way without removing and creating the item, but here's what I coded real quick

It only allows you to hold on of each item-class (there's enough for all 6 items slots) so in the object editor pick a classifcation for each item.

JASS:
scope ItemType initializer onInit

    private function Actions takes nothing returns boolean
        local integer i  = 0
        local unit u     = GetTriggerUnit()
        local item itm   = GetManipulatedItem()
        local item tmp   = null
        local itemtype x = GetItemType(itm)
        
        loop
            exitwhen i == 6
            set tmp = UnitItemInSlot(u, i)
            
            if (GetItemType(tmp) == x and itm != tmp) then
                call CreateItem(GetItemTypeId(itm), GetUnitX(u), GetUnitY(u))
                call RemoveItem(itm)
                
                set itm = null
                set tmp = null
                set u   = null
                
                return false
            endif
            
            set i = i + 1
        endloop
        
        set itm = null
        set tmp = null
        set u   = null
        set x   = null
        
        return false
    endfunction

    //===========================================================================
    private function onInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM)
        call TriggerAddCondition(t, function Actions)
    endfunction

endscope
 
Status
Not open for further replies.
Top