• 🏆 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] Switch inventory pages using arrow keys

Status
Not open for further replies.
Level 28
Joined
Feb 18, 2014
Messages
3,579
I want to give my hero 3 inventory pages and the ability to switch between them using the left/right arrow key. Let's say I press the right arrow key, all the items I have on my current inventory (let's call it inventory 1) will be stored and removed. So now I have an empty/new inventory (let's call it inventory 2)

If I press the left arrow key, all the items I currently have on inventory 2 will be stored and removed and all the items I had on inventory 1 will be restored.

So my question is how can I do that?
 
Level 5
Joined
Oct 16, 2007
Messages
67
I made an exampel on how to do it. It might not be a good way but it is a way. :grin:
This would allow 1 unit per Player to use the system. A good other way would be a hashtable, then multiple units per player could use the system. You could also use unit Indexing but for this example I went with Playernumber.
I hope I didn't make any maths errors.
 

Attachments

  • Inventory Test.w3m
    20.5 KB · Views: 87
Level 28
Joined
Feb 18, 2014
Messages
3,579
I made an exampel on how to do it. It might not be a good way but it is a way. :grin:
This would allow 1 unit per Player to use the system. A good other way would be a hashtable, then multiple units per player could use the system. You could also use unit Indexing but for this example I went with Playernumber.
I hope I didn't make any maths errors.
I can't open the map, I suppose it was made with the latest patch? Can you post the triggers instead?
Inventory v2.1a 's Bag library could be modified to work with arrow keys.
I'm not familiar with JASS sadly. The system looks very complicated :/
 
Level 5
Joined
Oct 16, 2007
Messages
67
Variables:
Inv_ItemPoint - Point
Inv_Page - Integer Array
Inv_PageLimit - Integer with start value = 2 (Amount of pages you want-1)
Inv_Items - Item Array

Hero - Unit array (unit for the inventory, only 1 per player)
tmpItem - Item (for easy acces to a item)

Trigger
  • Inv Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet Hero[1] = Paladin 0001 <gen>
      • Set VariableSet Inv_ItemPoint = (Center of (Playable map area))
      • Camera - Lock camera target for Player 1 (Red) to Paladin 0001 <gen>, offset by (0.00, 0.00) using Default rotation
  • Inv Left
    • Events
      • Player - Player 1 (Red) Presses the Left Arrow key
      • Player - Player 2 (Blue) Presses the Left Arrow key
    • Conditions
      • Inv_Page[(Player number of (Triggering player))] Greater than 0
    • Actions
      • Trigger - Run Inv Save <gen> (ignoring conditions)
      • Set VariableSet Inv_Page[(Player number of (Owner of (Triggering unit)))] = (Inv_Page[(Player number of (Owner of (Triggering unit)))] - 1)
      • Trigger - Run Inv Load <gen> (ignoring conditions)
  • Inv Right
    • Events
      • Player - Player 1 (Red) Presses the Right Arrow key
      • Player - Player 2 (Blue) Presses the Right Arrow key
    • Conditions
      • Inv_Page[(Player number of (Triggering player))] Less than Inv_PageLimit
    • Actions
      • Trigger - Run Inv Save <gen> (ignoring conditions)
      • Set VariableSet Inv_Page[(Player number of (Owner of (Triggering unit)))] = (Inv_Page[(Player number of (Owner of (Triggering unit)))] + 1)
      • Trigger - Run Inv Load <gen> (ignoring conditions)
  • Inv Save
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set VariableSet tmpItem = (Item carried by Hero[(Player number of (Triggering player))] in slot (Integer A))
          • Set VariableSet Inv_Items[(((Inv_Page[(Player number of (Triggering player))] x 6) + (Integer A)) + (((Inv_PageLimit + 1) x 6) x ((Player number of (Triggering player)) - 1)))] = tmpItem
          • Item - Move tmpItem to Inv_ItemPoint
          • Item - Hide tmpItem
  • Inv Load
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set VariableSet tmpItem = Inv_Items[((Integer A) + ((Inv_Page[(Player number of (Triggering player))] x 6) + (((Inv_PageLimit + 1) x 6) x ((Player number of (Triggering player)) - 1))))]
          • Item - Show tmpItem
          • Hero - Give tmpItem to Hero[(Player number of (Triggering player))]
To add more players just add the key event to left and right. You also should check if the unit is alive.
 
Level 28
Joined
Feb 18, 2014
Messages
3,579
Variables:
Inv_ItemPoint - Point
Inv_Page - Integer Array
Inv_PageLimit - Integer with start value = 2 (Amount of pages you want-1)
Inv_Items - Item Array

Hero - Unit array (unit for the inventory, only 1 per player)
tmpItem - Item (for easy acces to a item)

Trigger
  • Inv Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet Hero[1] = Paladin 0001 <gen>
      • Set VariableSet Inv_ItemPoint = (Center of (Playable map area))
      • Camera - Lock camera target for Player 1 (Red) to Paladin 0001 <gen>, offset by (0.00, 0.00) using Default rotation
  • Inv Left
    • Events
      • Player - Player 1 (Red) Presses the Left Arrow key
      • Player - Player 2 (Blue) Presses the Left Arrow key
    • Conditions
      • Inv_Page[(Player number of (Triggering player))] Greater than 0
    • Actions
      • Trigger - Run Inv Save <gen> (ignoring conditions)
      • Set VariableSet Inv_Page[(Player number of (Owner of (Triggering unit)))] = (Inv_Page[(Player number of (Owner of (Triggering unit)))] - 1)
      • Trigger - Run Inv Load <gen> (ignoring conditions)
  • Inv Right
    • Events
      • Player - Player 1 (Red) Presses the Right Arrow key
      • Player - Player 2 (Blue) Presses the Right Arrow key
    • Conditions
      • Inv_Page[(Player number of (Triggering player))] Less than Inv_PageLimit
    • Actions
      • Trigger - Run Inv Save <gen> (ignoring conditions)
      • Set VariableSet Inv_Page[(Player number of (Owner of (Triggering unit)))] = (Inv_Page[(Player number of (Owner of (Triggering unit)))] + 1)
      • Trigger - Run Inv Load <gen> (ignoring conditions)
  • Inv Save
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set VariableSet tmpItem = (Item carried by Hero[(Player number of (Triggering player))] in slot (Integer A))
          • Set VariableSet Inv_Items[(((Inv_Page[(Player number of (Triggering player))] x 6) + (Integer A)) + (((Inv_PageLimit + 1) x 6) x ((Player number of (Triggering player)) - 1)))] = tmpItem
          • Item - Move tmpItem to Inv_ItemPoint
          • Item - Hide tmpItem
  • Inv Load
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set VariableSet tmpItem = Inv_Items[((Integer A) + ((Inv_Page[(Player number of (Triggering player))] x 6) + (((Inv_PageLimit + 1) x 6) x ((Player number of (Triggering player)) - 1))))]
          • Item - Show tmpItem
          • Hero - Give tmpItem to Hero[(Player number of (Triggering player))]
To add more players just add the key event to left and right. You also should check if the unit is alive.
Worked like a charm! Thank you so much :D

What do you mean by "check if the unit is alive"? Will it cause a problem if the hero dies?
 
Level 5
Joined
Oct 16, 2007
Messages
67
Worked like a charm! Thank you so much :D

What do you mean by "check if the unit is alive"? Will it cause a problem if the hero dies?

It would mess with your page and unhides the items. You can just add the unit is alive condition to "Inv Left" and "Inv Right".
 
Status
Not open for further replies.
Top