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

Simple ItemClassLimit

This bundle is marked as useful / simple. Simplicity is bliss, low effort and/or may contain minor bugs.
Simple system for simple maps.

Allows GUI users to easily create item carrying limitations with practically as many classifications as they want.

The code itself is in JASS but JNGP is NOT REQUIRED.

Implementation: (if you know JASS this should be self explanatory)
1. Copy the trigger ItemClassLimit and paste it amongst your map's triggers.
2. Make sure you have these 5 global variables in the map:
integer NumberOfItemClasses (default value 0)
integer array[1000] ItemClassId
integer array[1000] ItemClassLimit
string array[1000] ItemClassName
string array[1000] ItemClassErrorMsg
(The array size is not crucial, just make sure it's big enough. 100 is huge already.)
3. Register new item classes in separate trigger using GUI CustomScript

A new item class can be registerred with one simple CustomScript line.
example:
call NewItemClass( "MainHand Weapon", 1000, 1 )

This example would set up a class called MainHand Weapon, Item level to use as classification is 1000 and only 1 item can be carried by the same unit.

This system ONLY works with stardard war3 6 slot inventory.

Hopefully this will get approved even by the minimum standards so that it may help someone.

(I know this is quite simple, but as I made this for a request, I thought others might also have use for it.)

JASS:
//===========================================================================
//======================== ITEM CLASS LIMIT =================================
//===========================================================================
//
// - This simple system allows user to limit the number of specific class of
//   items one unit can carry.
//
// - ItemLevel is used as item class. So there can be thousands of custom
//   item classes.
//
// - A new item class can be registerred with this function:
//   call NewItemClass( "className", ItemLevelToUse, CarryingLimit )
//
//   Example: call NewItemClass( "Main Hand", 1000, 1 )
//    - After this, open Object Editor and set an item's level to 1000
//                  ( ! hold Shift while clicking ! )
//    - Now your item is limited to 1 item per unit.
//
// - JNGP is NOT REQUIRED to use this. Normal WE work's just fine.
//
// - This only works with the standard WC3 inventory.
//
// - No need to give credits to anyone, feel free to edit.
//
// - Originally made by Wezthal for Bloodbane7's request.
//   
//===========================================================================
function GetItemClassIndex takes integer ItemClassId returns integer
    local integer i = 0
    loop
        exitwhen (i > udg_NumberOfItemClasses - 1)
        if (udg_ItemClassId[i] == ItemClassId) then
            return i
        endif
        set i = i + 1
    endloop
    return -1
endfunction
//===========================================================================
function CountItemsOfClass takes unit u, integer index returns integer
    local integer i = 0
    local integer n = 0
    loop
        exitwhen i > 5
        if (GetItemLevel(UnitItemInSlot(u, i)) == udg_ItemClassId[index]) then
            set n = n + 1
        endif
        set i = i + 1
    endloop
    return n
endfunction
//===========================================================================
function AcquireItem takes nothing returns nothing
    local unit u = GetManipulatingUnit()
    local item it = GetManipulatedItem()
    local integer i = GetItemClassIndex(GetItemLevel(it))
    local integer n = udg_ItemClassLimit[i]
    local real f
    if (CountItemsOfClass(u, i) > n) then
        set f = GetUnitFacing(u)
        set n = GetItemTypeId(it)
        call RemoveItem(it)
        set it = CreateItem(n, GetUnitX(u)+(75.*Cos(f*bj_DEGTORAD)), GetUnitY(u)+(75.*Sin(f*bj_DEGTORAD)))
        call DisplayTimedTextToPlayer(GetOwningPlayer(u), 0, 0, 1.00, "|cffFFCC00"+udg_ItemClassErrorMsg[i]+"|r")
    endif
    set it = null
    set u = null
endfunction
//===========================================================================
function NewItemClass takes string ItemClassName, integer ItemClassId, integer ItemClassLimit returns nothing
    if (ItemClassName == null) or (ItemClassName == "") or (ItemClassId == null) or (ItemClassId < 0) or (ItemClassLimit < 1) then
        call BJDebugMsg("Couldn't register new itemclass. Check parameters.")
        return
    else
        set udg_ItemClassName[udg_NumberOfItemClasses] = ItemClassName
        set udg_ItemClassId[udg_NumberOfItemClasses] = ItemClassId
        set udg_ItemClassLimit[udg_NumberOfItemClasses] = ItemClassLimit
        if (ItemClassLimit == 1) then
            set udg_ItemClassErrorMsg[udg_NumberOfItemClasses] = "You can only carry "+I2S(ItemClassLimit)+" "+ItemClassName+"."
        else
            set udg_ItemClassErrorMsg[udg_NumberOfItemClasses] = "You can only carry "+I2S(ItemClassLimit)+" "+ItemClassName+"s."
        endif
        set udg_NumberOfItemClasses = udg_NumberOfItemClasses + 1
    endif
endfunction
//===========================================================================
function InitTrig_ItemClassLimit takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerAddAction(t, function AcquireItem)
    set t = null
endfunction
//===========================================================================
//===========================================================================
//===========================================================================

Keywords:
Item, Limit.
Contents

Just another Warcraft III map (Map)

Reviews
18:00, 15th Apr 2010 TriggerHappy: This is just a bunch of O(n) searches. Just use hashtables.

Moderator

M

Moderator

18:00, 15th Apr 2010
TriggerHappy:

This is just a bunch of O(n) searches.
Just use hashtables.
 
Level 7
Joined
May 21, 2009
Messages
289
I like it, since he made it for a map I needed. And its so simple, I know hardly anything about JASS and I didn't need to use JASS at all. One simple trigger in GUI is all I ever had to edit.

EDIT:
This was intended for use with multiple players with multiple heroes, and I'm using it for multiple heroes for every player.
 
Top