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. Rubbed the right way, the genie is out of its lamp! The 12th Concept Art Contest Results have been announced.
    Dismiss Notice
  5. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice
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. BPower

    BPower

    Joined:
    Mar 18, 2012
    Messages:
    1,709
    Resources:
    21
    Spells:
    15
    Tutorials:
    1
    JASS:
    5
    Resources:
    21
    Not worth it. It would require a lot of extra space to store all these information.
    Also this effect might influence units in an aoe and not only the carrier.

    In order to safely remove all buffs from all affected units the code would be incredible long with alot of condition checks.
     
  2. It doesn't do that at the same moment the item is acquired, at least on flute.

    Edit:
    GIF (692x539, 4,85MB)
    [​IMG]
     
  3. Doomlord

    Doomlord

    Joined:
    Dec 15, 2011
    Messages:
    1,150
    Resources:
    14
    Spells:
    12
    JASS:
    2
    Resources:
    14
    ^What BPower said. I am bothered about that too but those extra miles are not worth going in the slightest. Coding is more or less about coping with not knowing what the users are going to throw at your system, that is why some mapmakers prefer to create simple systems running on a logic limited to a particular map of theirs where they can control everything.

    The buff is removed immediately so I guess it cannot affect nearby units.
     
  4. It hurts me as a perfectionist (sry, nothing I can do about it :/ ), but I guess as long as players playing my map I have this on won't complain about it, I won't get bothered too much about it.

    Again the range feature was really nice add-on, I will update the version I used on my map to this one now :)
     
  5. Doomlord

    Doomlord

    Joined:
    Dec 15, 2011
    Messages:
    1,150
    Resources:
    14
    Spells:
    12
    JASS:
    2
    Resources:
    14
    Thank you! Hope you enjoy it :)
     
  6. marvey323

    marvey323

    Joined:
    Feb 1, 2009
    Messages:
    106
    Resources:
    0
    Resources:
    0
    Uh

    This system is not MUI ?

    Because I placed it in my map, properly configured.. and as soon as another player picks up an item that is restricted for that player, I also get the error messages on my screen
     
  7. Doomlord

    Doomlord

    Joined:
    Dec 15, 2011
    Messages:
    1,150
    Resources:
    14
    Spells:
    12
    JASS:
    2
    Resources:
    14
    That is indeed an important bug. I probably overlooked that when I first made the system (then there was still no way to test multiplayer without someone to help). Anyway, thank you for reporting. Oh and it is called MPI, not MUI.

    The issue has been addressed in the new version. Please update the system ASAP.
     
  8. marvey323

    marvey323

    Joined:
    Feb 1, 2009
    Messages:
    106
    Resources:
    0
    Resources:
    0
    Update:

    So I have updated to version 1.0.f however upon importing, I get the errors :

    "Undeclared function IRS_RegisterRestrictedItem" as well as "Undeclared function IRS_ClassRegistration"

    even though I imported the map-specific custom code at the start as well as replacing the old IRS trigger with the new one. Am I missing something?


    Update 2:

    Solved the problem of importing the update: It was totally weird but I had to basically cut and paste my item configuration trigger from 1.0e to 1.0f .. and then the map saved without giving errors. Isn't that weird?
     
    Last edited: Jan 23, 2014
  9. Doomlord

    Doomlord

    Joined:
    Dec 15, 2011
    Messages:
    1,150
    Resources:
    14
    Spells:
    12
    JASS:
    2
    Resources:
    14
    Well that is really weird indeed. So, does everything work fine now? Is there still any issue?
     
  10. zv27

    zv27

    Joined:
    Aug 21, 2010
    Messages:
    295
    Resources:
    0
    Resources:
    0
    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)
     
  11. Doomlord

    Doomlord

    Joined:
    Dec 15, 2011
    Messages:
    1,150
    Resources:
    14
    Spells:
    12
    JASS:
    2
    Resources:
    14
    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 :)
     
  12. zv27

    zv27

    Joined:
    Aug 21, 2010
    Messages:
    295
    Resources:
    0
    Resources:
    0
    ok btw a very good system
     
  13. GhostHunter123

    GhostHunter123

    Joined:
    Oct 17, 2012
    Messages:
    464
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Would you mind adding a way to set a number limitation for each item? For example, I could have two items from the same class and no more.
     
  14. Doomlord

    Doomlord

    Joined:
    Dec 15, 2011
    Messages:
    1,150
    Resources:
    14
    Spells:
    12
    JASS:
    2
    Resources:
    14
    I will look into it when I have time. Thank you for the suggestion :)
     
  15. marvey323

    marvey323

    Joined:
    Feb 1, 2009
    Messages:
    106
    Resources:
    0
    Resources:
    0
    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
     
  16. Doomlord

    Doomlord

    Joined:
    Dec 15, 2011
    Messages:
    1,150
    Resources:
    14
    Spells:
    12
    JASS:
    2
    Resources:
    14
    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.
     
  17. And add 5k condition checks, I'd really like that, thank you!!
     
  18. MojObi-Dos

    MojObi-Dos

    Joined:
    Dec 31, 2014
    Messages:
    67
    Resources:
    0
    Resources:
    0
    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 :)
     
  19. MojObi-Dos

    MojObi-Dos

    Joined:
    Dec 31, 2014
    Messages:
    67
    Resources:
    0
    Resources:
    0
    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.
     
  20. zv27

    zv27

    Joined:
    Aug 21, 2010
    Messages:
    295
    Resources:
    0
    Resources:
    0
    As for me, I would only replace this
    Code (vJASS):
    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



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