• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Triggers ain't work

Status
Not open for further replies.
Well, first of all, hello everyone :)

I'm making a item core which stores and gives data of every item, and I got some troubles with it. This core contains:
  • GetItemIndex: returns the item's index which is like the unit indexing system, if an item hasn't got one, it'll set an index for that item.
  • ItemRegistry: takes items' values like rawid, model, icon,... and creates a RegIndex for that type of item.
  • GetItemTier: 1 type of item can have many tiers, this function returns the tier of an item and set its tier if it hasn't got one.
  • ItemStatRegistry: takes stat of a specific tier of an item type and save it in hashtable.

If I succeeded, I could have many items by registrying it in trigger, but only needed to create 1 item in Object Editor.

This is my ItemCore library:

JASS:
library ItemCore

    globals
        private                 item        array   ItemIndexed   
        private                 integer             ItemIndexMax        =   0
        private                 integer     array   ItemTier
        
        private                 integer     array   ItemTierMax
        
        private                 integer             ItemRegMax          =   0
        private                 string      array   ItemRegRawId    
        private                 string      array   ItemRegAnimationTag
        private                 string      array   ItemRegModel    
        private                 string      array   ItemRegIcon    
        private                 integer     array   ItemRegSlot
        private                 string      array   ItemRegAttachPoint    
        private                 string      array   ItemRegType 
        private     constant    string              ABC                 = "0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[ ]^_`abcdefghijklmnopqrstuvwxyz"
        private                 hashtable   array   ItemData   
    
    endglobals
    
    //========================Villager's Animation Tags======================//
    //                  None = VillagerMan Attack                            //
    //                  Alternate = Onehand Attack                           //
    //                  Channel = Twohand Attack                             //
    //                  Defend = Defend Attack                               //
    //                  Flesh = Spell Attack                                 //
    //                  Gold = Duel Attack                                   //
    //                  Lumber = Bow Attack                                  //
    //                  Work = Crossbow Attack                               //
    //=======================================================================//
    
function ConvertItemRawCode takes string rawcode returns integer id
    local integer array     i
    local integer           t           = 0
    local integer           n           = 0
    local integer           id
    local string  array     char
    local string            p
    
    
    loop
        exitwhen t > 3
        set char[t] = SubString(rawcode,t,t+1)
        
        loop
            exitwhen n > 74 or SubString(ABC, n, n+1) ==  char[t]
            set n = n + 1
        endloop
        
        set i[t] = n + 48
        set n = 0
        set t = t + 1
    endloop

    set id = i[0]*256*256*256 + i[1]*256*256 + i[2]*256 + i[3]  
    return id
    
endfunction

function GetItemIndex takes item temp_i returns integer index
    local integer i = 1
    local integer index
    local boolean hadvalue = false
    
    loop
        exitwhen (i > ItemIndexMax or hadvalue == true)
        if ItemIndexed[i] == temp_i then
            set hadvalue = true
            set index = i
        endif
        set i = i + 1
    endloop
        
    if hadvalue == false then
        set ItemIndexMax = ItemIndexMax + 1
        set index = ItemIndexMax
        set ItemIndexed[index] = temp_i
    endif
    
    return index
endfunction

//=============================================================================//
//==========================ITEM REGISTRY INDEX================================//
//=============================================================================//

private function GetItemRegIndex takes item temp_i returns integer index
    local integer   i       = 0
    local integer   index
    
    loop
        exitwhen i > ItemRegMax
        if ConvertItemRawCode(ItemRegRawId[i]) == GetItemTypeId( temp_i ) then
            set index = i
        endif
        set i = i + 1
    endloop
    return index
endfunction

private function GetItemRegIndexEx takes string rawid returns integer ex_index
    local integer   i       = 0
    local integer   ex_index
    
    loop
        exitwhen i > ItemRegMax
        if ItemRegRawId[i] == rawid then
            set ex_index = i
        endif
        set i = i + 1
    endloop
    return ex_index
endfunction

//=============================================================================//
//===========================GET ITEM TIER VALUE===============================//
//=============================================================================//

function GetItemTier takes item temp_i returns integer tier
    local integer   i           = 1
    local integer   regindex    = GetItemRegIndex(temp_i)
    local integer   index       = GetItemIndex(temp_i)
    local integer   tier
    local boolean   hadvalue    = false
    
    loop
        exitwhen (i > ItemTierMax[regindex] or hadvalue == true)
        if ItemTier[index] == i then
            set hadvalue = true
            set tier = i
            
        endif
        set i = i + 1
    endloop
        
    if hadvalue == false then
        set ItemTier[index] = GetRandomInt( 1 , ItemTierMax[regindex] ) 
        set tier = ItemTier[index]
    endif
    
    return tier
