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

Inventory not working properly

Status
Not open for further replies.
Level 5
Joined
Sep 27, 2011
Messages
141
I am making an Item system for one of my maps that includes a custom inventory when i pick up the first item it runs smoothly but when i pick up the second item it fulls up the rest of the slots and full slots or not the system completely ignores the third item can someone help please.
I suspect it has something to do with this trigger.
  • Add to Inventory
    • Events
    • Conditions
    • Actions
      • Set Player_Number = (Player number of Item_Owner[Item_Current_Index])
      • Set Temp_Int = 0
      • Custom script: loop
      • Set Temp_Int = (Temp_Int + 1)
      • Set Inventory_Occupied = (Load 0 of Temp_Int from Inventory_Hash[Player_Number])
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Inventory_Occupied Equal to True
        • Then - Actions
          • Set full = True
        • Else - Actions
          • Set full = False
          • Set Inventory_Occupied = True
          • Set Inventory_Index = Item_Current_Index
          • Set tempLoc1 = (Center of Inventory_Region[Temp_Int])
          • Destructible - Create a Item_Destructables[(Item level of Indexed_Item)] at tempLoc1 facing 360.00 with scale 1.52 and variation 0
          • Set Inventory_Destructable = (Last created destructible)
          • Custom script: call RemoveLocation(udg_tempLoc1)
          • Hashtable - Save Inventory_Occupied as 0 of Temp_Int in Inventory_Hash[Player_Number]
          • Hashtable - Save Inventory_Index as 1 of Temp_Int in Inventory_Hash[Player_Number]
          • Hashtable - Save Handle OfInventory_Destructable as 2 of Temp_Int in Inventory_Hash[Player_Number]
          • Set tempLoc1 = (Random point in Item Region <gen>)
          • Item - Move Indexed_Item to tempLoc1
          • Custom script: call RemoveLocation(udg_tempLoc1)
          • Set Temp_Int = 18
      • Custom script: exitwhen(udg_Temp_Int==18)
      • Custom script: endloop
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • full Equal to True
        • Then - Actions
          • Set tempLoc1 = (Position of TempUnit)
          • Item - Move Indexed_Item to tempLoc1
          • Custom script: call RemoveLocation(udg_tempLoc1)
          • Set SPG = (Player group(Item_Owner[Item_Current_Index]))
          • Game - Display to SPG for 5.00 seconds the text: Inventory is full.
          • Custom script: call DestroyForce(udg_SPG)
        • Else - Actions
