• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Item Restriction System (IRS) v1.0f

ITEM RESTRICTION SYSTEM v1.0f

Features
  • Easy registration of specific item-type requirements.
  • Support item classes.
  • GUI-friendly interface and usage.
  • A single trigger with short code.
  • Vanilla World Editor JASS.
  • => A simple item restriction system, could be useful for RPGs.

Codes:

JASS:
//***************************************************************************************
//*                                                                                     *
//*                      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

Range filter values are as follow:
  • "0" means the item can be used by both melee and ranged units.
  • "1" means the item is for ranged units only.
  • "2" means the item is for melee units only.
Other values will cause the system to throw an error.

Here is cool suggestion by zv27 for those who have difficulty remembering the numbers.

zv27;2476654 said:
Range filter values are as follow:

"0" means the item can be used by both melee and ranged units.
"1" means the item is for ranged units only.
"2" means the item is for melee units only.

small suggestions[I think it would be easier to navigate]

set IRS_MeleeRanged = 0 -> means the item can be used by both melee and ranged units.
set IRS_Ranged = 1 -> means the item is for ranged units only.
set IRS_Melee = 2 -> means the item is for melee units only.

call IRS_ItemRegistration ('afac', "Weapon", "Mountain King", 10, 20, 10, 10, udg_IRS_Melee)

JASS:
// Map Header Custom Code

// SimError by Vexorian at wc3c.net

// Modified version

function IRS_SimError takes player p, string s returns nothing
    local string msg = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n|cffffcc00" + s + "|r"
    local sound error = CreateSoundFromLabel ("InterfaceError", false, false, false, 10, 10)

    if GetLocalPlayer() == p then
        call ClearTextMessages ()
        call DisplayTimedTextToPlayer (p, 0.52, 0.96, 2.00, msg)
        call StartSound (error)
    endif
endfunction

function IRS_SimNotify takes player p, string s returns nothing
    local string msg = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n|cffffcc00" + s + "|r"
    local sound notify = CreateSoundFromLabel("Hint", false, false, false, 10, 10)

    if GetLocalPlayer() == p then
        call ClearTextMessages()
        call DisplayTimedTextToPlayer (p, 0.52, 0.96, 2.00, msg)
        call StartSound (notify)
    endif
endfunction

  • Setting
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Set the error messages here --------
      • -------- Don't touch the indexes, modify the value only --------
      • -------- Wrong Hero Class --------
      • Set IRS_String[0] = This item is not for your Hero's class. It is reserved only for
      • -------- Hero already has an item of the same class --------
      • Set IRS_String[1] = Your Hero already has an item of type
      • -------- Insufficient Hero Level --------
      • Set IRS_String[2] = The minimum Level required to carry this item is
      • -------- Insufficient Strength --------
      • Set IRS_String[3] = The minimum Strength required to carry this item is
      • -------- Insufficient Agility --------
      • Set IRS_String[4] = The minimum Agility required to carry this item is
      • -------- Insufficient Intelligence --------
      • Set IRS_String[5] = The minimum Intelligence required to carry this item is
      • -------- Alternate for Hero already has an item of the same class, IRS_Switch = true only --------
      • Set IRS_String[6] = A new item has replaced an item in your inventory with class
      • -------- Ranged Only --------
      • Set IRS_String[7] = This item is for ranged units only
      • -------- Melee Only --------
      • Set IRS_String[8] = This item is for melee units only
      • -------- ================================================== --------
      • -------- Set to true to switch to Drop-old-item-of-same-class mode --------
      • Set IRS_Switch = False

Let us try to register the following requirements for Alleria's Flute of Accuracy (afac):
  • Mountain King class only.
  • Item Classification: Weapon.
  • A minimum Level of 10.
  • A minimum Strength of 20.
  • A minimum Agility of 10.
  • A minimum Intelligence of 10.
  • Ranged units only.

Here is the examplary code:

  • Examplary Declaration
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Item Requirements Registration --------
      • Custom script: call IRS_ItemRegistration ('afac', "Weapon", "Mountain King", 10, 20, 10, 10, 1)
      • -------- Item Requirements Registration - End --------