endfunction

function GetItemTierName takes item temp_i returns string name
    local   integer     tier        = GetItemTier(temp_i)
    local   integer     regindex    = GetItemRegIndex(temp_i)
    local   string      name        = LoadStr( ItemData[regindex] , 0 , tier )
    return name
endfunction

function GetItemTierCost takes item temp_i returns integer cost
    local   integer     tier        = GetItemTier(temp_i)
    local   integer     regindex    = GetItemRegIndex(temp_i)
    local   integer     cost        = LoadInteger( ItemData[regindex] , 1 , tier )
    return cost
endfunction

function GetItemTierDamage takes item temp_i returns integer dmg
    local   integer     tier        = GetItemTier(temp_i)
    local   integer     regindex    = GetItemRegIndex(temp_i)
    local   integer     dmg         = LoadInteger( ItemData[regindex] , 2 , tier )
    return dmg
endfunction

function GetItemTierArmor takes item temp_i returns integer a
    local   integer     tier        = GetItemTier(temp_i)
    local   integer     regindex    = GetItemRegIndex(temp_i)
    local   integer     a        = LoadInteger( ItemData[regindex] , 3 , tier )
    return a
endfunction

function GetItemTierAS takes item temp_i returns integer as
    local   integer     tier        = GetItemTier(temp_i)
    local   integer     regindex    = GetItemRegIndex(temp_i)
    local   integer     as          = LoadInteger( ItemData[regindex] , 4 , tier )
    return as
endfunction

function GetItemTierMS takes item temp_i returns integer ms
    local   integer     tier        = GetItemTier(temp_i)
    local   integer     regindex    = GetItemRegIndex(temp_i)
    local   integer     ms          = LoadInteger( ItemData[regindex] , 5 , tier )
    return ms
endfunction

function GetItemTierStrength takes item temp_i returns integer str
    local   integer     tier        = GetItemTier(temp_i)
    local   integer     regindex    = GetItemRegIndex(temp_i)
    local   integer     str         = LoadInteger( ItemData[regindex] , 6 , tier )
    return str
endfunction

function GetItemTierAgility takes item temp_i returns integer agi
    local   integer     tier        = GetItemTier(temp_i)
    local   integer     regindex    = GetItemRegIndex(temp_i)
    local   integer     agi         = LoadInteger( ItemData[regindex] , 7 , tier )
    return agi
endfunction

function GetItemTierIntel takes item temp_i returns integer intel
    local   integer     tier        = GetItemTier(temp_i)
    local   integer     regindex    = GetItemRegIndex(temp_i)
    local   integer     intel       = LoadInteger( ItemData[regindex] , 8 , tier )
    return intel
endfunction

//========================================================================//
//=====================GET ITEM REGISTRY VALUE============================//
//========================================================================//

function GetItemOccupyingSlot takes item temp_i returns integer slot
    local integer slot = 1
    set slot = ItemRegSlot[GetItemRegIndex(temp_i)]
    return slot
endfunction

function GetItemTypeEx takes item temp_i returns string itype
    local string itype
    set itype = ItemRegType[GetItemRegIndex(temp_i)]
    return itype
endfunction

function GetItemAnimationTag takes item temp_i returns string anitag
    local string anitag
    set anitag = ItemRegAnimationTag[GetItemRegIndex(temp_i)]
    return anitag
endfunction

function GetItemAttachPoint takes item temp_i returns string attpoint
    local string attpoint
    set attpoint = ItemRegAttachPoint[GetItemRegIndex(temp_i)]
    return attpoint
endfunction

function GetItemModel takes item temp_i returns string model
    local string model
    set model = ItemRegModel[GetItemRegIndex(temp_i)]
    return model
endfunction

function GetItemIcon takes item temp_i returns string icon
    local string icon
    set icon = ItemRegIcon[GetItemRegIndex(temp_i)]
    return icon
endfunction