Here is the rest of what may be needed.
  • Item Indexer
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set Indexed_Item = (Item being manipulated)
      • Set TempUnit = (Hero manipulating item)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Custom value of Indexed_Item) Equal to 0
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Recycle_Index Equal to 0
            • Then - Actions
              • Set Item_Current_Index = Item_Recycle_Number[Item_Recycle_Index]
              • Set Item_Recycle_Index = (Item_Recycle_Index - 1)
            • Else - Actions
              • Set Item_Index = (Item_Index + 1)
              • Set Item_Current_Index = Item_Index
          • Item - Set the custom value of Indexed_Item to Item_Current_Index
          • Set Item_Owner[Item_Current_Index] = (Owner of (Hero manipulating item))
          • Set Item_Level[Item_Current_Index] = (Random integer number between ((Hero level of (Hero manipulating item)) - 3) and ((Hero level of (Hero manipulating item)) + 3))
          • If (Item_Level[Item_Current_Index] Less than 1) then do (Set Item_Level[Item_Current_Index] = 1) else do (Do nothing)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item level of Indexed_Item) Greater than or equal to 0
              • (Item level of Indexed_Item) Less than or equal to 50
            • Then - Actions
              • Set Item_Class[Item_Current_Index] = weapon
              • Set Item_Damage[Item_Current_Index] = ((Integer((Power((Real(Item_Level[Item_Current_Index])), 2.00)))) + ((Integer((Power((Real(Item_Level[Item_Current_Index])), 1.96)))) + 10))
              • Set Temp_Int = 1
            • Else - Actions
          • Trigger - Run Set Item Stats <gen> (checking conditions)
        • Else - Actions
          • Set Item_Current_Index = (Custom value of Indexed_Item)
          • Set Item_Owner[Item_Current_Index] = (Owner of (Hero manipulating item))
          • Trigger - Run Add to Inventory <gen> (checking conditions)
  • Tracking
    • Events
    • Conditions
    • Actions
      • Custom script: local trackable tr = GetTriggeringTrackable()
      • Custom script: set udg_Integer = GetHandleId(tr)
      • Set Inventory_Slot = (Load 1 of Integer from Track_Table)
      • Set Player = (Load 0 of Integer in Track_Table)
      • Set Player_Number = (Player number of Player)
      • Set Inventory_Index = (Load 1 of Inventory_Slot from Inventory_Hash[Player_Number])
      • Set Inventory_Occupied = (Load 0 of Temp_Int from Inventory_Hash[Player_Number])
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Inventory_Occupied Equal to True
        • Then - Actions
          • Set Temp_Int = 0
          • -------- check number of different stats --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Damage[Inventory_Index] Greater than 0
            • Then - Actions
              • Set Temp_Int = (Temp_Int + 1)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Ability_Power[Inventory_Index] Greater than 0
            • Then - Actions
              • Set Temp_Int = (Temp_Int + 1)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Agility[Inventory_Index] Greater than 0
            • Then - Actions
              • Set Temp_Int = (Temp_Int + 1)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Crit_Damage[Inventory_Index] Greater than 0
            • Then - Actions
              • Set Temp_Int = (Temp_Int + 1)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Intelligence[Inventory_Index] Greater than 0
            • Then - Actions
              • Set Temp_Int = (Temp_Int + 1)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Strength[Inventory_Index] Greater than 0
            • Then - Actions
              • Set Temp_Int = (Temp_Int + 1)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Attack_Cooldown[Inventory_Index] Greater than 0.00
            • Then - Actions
              • Set Temp_Int = (Temp_Int + 1)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Crit_Chance[Inventory_Index] Greater than 0.00
            • Then - Actions
              • Set Temp_Int = (Temp_Int + 1)
            • Else - Actions
          • Multiboard - Change the number of rows for Inventory_MultiBoard[Player_Number] to (Temp_Int + 3)
          • Multiboard - Change the title of Inventory_MultiBoard[Player_Number] to Item_Name[Inventory_Index]
          • For each (Integer Temp_Int2) from 2 to (Temp_Int + 1), do (Actions)
            • Loop - Actions
              • Multiboard - Set the width for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to 10.00% of the total screen width
              • Multiboard - Set the width for Inventory_MultiBoard[Player_Number] item in column 2, row Temp_Int2 to 5.00% of the total screen width
              • Multiboard - Set the width for Inventory_MultiBoard[Player_Number] item in column 3, row Temp_Int2 to 5.00% of the total screen width
              • Multiboard - Set the display style for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to Show text and Show icons
              • Multiboard - Set the display style for Inventory_MultiBoard[Player_Number] item in column 2, row Temp_Int2 to Show text and Hide icons
              • Multiboard - Set the display style for Inventory_MultiBoard[Player_Number] item in column 3, row Temp_Int2 to Show text and Hide icons
          • Set Temp_Int2 = 2
          • -------- set stat text --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Damage[Inventory_Index] Greater than 0
            • Then - Actions
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to Damage
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 2, row Temp_Int2 to (String(Item_Damage[Inventory_Index]))
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 3, row Temp_Int2 to (String(Player_Damage[Player_Number]))
              • Multiboard - Set the icon for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to ReplaceableTextures\CommandButtons\BTNAttack.blp
              • Set Temp_Int2 = (Temp_Int2 + 1)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Attack_Cooldown[Inventory_Index] Greater than 0.00
            • Then - Actions
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to Attack Cooldown
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 2, row Temp_Int2 to (String(Item_Attack_Cooldown[Inventory_Index]))
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 3, row Temp_Int2 to (String(Player_AC[Inventory_Index]))
              • Multiboard - Set the icon for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to ReplaceableTextures\CommandButtons\BTNGlove.blp
              • Set Temp_Int2 = (Temp_Int2 + 1)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Strength[Inventory_Index] Greater than 0
            • Then - Actions
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to Strength
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 2, row Temp_Int2 to (String(Item_Strength[Inventory_Index]))
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 3, row Temp_Int2 to (String(Player_Str[Player_Number]))
              • Multiboard - Set the icon for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to UI\Widgets\Console\Human\human-attribute-str.blp
              • Set Temp_Int2 = (Temp_Int2 + 1)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Agility[Inventory_Index] Greater than 0
            • Then - Actions
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to Agility
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 2, row Temp_Int2 to (String(Item_Agility[Inventory_Index]))
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 3, row Temp_Int2 to (String(Player_Agi[Player_Number]))
              • Multiboard - Set the icon for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to UI\Widgets\Console\Human\human-attribute-agi.blp
              • Set Temp_Int2 = (Temp_Int2 + 1)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Intelligence[Inventory_Index] Greater than 0
            • Then - Actions
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to Intelligence
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 2, row Temp_Int2 to (String(Item_Intelligence[Inventory_Index]))
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 3, row Temp_Int2 to (String(Player_Int[Player_Number]))
              • Multiboard - Set the icon for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to UI\Widgets\Console\Human\human-attribute-int.blp
              • Set Temp_Int2 = (Temp_Int2 + 1)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Crit_Chance[Inventory_Index] Greater than 0.00
            • Then - Actions
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to Critical hit chance
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 2, row Temp_Int2 to (String(Item_Crit_Chance[Inventory_Index]))
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 3, row Temp_Int2 to (String(Player_Crit_Chance[Inventory_Index]))
              • Multiboard - Set the icon for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to ReplaceableTextures\CommandButtons\BTNCriticalStrike.blp
              • Set Temp_Int2 = (Temp_Int2 + 1)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Crit_Damage[Inventory_Index] Greater than 0
            • Then - Actions
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to Critical hit damage
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 2, row Temp_Int2 to (String(Item_Crit_Damage[Inventory_Index]))
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 3, row Temp_Int2 to (String(Player_Crit_Dmg[Player_Number]))
              • Multiboard - Set the icon for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to ReplaceableTextures\CommandButtons\BTNCriticalStrike.blp
              • Set Temp_Int2 = (Temp_Int2 + 1)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Ability_Power[Inventory_Index] Greater than 0
            • Then - Actions
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to Ability Power
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 2, row Temp_Int2 to (String(Item_Ability_Power[Inventory_Index]))
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 3, row Temp_Int2 to (String(Player_Ability_Power[Player_Number]))
              • Multiboard - Set the icon for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to ReplaceableTextures\CommandButtons\BTNBrilliance.blp
              • Set Temp_Int2 = (Temp_Int2 + 1)
            • Else - Actions
          • -------- other stuff --------
          • Set Temp_Int2 = (Temp_Int + 2)
          • Multiboard - Set the display style for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to Show text and Hide icons
          • Multiboard - Set the display style for Inventory_MultiBoard[Player_Number] item in column 2, row Temp_Int2 to Show text and Hide icons
          • Multiboard - Set the display style for Inventory_MultiBoard[Player_Number] item in column 3, row Temp_Int2 to Show text and Hide icons
          • Multiboard - Set the width for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to 10.00% of the total screen width
          • Multiboard - Set the width for Inventory_MultiBoard[Player_Number] item in column 2, row Temp_Int2 to 5.00% of the total screen width
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Class[Inventory_Index] Equal to weapon
            • Then - Actions
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to ((String(Item_Hands[Inventory_Index])) + handed weapon)
            • Else - Actions
              • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to Item_Class[Inventory_Index]
          • Set Temp_Int2 = (Temp_Int + 3)
          • Multiboard - Set the display style for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to Show text and Hide icons
          • Multiboard - Set the display style for Inventory_MultiBoard[Player_Number] item in column 2, row Temp_Int2 to Show text and Hide icons
          • Multiboard - Set the display style for Inventory_MultiBoard[Player_Number] item in column 3, row Temp_Int2 to Show text and Hide icons
          • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to Item Level:
          • Multiboard - Set the text for Inventory_MultiBoard[Player_Number] item in column 2, row Temp_Int2 to (String(Item_Level[Inventory_Index]))
          • Multiboard - Set the width for Inventory_MultiBoard[Player_Number] item in column 1, row Temp_Int2 to 10.00% of the total screen width
          • Multiboard - Set the width for Inventory_MultiBoard[Player_Number] item in column 2, row Temp_Int2 to 5.00% of the total screen width
        • Else - Actions
      • Custom script: set tr = null
