library ClassReq initializer init
globals
hashtable ClassReqHash = InitHashtable()
endglobals
private function onItemPickup takes nothing returns nothing
local unit picker = GetManipulatingUnit()
local item manip = GetManipulatedItem()
local integer manipID = GetItemTypeId(manip)
local integer unitID = GetUnitTypeId(picker)
local player p = GetOwningPlayer(picker)
local integer playerID = GetPlayerId(p)
local integer i = 1
local integer i2
local boolean trueCheck = LoadInteger(ClassReqHash, 1, manipID) > 5
local boolean b = false
if not trueCheck then
return
endif
set trueCheck = LoadInteger(ClassReqHash, 0, manipID) < GetHeroLevel(picker)
loop
set i2 = LoadInteger(ClassReqHash, i, manipID)
if i2 > 5 then
set b = b or i2 == unitID
set i = i + 1
else
exitwhen true
endif
endloop
if not(trueCheck and b) then
call UnitRemoveItem(picker, manip)
if not b then
call DisplayTimedTextToPlayer(p, 0, 0, 15, GetUnitName(picker) + " cannot equip " + GetItemName(manip))
else
call DisplayTimedTextToPlayer(p, 0, 0, 15, GetUnitName(picker) + " is too low to equip " + GetItemName(manip))
endif
endif
set picker = null
set manip = null
set p = null
endfunction
function RegisterItem takes nothing returns nothing
local integer i = 0
call SaveInteger(ClassReqHash, 0, udg_ClassReqItem, udg_ClassReqLevel)
loop
if udg_ClassReqUnit[i] > 5 then
call SaveInteger(ClassReqHash, i + 1, udg_ClassReqItem, udg_ClassReqUnit[i])
set i = i + 1
else
exitwhen true
endif
endloop
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerAddAction(t, function onItemPickup)
endfunction
endlibrary