//=====================================================================================//
//Parameters: rawcode, name, cost, dmg, def, AS, MS, Strength, Agility, Intelligence   //
//Ex Parameters: rawcode, HP, HP reg, MP, MP reg, precision, crit, bash                //
//=====================================================================================//
function ItemStatRegistry takes string rawid, string name, integer cost, integer dmg, integer def, integer as, integer ms, integer str, integer agi, integer intel returns nothing
    local   integer       index               = GetItemRegIndexEx(rawid)
    
    set ItemTierMax[index] = ItemTierMax[index] + 1
    call SaveStr( ItemData[index] , 0 , ItemTierMax[index] , name )
    call SaveInteger( ItemData[index] , 1 , ItemTierMax[index] , cost )
    call SaveInteger( ItemData[index] , 2 , ItemTierMax[index] , dmg )
    call SaveInteger( ItemData[index] , 3 , ItemTierMax[index] , def )
    call SaveInteger( ItemData[index] , 4 , ItemTierMax[index] , as )
    call SaveInteger( ItemData[index] , 5 , ItemTierMax[index] , ms )
    call SaveInteger( ItemData[index] , 6 , ItemTierMax[index] , str )
    call SaveInteger( ItemData[index] , 7 , ItemTierMax[index] , agi )
    call SaveInteger( ItemData[index] , 8 , ItemTierMax[index] , intel )
    
endfunction

function ItemStatRegistryEx takes string rawid, integer HP, real HPreg, integer MP, real MPreg, real precision, real crit, real bash returns nothing
endfunction
//===========================================================================//
//Parameters: rawcode, slot, type, animation tag, attach point, model, icon  //
//===========================================================================//
function ItemRegistry takes string rawid, integer slot, string itype, string anitag, string attpoint ,string model, string icon returns nothing
    local integer   index       = 0
    local boolean   hadindex    = false
    
    loop
        exitwhen (index > ItemRegMax or hadindex == true)
        if ItemRegRawId[index] == rawid then
            set ItemRegSlot[index]              = slot
            set ItemRegType[index]              = itype
            set ItemRegAnimationTag[index]      = anitag
            set ItemRegAttachPoint[index]       = attpoint
            set ItemRegModel[index]             = model
            set ItemRegIcon[index]              = icon
            set hadindex = true
        endif
        set index = index + 1
    endloop

    if hadindex == false then
        set ItemRegMax      =   ItemRegMax + 1
        set index           =   ItemRegMax
        set ItemRegRawId[index]             = rawid
        set ItemRegSlot[index]              = slot
        set ItemRegType[index]              = itype
        set ItemRegAnimationTag[index]      = anitag
        set ItemRegAttachPoint[index]       = attpoint
        set ItemRegModel[index]             = model
        set ItemRegIcon[index]              = icon
        set ItemData[index] = InitHashtable()
    endif
endfunction

endlibrary


