Name | Type | is_array | initial_value |
ItemClassErrorMsg | string | Yes | |
ItemClassId | integer | Yes | 0 |
ItemClassLimit | integer | Yes | 0 |
ItemClassName | string | Yes | |
NumberOfItemClasses | integer | No | 0 |
//TESH.scrollpos=55
//TESH.alwaysfold=0
//===========================================================================
//======================== 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
//===========================================================================
//===========================================================================
//===========================================================================