• 🏆 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!

[Solved] Need Some Helps With vJass

Status
Not open for further replies.
Level 5
Joined
Sep 21, 2012
Messages
68
Hi, is anyone know how to add a condition to this trigger (At the beginning of this trigger).

Condition:
  • Multiple ConditionsOr - Any (Conditions) are true
    • Conditions
      • (Unit-type of (Triggering unit)) Not equal to (!=) A Unit
      • (Unit-type of (Triggering unit)) Not equal to (!=) A Unit
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


For more information, I'm currently using this Item Class System ([code=jass] Item Restriction System (IRS) v1.0f) by Doomlord. Every player has a Carrier (A moving Bag) follow its player's hero. Every items divided into many classes and levels.
For examble:
-Item A: require level 15, class Warrior
But that player's hero don't have enough level to equip Item A so his Carrier picked it up. The problem showed up, the system said "your hero don't have enough level to carry this item". That's why I want to add the above condition to the trigger so that the trigger can pass that Carrier. Let that Carrier to pick up that item without any problem.....

I hope you guys understand what I've said. I can't add this condition because my knowledge about Jass Things is 0%.
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
I did not take a look at what this system actually does, but in the function IRS_ItemAcquireCheck you could try adding a the condition at the top and exiting the trigger, if the unit is of this type.

Add under the locals of IRS_ItemAcquireCheck:
JASS:
if(GetUnitTypeId(u)=='RawcodeOfYourUnit' or GetUnitTypeId(u)=='RawcodeOfYourUnit') then
    set p = null
    set it = null
    set u = null
    return false
endif
RawcodeOfYourUnit is something like 'hfoo'. (press ctrl + D to see rawcodes in the object editor) Rawcodes are written in 'apostrophes'. Use the keyword or between the conditions.

Rawcode of a footman:
JASS:
'hfoo'
For custom units you will see something like h000:hfoo in the object editor. The rawcode is only the first part ('h000').

Tell me if this works for you. If not I can take a closer look at this system.
 
Level 5
Joined
Sep 21, 2012
Messages
68
Well, it didn't work.... still "your unit don't have enough level"

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(GetUnitTypeId(u)== 'hamg' or GetUnitTypeId(u)=='hapm') then
set p = null
set it = null
set u = null
return false
endif

    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
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
The raw codes you are using are 'hamg' and 'hapm', which is archmage and admiral proudmoore. You need to use the raw codes of the Carriers. Did you modify these two heroes into the carriers? If not, you are using the wrong raw codes.

If you based your carriers on these two heroes, you also need a different raw code.
 
Level 5
Joined
Sep 21, 2012
Messages
68
The raw codes you are using are 'hamg' and 'hapm', which is archmage and admiral proudmoore. You need to use the raw codes of the Carriers. Did you modify these two heroes into the carriers? If not, you are using the wrong raw codes.

If you based your carriers on these two heroes, you also need a different raw code.

I was using the [code=jass] Item Restriction System (IRS) v1.0f map to test it (because my map takes about 10 minutes in total to save and load).

Edit: It worked. Thank you.
 
Last edited:
Status
Not open for further replies.
Top