And when I use it, some problems turn out
  • Acquires Item
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Cinematic - Clear the screen of text messages for (All players)
      • Set Temp_Item = (Item being manipulated)
      • Set Temp_Model = (GetItemModel( udg_Temp_Item ))
      • Special Effect - Create a special effect attached to the (GetItemAttachPoint( udg_Temp_Item )) of (Triggering unit) using Temp_Model
      • Set Hero_Weapon[(Player number of (Owner of (Triggering unit)))] = (Last created special effect)
      • Set Hero_CurAniTag[(Player number of (Owner of (Triggering unit)))] = (GetItemAnimationTag( udg_Temp_Item ))
      • Custom script: call AddUnitAnimationProperties( GetTriggerUnit() , udg_Hero_CurAniTag[ GetConvertedPlayerId( GetOwningPlayer( GetTriggerUnit() ) ) ] , true)
      • Set Multiboard_String[0] = (GetItemTierName( udg_Temp_Item ))
      • Game - Display to (All players) for 30.00 seconds the text: Multiboard_String[0]
      • Set Multiboard_String[1] = (String((GetItemTierCost( udg_Temp_Item ))))
      • Game - Display to (All players) for 30.00 seconds the text: (Cost: + Multiboard_String[1])
      • Game - Display to (All players) for 30.00 seconds the text: (Damage: + (String((GetItemTierDamage( udg_Temp_Item )))))
      • Game - Display to (All players) for 30.00 seconds the text: (Armor: + (String((GetItemTierArmor( udg_Temp_Item )))))
      • Game - Display to (All players) for 30.00 seconds the text: (Attack Rate: + (String((GetItemTierAS( udg_Temp_Item )))))
      • Game - Display to (All players) for 30.00 seconds the text: (Move Speed: + (String((GetItemTierMS( udg_Temp_Item )))))
      • Game - Display to (All players) for 30.00 seconds the text: (Strength: + (String((GetItemTierStrength( udg_Temp_Item )))))
      • Game - Display to (All players) for 30.00 seconds the text: (Agility: + (String((GetItemTierAgility( udg_Temp_Item )))))
      • -------- =================== ERROR ==================== --------
      • -------- Can't get the intel value --------
      • Game - Display to (All players) for 30.00 seconds the text: (Intelligence: + (String((GetItemTierIntel( udg_Temp_Item )))))
      • -------- =============================================== --------
  • Item Registry
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Custom script: call ItemRegistry( "I000" , 2 , "Weapon" , "channel" ,"hand, right", "RedDawn.mdx" , "none")
      • Custom script: call ItemRegistry( "I001" , 2 , "Weapon" , "flesh" ,"hand, right", "StaffOfNegation.mdx" , "none")
      • Custom script: call ItemRegistry( "I002" , 1 , "Shield" , "defend" ,"hand, right", "Orc Shield(Rigth).mdx" , "none")
      • Custom script: call ItemRegistry( "A0BC" , 1 , "Weapon" , "alternate" ,"hand, left", "ClawLeft.mdx" , "none")
      • Custom script: call ItemStatRegistry( "I000" , "|cff8e8f8eUsed Red Dawn|r" , 1600, 17 , 0 , -10 , 0 , 0 , 0, 0)
      • Custom script: call ItemStatRegistry( "I000" , "Red Dawn" , 2000, 20 , 0 , 0 , 0 , 0 , 0, 0)
      • Custom script: call ItemStatRegistry( "I000" , "|cffff0202Enhanced Red Dawn|r" , 2600, 23 , 0 , 5 , 0 , 2, 0, 0)
      • Custom script: call ItemStatRegistry( "I000" , "|cff04ff00Superior Red Dawn|r" , 3200, 26 , 0 , 7 , 0 , 4 , 0, 0)
      • Custom script: call ItemStatRegistry( "I001" , "Staff of Negation" , 1600, 6 , 0 , 0 , 0 , 0 , 0, 3)
      • Custom script: call ItemStatRegistry( "I001" , "|cff8e8f8eUsed Staff of Negation|r" , 1300, 4 , 0 , 0 , 0 , 0 , 0, 2)
      • Custom script: call ItemStatRegistry( "I002" , "Wooden Shield" , 900, 0 , 4 , 0 , 0 , 0 , 0, 0)
      • Custom script: call ItemStatRegistry( "I002" , "|cff8e8f8eUsed Wooden Shield|r" , 700, 0 , 3 , 0 , 0 , 0 , 0, 0)
      • Custom script: call ItemStatRegistry( "A0BC" , "Claw of Attack" , 1500, 12 , 0 , 0 , 0 , 0 , 0, 0)
      • Custom script: call ItemStatRegistry( "A0BC" , "|cff8e8f8eUsed Claw of Attack|r" , 1300, 10 , 0 , 0 , 0 , 0 , 0, 0)
  • Multiboard
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 1, do (Actions)
        • Loop - Actions
          • Multiboard - Create a multiboard with 4 columns and 1 rows, titled Item Information
          • Set Multiboard[(Integer A)] = (Last created multiboard)
          • Multiboard - Hide (Last created multiboard)
      • Set Multiboard_Label[1] = |cff3ca9d0Damage:|r
      • Set Multiboard_Label[2] = |cff3ca9d0Defense:|r
      • Set Multiboard_Label[3] = |cff3ca9d0Attack Rate:|r
      • Set Multiboard_Label[4] = |cff3ca9d0Move Speed:|r
      • Set Multiboard_Label[5] = |cff3ca9d0Strength:|r
      • Set Multiboard_Label[6] = |cff3ca9d0Agility:|r
      • Set Multiboard_Label[7] = |cff3ca9d0Intelligence:|r
  • Show Info
    • Events
      • Unit - A unit Uses an item
    • Conditions
    • Actions
      • Set Temp_Item = (Item being manipulated)
      • Set Temp_Integer = (Player number of (Owner of (Triggering unit)))
      • Multiboard - Show Multiboard[Temp_Integer]
      • Multiboard - Maximize Multiboard[Temp_Integer]
      • Set Multiboard_Row = 5
      • Set Multiboard_String[0] = (GetItemTierName( udg_Temp_Item ))
      • Set Multiboard_String[1] = (String((GetItemTierCost( udg_Temp_Item ))))
      • Set Multiboard_String[2] = (String((GetItemTierDamage( udg_Temp_Item ))))
      • Set Multiboard_String[3] = (String((GetItemTierArmor( udg_Temp_Item ))))
      • Set Multiboard_String[4] = (String((GetItemTierAS( udg_Temp_Item ))))
      • Set Multiboard_String[5] = (String((GetItemTierMS( udg_Temp_Item ))))
      • Set Multiboard_String[6] = (String((GetItemTierStrength( udg_Temp_Item ))))
      • Set Multiboard_String[7] = (String((GetItemTierAgility( udg_Temp_Item ))))
      • Set Multiboard_String[8] = (String((GetItemTierIntel( udg_Temp_Item ))))
      • For each (Integer A) from 2 to 8, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Multiboard_String[(Integer A)] Not equal to 0
              • Multiboard_String[(Integer A)] Not equal to Empty String
            • Then - Actions
              • Set Multiboard_Row = (Multiboard_Row + 1)
              • Set Multiboard_Caption[Multiboard_Row] = Multiboard_Label[((Integer A) - 1)]
              • Set Multiboard_Value[Multiboard_Row] = Multiboard_String[(Integer A)]
            • Else - Actions
      • Multiboard - Change the number of rows for Multiboard[Temp_Integer] to (Multiboard_Row + 1)
      • For each (Integer Multiboard_Loop) from 1 to (Multiboard_Row + 1), do (Actions)
        • Loop - Actions
          • Multiboard - Set the display style for Multiboard[Temp_Integer] item in column 1, row Multiboard_Loop to Hide text and Hide icons
          • Multiboard - Set the display style for Multiboard[Temp_Integer] item in column 2, row Multiboard_Loop to Show text and Hide icons
          • Multiboard - Set the display style for Multiboard[Temp_Integer] item in column 3, row Multiboard_Loop to Show text and Hide icons
          • Multiboard - Set the display style for Multiboard[Temp_Integer] item in column 4, row Multiboard_Loop to Hide text and Hide icons
          • Multiboard - Set the width for Multiboard[Temp_Integer] item in column 1, row Multiboard_Loop to 3.00% of the total screen width
          • Multiboard - Set the width for Multiboard[Temp_Integer] item in column 2, row Multiboard_Loop to 8.00% of the total screen width
          • Multiboard - Set the width for Multiboard[Temp_Integer] item in column 3, row Multiboard_Loop to 8.00% of the total screen width
          • Multiboard - Set the width for Multiboard[Temp_Integer] item in column 4, row Multiboard_Loop to 1.00% of the total screen width
          • -------- =================== ERROR ==================== --------
          • -------- This loop can't loop more than 7 times. --------
          • Game - Display to (All players) the text: (String(Multiboard_Loop))
          • -------- I used Display Text to check it, and the max value returned is 7, though Multiboard_Row sometime gets value up to 9. --------
          • -------- =============================================== --------
      • Multiboard - Set the display style for Multiboard[Temp_Integer] item in column 2, row 5 to Hide text and Hide icons
      • Multiboard - Set the display style for Multiboard[Temp_Integer] item in column 3, row 5 to Hide text and Hide icons
      • Multiboard - Set the display style for Multiboard[Temp_Integer] item in column 2, row (Multiboard_Row + 1) to Hide text and Hide icons
      • Multiboard - Set the display style for Multiboard[Temp_Integer] item in column 3, row (Multiboard_Row + 1) to Hide text and Hide icons
      • Multiboard - Set the width for Multiboard[Temp_Integer] item in column 2, row 2 to 16.00% of the total screen width
      • Multiboard - Set the width for Multiboard[Temp_Integer] item in column 3, row 2 to 0.00% of the total screen width
      • Multiboard - Set the text for Multiboard[Temp_Integer] item in column 2, row 2 to Multiboard_String[0]
      • Multiboard - Set the text for Multiboard[Temp_Integer] item in column 2, row 3 to |cffffcc00Type:|r
      • -------- =================== ERROR ==================== --------
      • -------- If turn this action on, all remaining actions will be skipped --------
      • Multiboard - Set the text for Multiboard[Temp_Integer] item in column 3, row 3 to (GetItemTypeEx( udg_Temp_Item ))
      • -------- =============================================== --------
      • Multiboard - Set the text for Multiboard[Temp_Integer] item in column 2, row 4 to |cffffcc00Cost:|r
      • Multiboard - Set the text for Multiboard[Temp_Integer] item in column 3, row 4 to Multiboard_String[1]
      • -------- =================== ERROR ==================== --------
      • -------- Remaining actions are skipped no matter what. --------
      • -------- =============================================== --------
      • For each (Integer Multiboard_Loop) from 6 to Multiboard_Row, do (Actions)
        • Loop - Actions
          • Game - Display to (All players) the text: (String(Multiboard_Loop))
          • Multiboard - Set the text for Multiboard[Temp_Integer] item in column 2, row Multiboard_Loop to Multiboard_Caption[Multiboard_Loop]
          • Multiboard - Set the text for Multiboard[Temp_Integer] item in column 3, row Multiboard_Loop to Multiboard_Value[Multiboard_Loop]
All errors which I detected are marked by comments. Hope someone can help me.
 
Last edited:
Status
Not open for further replies.
Top