Thanks in advance for any help
 
Level 5
Joined
Sep 27, 2011
Messages
141
It loops from 1 to 18 where Temp_Int is the inventory slot checking if the slot is full each time if the slot it full it sets it to full and saves it using the hashtable under the Temp_Int Temp_int is then set to 18 to end the loop i have also tried to use skip remaining actions which doesnt work either, From debug msgs i found that the Temp_Int values are correct and that the trigger does not run at all for the third item picked up no matter which order they are selected in. Other information saved to the table is the index of the picked up item so stats can be read however i believe that is irrelivent to the problem. Although all slots are shown to be full after picking up the second item but not the first the first works fine the inventory full msg is not displayed and the item is not moved. The items all have no index before being picked up so are assigned one even if they did the trigger should still work. I really cant see whats wrong, I can upload the map so far if that would help.
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
Hello. After some debugging, I seem to have figured out what was wrong with your code. You have an infinite loop here since well, when number_of_Stats is greater than 0, Temp_Int2 will never be able to be equal to it, thus leading to an infinite loop situation.

  • -------- Setting Item Stats --------
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Number_Of_Stats Greater than 0
    • Then - Actions
      • Set Temp_Int2 = 0
      • Set Temp_Int2 = (Temp_Int2 + 1)
      • Set Temp_Int = (Random integer number between 1 and Max_Stats)
      • Custom script: loop
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Int Equal to 1
        • Then - Actions
          • Game - Display to (All players) for 5.00 seconds the text: 6
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • Item_Class[Item_Current_Index] Equal to weapon
            • Then - Actions
              • Set Item_Attack_Cooldown[Item_Current_Index] = (Item_Attack_Cooldown[Item_Current_Index] - 0.05)
            • Else - Actions
              • Set Temp_Int2 = (Temp_Int2 - 1)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Int Equal to 2
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • Item_Class[Item_Current_Index] Equal to weapon
            • Then - Actions
              • Set Item_Ability_Power[Item_Current_Index] = (Item_Ability_Power[Item_Current_Index] + ((Random integer number between (Item_Level[Item_Current_Index] / 2) and Item_Level[Item_Current_Index]) + 5))
            • Else - Actions
              • Set Temp_Int2 = (Temp_Int2 - 1)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Int Equal to 3
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • Item_Class[Item_Current_Index] Equal to weapon
            • Then - Actions
              • Set Item_Crit_Chance[Item_Current_Index] = (Item_Crit_Chance[Item_Current_Index] + (Random real number between 0.50 and 1.50))
            • Else - Actions
              • Set Temp_Int2 = (Temp_Int2 - 1)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Int Equal to 4
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • Item_Class[Item_Current_Index] Equal to weapon
            • Then - Actions
              • Set Item_Crit_Damage[Item_Current_Index] = (Item_Crit_Damage[Item_Current_Index] + (Random integer number between 5 and 15))
            • Else - Actions
              • Set Temp_Int2 = (Temp_Int2 - 1)
        • Else - Actions
      • Custom script: exitwhen(udg_Temp_Int2==udg_Number_Of_Stats)
      • Custom script: endloop
      • Game - Display to (All players) for 5.00 seconds the text: 5
    • Else - Actions
      • Game - Display to (All players) for 5.00 seconds the text: 10
I think I will leave it to you to figure out how to fix it yourself since you will know your code better than me.

I have also attached the map with debug messages for you to witness the infinite loop.
 

Attachments

  • RPG.w3x
    590.7 KB · Views: 43
Status
Not open for further replies.
Top