+ v1.0: Initial release.
+ v1.0a: Improved the API and the code alike. Fixed some bugs. Added error message configurables.
+ v1.0b: Fixed a bug with item type.
+ v1.0c: Added a variable creation method for the Hashtable.
+ v1.0d: Added a new boolean switch that drops an old item of the same class instead of the new one. Fixed Map Header code logic.
+ v1.0e: Added range filter.
+ v1.0f: Fixed an important bug with error messages.


FINAL WORDS

+ All feedback, testing, criticism, suggestions, etc. are welcome. Thanks in advance.
+ If you need help with this system, contact me or post in this thread.

Keywords:
item, restriction, ORPG, RPG, class
Contents

Item Restriction System v1.0f (Map)

Reviews
Item Restriction System v1.0a | Reviewed by Maker | 27th Feb 2013 APPROVED [tr] A very useful system
Level 16
Joined
Dec 15, 2011
Messages
1,423
Range filter values are as follow:

"0" means the item can be used by both melee and ranged units.
"1" means the item is for ranged units only.
"2" means the item is for melee units only.

small suggestions[I think it would be easier to navigate]

set IRS_MeleeRanged = 0 -> means the item can be used by both melee and ranged units.
set IRS_Ranged = 1 -> means the item is for ranged units only.
set IRS_Melee = 2 -> means the item is for melee units only.

call IRS_ItemRegistration ('afac', "Weapon", "Mountain King", 10, 20, 10, 10, IRS_Melee)

Looks like a cool idea. However, since some people would prefer to type only a number instead of a variable name, I will quote your suggestion in the main post so that people can choose whichever method they prefer :)
 
Level 5
Joined
Feb 1, 2009
Messages
111
Is it possible to make this scenario any chance?

-> unit type A can carry any item
-> unit type B can only carry a few of those items that A can
-> unit type C can only carry a few of those items that A can but not the ones B can
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
Is it possible to make this scenario any chance?

-> unit type A can carry any item
-> unit type B can only carry a few of those items that A can
-> unit type C can only carry a few of those items that A can but not the ones B can

I think I will look into it some other time. But first I would like you to explain the benefits of this addition since, in my opinion, public systems should have features that benefit all maps that use it, not only a single map in particular.

Anyhow, thank you for the suggestion.
 

Deleted member 219079

D

Deleted member 219079

And add 5k condition checks, I'd really like that, thank you!!
 
Level 4
Joined
Dec 31, 2014
Messages
68
I appreciate the age of this post and I know this isn't really the place for troubleshooting but I am having difficulty with my custom Items with this system.
I have sent a private message to the Creator and also made my own thread about this. I thought since that you guys who have posted here seem to be quite savvy with triggers and scripts may know whats wrong?


So what is happening is when viewing the rawdata I see my custom items looking something along the lines of 'l020:ratc'.
I have tried That with the custom script;
  • Custom script: call IRS_RegisterRestrictedItem ('l020:ratc', "Weapon", null, 0, 0, 0, 0, 0)
[as I only need it so that a unit cannot carry 2 of the same type of weapon and all my Heroes are melee characters I made it 0,0,0,0,0]

This throws me a script error: 'Expected a valid argument list'.

I have also tried l020 on its own;
  • Custom script: call IRS_RegisterRestrictedItem ('l020', "Weapon", null, 0, 0, 0, 0, 0)
Which gets accepted by the script but doesn't work in-game.

The same with ratc;
  • Custom script: call IRS_RegisterRestrictedItem ('ratc', "Weapon", null, 0, 0, 0, 0, 0)
which again, gets accepted by the script but doesn't work.

I'd be grateful for any advise :)
 
Level 4
Joined
Dec 31, 2014
Messages
68
Ok I managed to get it to work, for future reference if people are having trouble with custom items as I have;

Type the 'I000' part at Call IRS_RegisterRestrictedItem. Make sure it is an i not an l.
 
