• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

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