1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  3. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  4. From the gates of hell, the 5th Special Effect Contest Results have emerged.
    Dismiss Notice
  5. Rubbed the right way, the genie is out of its lamp! The 12th Concept Art Contest Results have been announced.
    Dismiss Notice
  6. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  7. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
Do you have good ideas for new contests? If so, please open new threads in the Contest Submission sub-forum to discuss them.
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

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

Submitted by Doomlord
This bundle is marked as approved. It works and satisfies the submission rules.
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:

Code (vJASS):
//***************************************************************************************
//*                                                                                     *
//*                      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
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.



Code (vJASS):
// 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
  • 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


Examplary Declaration

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 --------



Changelog

+ 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
Moderator
Item Restriction System v1.0a | Reviewed by Maker | 27th Feb 2013 APPROVED [tr] [IMG] A very useful system
  1. Recklessness

    Recklessness

    Joined:
    Aug 17, 2014
    Messages:
    82
    Resources:
    0
    Resources:
    0
    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... :(
     
  2. _Guhun_

    _Guhun_

    Joined:
    Jun 12, 2010
    Messages:
    371
    Resources:
    7
    Spells:
    6
    Tutorials:
    1
    Resources:
    7
    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)
     
  3. Recklessness

    Recklessness

    Joined:
    Aug 17, 2014
    Messages:
    82
    Resources:
    0
    Resources:
    0
    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
     
  4. _Guhun_

    _Guhun_

    Joined:
    Jun 12, 2010
    Messages:
    371
    Resources:
    7
    Spells:
    6
    Tutorials:
    1
    Resources:
    7
    Make a trigger called "SimError" in your map, and copy this code into it:
    Code (vJASS):

    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.
     
  5. Recklessness

    Recklessness

    Joined:
    Aug 17, 2014
    Messages:
    82
    Resources:
    0
    Resources:
    0
    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

    [​IMG]

    [​IMG]

    [​IMG]

    [​IMG]
     
  6. Recklessness

    Recklessness

    Joined:
    Aug 17, 2014
    Messages:
    82
    Resources:
    0
    Resources:
    0
    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...

    [​IMG]
    These are the errors I am being given and below is the affected trigger
    [​IMG]
     
    Last edited: Mar 18, 2019