Level 10
Joined
Aug 21, 2010
Messages
316
As for me, I would only replace this
JASS:
function IRS_SimError takes player p, string s returns nothing
    local string msg = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n|cffffcc00" + s + "|r"
    local sound error = CreateSoundFromLabel ("InterfaceError", false, false, false, 10, 10)

    if GetLocalPlayer() == p then
        call ClearTextMessages ()
        call DisplayTimedTextToPlayer (p, 0.52, 0.96, 2.00, msg)
        call StartSound (error)
    endif
endfunction

function IRS_SimNotify takes player p, string s returns nothing
    local string msg = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n|cffffcc00" + s + "|r"
    local sound notify = CreateSoundFromLabel("Hint", false, false, false, 10, 10)

    if GetLocalPlayer() == p then
        call ClearTextMessages()
        call DisplayTimedTextToPlayer (p, 0.52, 0.96, 2.00, msg)
        call StartSound (notify)
    endif
endfunction


JASS:
function SimMsg takes player p,string s,string sL,integer fir,integer for,real x,real y,real dr returns nothing
    local string msg="\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n|cffffcc00"+s+"|r"
    local sound error=CreateSoundFromLabel(sL, false, false, false,fir,for)
    if GetLocalPlayer()==p then
        call ClearTextMessages()
        call DisplayTimedTextToPlayer(p,x,y,dr,msg)
        call StartSound(error)
    endif
endfunction
 
Level 4
Joined
Aug 17, 2014
Messages
102
When I get 10 errors saying "Symbol not Declared"

these errors are affected by the following
call IRS_SimError(p, udg_IRS_String[0] + " " + LoadStr(udg_IRS_Hashtable, i, 1))
call IRS_SimNotify(p, udg_IRS_String[6] + " " + LoadStr(udg_IRS_Hashtable, i, 0))
call IRS_SimError(p, udg_IRS_String[1] + " " + LoadStr(udg_IRS_Hashtable, i, 0))
call IRS_SimError(p, udg_IRS_String[2] + " " + I2S(k))
call IRS_SimError(p, udg_IRS_String[3] + " " + I2S(k))
call IRS_SimError(p, udg_IRS_String[4] + " " + I2S(k))
call IRS_SimError(p, udg_IRS_String[5] + " " + I2S(k))
call IRS_SimError(p, udg_IRS_String[7])
call IRS_SimError(p, udg_IRS_String[8])
call IRS_SimError(p, "Invalid range filter value for item")

