• 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.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

Limit Items

Status
Not open for further replies.
Level 33
Joined
Mar 27, 2008
Messages
8,035
A test map is attached.
A system that prevents a unit from holding more than 1 of the same item at a time.

The Event can also be related to an Event where the unit bought an item from the shop, not just collect from ground, okay ?
So don't worry about it, works for both collect item on ground and buys an item from shop Event
 

Attachments

  • Simple Prevent Same Item System.w3x
    13.4 KB · Views: 68
Level 7
Joined
Apr 27, 2011
Messages
272
Here is a simple JASS snippet for you ^.^

JASS:
//===========================================================================
// I made a snippet for you to use ^.^
//
// [1] Backup your map first!
//
// [2] Make a trigger in your map and convert it to custom text and clear its
// contents.
//
// [3] Copy paste everything in here and paste it inside the new trigger
//
// [4] Rename it as "Item Limiter"
//
// [5] And your ready to go!
//===========================================================================

function Display_Duration takes nothing returns real
    return 12.00 // <==this is how long the message will display itself
endfunction

function Message takes nothing returns string
    return "|cffff0000WARNING!: You can only have one weapon of the same type!" // <==this is the error message shown
    //when someone violates the item limit
endfunction

function Maximum_Item_Limit takes nothing returns integer
     return 1 // <== this is the maximum item limit
endfunction

function Item_Limiter takes nothing returns boolean
    local integer nloops       =0
    local integer nloopsmax    =5
    local integer ncounter     =0
    local unit    ItemOwner    =GetManipulatingUnit()
    local item    ItemAcquired =GetManipulatedItem()
    local item    ItemInSlot
    local integer ItemTypeId   =GetItemTypeId(ItemAcquired)
    
    loop
        exitwhen nloops>nloopsmax
        set ItemInSlot=UnitItemInSlot(ItemOwner,nloops)
        if(ItemInSlot!=null and GetItemTypeId(ItemInSlot)==ItemTypeId)then
            set ncounter=ncounter+1
        endif
        set nloops=nloops+1
    endloop
    
    if(ncounter>Maximum_Item_Limit())then
        call UnitRemoveItem(ItemOwner,ItemAcquired)
        DisplayTimedTextToPlayer(GetOwningPlayer(ItemOwner),0,0,Display_Duration(),Message())
    endif
    set ItemOwner=null
    set ItemInSlot=null
    return false
endfunction
//===========================================================================
function InitTrig_Item_Limiter takes nothing returns nothing
    local trigger Item_Limiter_Trg = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(Item_Limiter_Trg,EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddCondition(Item_Limiter_Trg,Condition(function Item_Limiter) )
endfunction

You can now configure the warning message, its display time, and the maximum item limit.
 
Last edited:
Status
Not open for further replies.
Top