//***************************************************************************************
//* *
//* ITEM RESTRICTION SYSTEM (IRS) *
//* *
//* Author: Doomlord *
//* Version: 1.0f *
//* *
//* Credits: *
//* + Vexorian: SimError [url]http://www.wc3c.net/showthread.php?t=101260[/url] *
//* + Magtheridon96: Help with code optimization *
//* + SeriousEnemy: Help with code optimization *
//* *
//***************************************************************************************
//*************************************************************************
//* INTRODUCTION: *
//* *
//* A simple system that allows for easy registration of requirements to *
//* carry a specific item type. This system also utilizes Custom Scripts *
//* to make it GUI-friendly. *
//* *
//* In addition, there is a tiny snippet that allows you to register *
//* unit type(s) as a "class". This can be referenced later by using the *
//* hashtable key (<Unit Raw Code>, 0) from IRS_Hashtable which will *
//* give you the class string of said unit. *
//* *
//*************************************************************************
//*******************
//* REQUIREMENTS: *
//* *
//* None *
//* *
//*******************
//************************************************************************************************************************************************
//* INSTALLATION INSTRUCTION: *
//* *
//* Step 1: Copy the code for SimError to your map's Map Header Custom Code. *
//* *
//* Step 2: Copy the whole IRS folder to your map. Don't forget to turn on "Automatically create unknown variables while pasting trigger data". *
//* *
//* Step 3: Create a trigger that runs at Map Initialization. It will be where you register the items and Heroes. *
//* *
//* Step 4: Register your desired unit type(s) as specific classes. Multiple unit types can be registered as one single type of Hero class. *
//* *
//* Step 5: Register your items as examplified in the Item Declaration trigger. Remember to use Map Initialization event. *
//* *
//************************************************************************************************************************************************
//**************************************************************************************
//* Class Registration API *
//* *
//* call IRS_ClassRegistration (integer unitRawCode, string className) *
//* *
//**************************************************************************************
//**************************************************************************
//* Item Requirement Registration API *
//* *
//* call IRS_ItemRegistration (integer itemRawCode, string itemClass, *
//* string heroClass, integer minLvl, integer minStr, integer minAgi, *
//* integer minInt, integer rangeFilter) *
//* *
//**************************************************************************
//=====================================================================================
// Item Pickup Check
function IRS_ItemAcquireCheck takes nothing returns boolean
local unit u = GetTriggerUnit ()
local player p = GetOwningPlayer(u)
local item it = GetManipulatedItem ()
local integer i = GetItemTypeId (it)
local integer k
local integer j = 0
if LoadStr(udg_IRS_Hashtable, GetUnitTypeId(u), 0) != LoadStr(udg_IRS_Hashtable, i, 1) and LoadStr(udg_IRS_Hashtable, i, 1) != null then
call IRS_SimError(p, udg_IRS_String[0] + " " + LoadStr(udg_IRS_Hashtable, i, 1))
call UnitRemoveItem(u, it)
return false
endif
loop
exitwhen j > 5
if LoadStr(udg_IRS_Hashtable, GetItemTypeId(UnitItemInSlot (u, j)), 0) == LoadStr(udg_IRS_Hashtable, i, 0) and UnitItemInSlot (u, j) != it and LoadStr(udg_IRS_Hashtable, i, 0) != null then
if udg_IRS_Switch then
call IRS_SimNotify(p, udg_IRS_String[6] + " " + LoadStr(udg_IRS_Hashtable, i, 0))
call UnitRemoveItem(u, UnitItemInSlot (u, j))
call UnitRemoveItem(u, it)
call UnitAddItem(u, it)
else
call IRS_SimError(p, udg_IRS_String[1] + " " + LoadStr(udg_IRS_Hashtable, i, 0))
call UnitRemoveItem(u, it)
endif
return false
endif
set j = j + 1
endloop
set k = LoadInteger(udg_IRS_Hashtable, i, 2)
if GetUnitLevel(u) < k then
call IRS_SimError(p, udg_IRS_String[2] + " " + I2S(k))
call UnitRemoveItem(u, it)
return false
endif
set k = LoadInteger(udg_IRS_Hashtable, i, 3)
if GetHeroStr(u, true) < k then
call IRS_SimError(p, udg_IRS_String[3] + " " + I2S(k))
call UnitRemoveItem(u, it)
return false
endif
set k = LoadInteger(udg_IRS_Hashtable, i, 4)
if GetHeroAgi(u, true) < k then
call IRS_SimError(p, udg_IRS_String[4] + " " + I2S(k))
call UnitRemoveItem(u, it)
return false
endif
set k = LoadInteger(udg_IRS_Hashtable, i, 5)
if GetHeroInt(u, true) < k then
call IRS_SimError(p, udg_IRS_String[5] + " " + I2S(k))
call UnitRemoveItem(u, it)
return false
endif
set k = LoadInteger(udg_IRS_Hashtable, i, 6)
if k >= 0 and k <= 2 then
if k == 1 then
if IsUnitType(u, UNIT_TYPE_MELEE_ATTACKER) then
call IRS_SimError(p, udg_IRS_String[7])
call UnitRemoveItem(u, it)
return false
endif
elseif k == 2 then
if IsUnitType(u, UNIT_TYPE_RANGED_ATTACKER) then
call IRS_SimError(p, udg_IRS_String[8])
call UnitRemoveItem(u, it)
return false
endif
endif
else
call IRS_SimError(p, "Invalid range filter value for item")
endif
set p = null
set it = null
set u = null
return false
endfunction
// Class Registration
function IRS_ClassRegistration takes integer unitType, string class returns nothing
call SaveStr (udg_IRS_Hashtable, unitType, 0, class)
endfunction
// Item Requirement Registration
function IRS_RegisterRestrictedItem takes integer itemRawCode, string itemClass, string heroClass, integer minLvl, integer minStr, integer minAgi, integer minInt, integer rangeFilter returns nothing
call SaveStr (udg_IRS_Hashtable, itemRawCode, 0, itemClass)
call SaveStr (udg_IRS_Hashtable, itemRawCode, 1, heroClass)
call SaveInteger (udg_IRS_Hashtable, itemRawCode, 2, minLvl)
call SaveInteger (udg_IRS_Hashtable, itemRawCode, 3, minStr)
call SaveInteger (udg_IRS_Hashtable, itemRawCode, 4, minAgi)
call SaveInteger (udg_IRS_Hashtable, itemRawCode, 5, minInt)
call SaveInteger (udg_IRS_Hashtable, itemRawCode, 6, rangeFilter)
endfunction
//===========================================================================
function InitTrig_IRS takes nothing returns nothing
local trigger acquireItem = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(acquireItem, EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerAddCondition(acquireItem, Condition(function IRS_ItemAcquireCheck))
set udg_IRS_Hashtable = InitHashtable()
set acquireItem = null
endfunction