I notice that most of them are affected by the " " , but really have no idea on how to solve this my jass knowledge is literally 0... :(
 
Level 12
Joined
Jun 12, 2010
Messages
413
When I get 10 errors saying "Symbol not Declared"

these errors are affected by the following
call IRS_SimError(p, udg_IRS_String[0] + " " + LoadStr(udg_IRS_Hashtable, i, 1))
call IRS_SimNotify(p, udg_IRS_String[6] + " " + LoadStr(udg_IRS_Hashtable, i, 0))
call IRS_SimError(p, udg_IRS_String[1] + " " + LoadStr(udg_IRS_Hashtable, i, 0))
call IRS_SimError(p, udg_IRS_String[2] + " " + I2S(k))
call IRS_SimError(p, udg_IRS_String[3] + " " + I2S(k))
call IRS_SimError(p, udg_IRS_String[4] + " " + I2S(k))
call IRS_SimError(p, udg_IRS_String[5] + " " + I2S(k))
call IRS_SimError(p, udg_IRS_String[7])
call IRS_SimError(p, udg_IRS_String[8])
call IRS_SimError(p, "Invalid range filter value for item")

I notice that most of them are affected by the " " , but really have no idea on how to solve this my jass knowledge is literally 0... :(

Seems like you did not import the global variables. Make sure the following variables exist in your map:
* IRS_String (string array)
* IRS_Hashtable (hashtable)
* IRS_Switch (boolean)
 
Level 4
Joined
Aug 17, 2014
Messages
102
Seems like you did not import the global variables. Make sure the following variables exist in your map:
* IRS_String (string array)
* IRS_Hashtable (hashtable)
* IRS_Switch (boolean)
I just finish checking and I do already have those variables in my map, but now after testing it again the jass helper is telling me undeclared function:
IRS_SimError and IRS_SimNotify

So do I just have to make variables for those and what type of variable would they be?
Sorry, for the poor knowledge
 
Level 12
Joined
Jun 12, 2010
Messages
413
I just finish checking and I do already have those variables in my map, but now after testing it again the jass helper is telling me undeclared function:
IRS_SimError and IRS_SimNotify

So do I just have to make variables for those and what type of variable would they be?
Sorry, for the poor knowledge

Make a trigger called "SimError" in your map, and copy this code into it:
JASS:
library SimError initializer
function IRS_SimError takes player p, string s returns nothing
   local string msg = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n|cffffcc00" + s + "|r"
   local sound error = CreateSoundFromLabel ("InterfaceError", false, false, false, 10, 10)

   if GetLocalPlayer() == p then
       call ClearTextMessages ()
       call DisplayTimedTextToPlayer (p, 0.52, 0.96, 2.00, msg)
       call StartSound (error)
   endif
endfunction

function IRS_SimNotify takes player p, string s returns nothing
   local string msg = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n|cffffcc00" + s + "|r"
   local sound notify = CreateSoundFromLabel("Hint", false, false, false, 10, 10)

   if GetLocalPlayer() == p then
       call ClearTextMessages()
       call DisplayTimedTextToPlayer (p, 0.52, 0.96, 2.00, msg)
       call StartSound (notify)
   endif
endfunction


endlibrary

Make sure you have vJass enabled. Alternatively, you can remove "library" and "endlibrary" lines and put the code in your Map Header instead.
 
Level 4
Joined
Aug 17, 2014
Messages
102
Make a trigger called "SimError" in your map, and copy this code into it:
JASS:
library SimError initializer
function IRS_SimError takes player p, string s returns nothing
   local string msg = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n|cffffcc00" + s + "|r"
   local sound error = CreateSoundFromLabel ("InterfaceError", false, false, false, 10, 10)

   if GetLocalPlayer() == p then
       call ClearTextMessages ()
       call DisplayTimedTextToPlayer (p, 0.52, 0.96, 2.00, msg)
       call StartSound (error)
   endif
endfunction

function IRS_SimNotify takes player p, string s returns nothing
   local string msg = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n|cffffcc00" + s + "|r"
   local sound notify = CreateSoundFromLabel("Hint", false, false, false, 10, 10)

   if GetLocalPlayer() == p then
       call ClearTextMessages()
       call DisplayTimedTextToPlayer (p, 0.52, 0.96, 2.00, msg)
       call StartSound (notify)
   endif
endfunction


endlibrary

Make sure you have vJass enabled. Alternatively, you can remove "library" and "endlibrary" lines and put the code in your Map Header instead.
I just tried it out and I changed where you put simError to IRS_SimError but now I still need something for the IRS_SimNotify and also I get different errors from the Vjass syntax errors error window than I do from the Script Errors window

d7f740eba9114378bfe678275a56c8ad.png


66e92e25ac07d40e4fc96c41a4c43f67.png


0b57d368b664da45b788f9e432077c30.png


2a52eb4960e32637f20ba1d98078a8b7.png
 
Level 4
Joined
Aug 17, 2014
Messages
102
I just figured it out and I feel slightly stupid... I put it on the map custom code and it seemed to work thanks for the help and patience _Guhun_

EDIT:
After it working fine all day I come back home and now suddenly I am having a new error... it was working just fine earlier without any issues and I literally have not changed anything I was working on something completely different and suddenly I was unable to test my map...

31c2da894d55b736a8475cdc067741e2.png

These are the errors I am being given and below is the affected trigger
b24f0482edc8bfbd64c55aba4a8e13d6.png
 
Last edited:
Top