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

Trying to make an item drafting shop

Level 2
Joined
Mar 20, 2024
Messages
9
I'm making a sort of CO-OP card game style map and am trying to make a shop that has a random 5 items (cards) in it from a subset of items (factions), and then when a player buys an item from it, it removes the item from the shop. I want this shop to have a refresh button that will remove all current items in the shop and replace them with 5 new items from that same original subset.

(im sorry I am not familiar with how to import my triggers into this box)

Currently I have a region on the map where the items are pulled from. Triggers add items to this region to create the possible items that could be put in this shop. When a player buys an item, I can get it to remove that item from the shop no problem because I can just have it remove an item of type(manipulated item) when it is bought. However, the main issue I am having, is that I am using the "Add item of item type(random item in region) to market for Unit X" to add these items into the shop. And this does not work properly with multiple adds because if this random selection chooses an item that is already in the shop, it will just not add anything. Also my refresh button, for some reason, I cant get it to remove more than one item from the shop at a time, and some times it wont remove anything. (Ive tried using the "remove item of item type (random item from region)" and "remove item of item type (random item of level X)", but this doesnt seem to work consistently and I am guessing it is because it is choosing a random item that matches that condition, THEN it checks to see if that item is in the shop before trying to remove. If the randomly selected type doesnt appear in the shop, then nothing is removed.)

For the refresh command, I need it to:
1. Remove all items currently in the shop
Then
2. Add 5 different items from the region I am using as a subgroup.

Can anyone help me out?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
Hello, so I'll start by asking, are you happy with the "Random item from Region" system? Or would you prefer something more advanced that can randomly Add items to the shop without the need of those extra steps. The first idea that comes to mind is an Array of Item-Types, which would be like a triggered List of every Item in the game. This would allow you to do something like "Create Item_Type[54]" and it'll spawn whatever the 54th Item is (you'd define this yourself). Then you could do "Create Item_Type[Random number between 1 and 100]" to create a random Item within a range.

Next question, which version of Warcraft 3 are you on? The latest patch? It's important to let people know when asking for help since the solutions vary from patch to patch, with newer versions having far more powerful tools at their disposal. Plus, you can't open maps made on a later version.

Lastly, you can click the link in my signature to learn how to post your triggers.
 
Last edited:
Level 2
Joined
Mar 20, 2024
Messages
9
Hello, so I'll start by asking, are you happy with the "Random item from Region" system? Or would you prefer something more advanced that can randomly Add items to the shop without the need of those extra steps. The first idea that comes to mind is an Array of Item-Types, which would be like a triggered List of every Item in the game. This would allow you to do something like "Create Item_Type[54]" and it'll spawn whatever the 54th Item is (you'd define this yourself).

Next question, which version of Warcraft 3 are you on? The latest patch? It's important to let people know when asking for help since the solutions vary from patch to patch, with newer versions having far more powerful tools at their disposal. Plus, you can't open maps made on a later version.

Lastly, you can click the link in my signature to learn how to post your triggers.
Thank you for the reply. Can this Array solution still be random and from a specific subset? Like if I wanted 5 random different "human" items? Is there a way, using arrays, to have a subset of items for each "faction"? Like "Human Items" "Undead Items" "Nature Items" etc etc. Long story short, I want players to unlock different "cards" when they select which faction they want to be at the beginning (which currently I am doing by adding items to the region after they select from a dialog and after they choose upgrades) that can be added to the pool of possible cards to show up in their shop when refreshing.

I am on the most recent patch, yeah.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
Thank you for the reply. Can this Array solution still be random and from a specific subset? Like if I wanted 5 random different "human" items? Is there a way, using arrays, to have a subset of items for each "faction"? Like "Human Items" "Undead Items" "Nature Items" etc etc. Long story short, I want players to unlock different "cards" when they select which faction they want to be at the beginning (which currently I am doing by adding items to the region after they select from a dialog and after they choose upgrades) that can be added to the pool of possible cards to show up in their shop when refreshing.

I am on the most recent patch, yeah.
Yeah, you can do just about anything you want with triggers. Arrays and Hashtables (a super Array) let you store near infinite amounts of data and can be categorized anyway you'd like. Here's an Array example:
  • Events
    • Map initialization
  • Conditions
  • Actions
    • -------- Define the different types of Human items... --------
    • Set Variable Human_Items[1] = Iron Sword
    • Set Variable Human_Items[2] = Buckler
    • Set Variable Human_Items[3] = Cap
    • -------- Now the Undead items... --------
    • Set Variable Undead_Items[1] = Demon Staff
    • Set Variable Undead_Items[2] = Poison Dagger
    • Set Variable Undead_Items[3] = Spiked Shield
So you'd essentially create a database of all your items.

Now if you want a random Undead_Item:
  • Set Variable Random_Number = (Random integer number between 1 and 3)
  • Item - Create 1 Undead_Items[Random_Number] at (Center of playable map area)
Or add it to the shop, I forget the exact wording since I'm writing this from memory. It's something to think about, only do it if you're actually comfortable with learning and using these more advanced techniques.
 
Last edited:
Level 2
Joined
Mar 20, 2024
Messages
9
Yeah, you can do just about anything you want with triggers. Arrays and Hashtables (a super Array) let you store near infinite amounts of data and can categorized anyway you'd like. Here's an Array example:
  • Events
    • Map initialization
  • Conditions
  • Actions
    • -------- Define the different types of Human items... --------
    • Set Variable Human_Items[1] = Iron Sword
    • Set Variable Human_Items[2] = Buckler
    • Set Variable Human_Items[3] = Cap
    • -------- Now the Undead items... --------
    • Set Variable Undead_Items[1] = Demon Staff
    • Set Variable Undead_Items[2] = Poison Dagger
    • Set Variable Undead_Items[3] = Spiked Shield
So you'd essentially create a database of all your items.

Now if you want a random Undead_Item:
  • Set Variable Random_Number = (Random integer number between 1 and 3)
  • Item - Create 1 Undead_Items[Random_Number] at...
Or add it to the shop, I forget the exact wording since I'm writing this from memory.
That sounds amazing, I def will look into hashtables and arrays then.

Only issue I have is, that random table could still run into the issue of attempting to add the same item to the shop that is already there. How can I prevent that when I go to add 5 random items?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
That sounds amazing, I def will look into hashtables and arrays then.

Only issue I have is, that random table could still run into the issue of attempting to add the same item to the shop that is already there. How can I prevent that when I go to add 5 random items?
You can use different techniques to exclude repeats from occurring. The first thought that comes to mind would be making your Random Number generation exclude numbers that have been picked already, which can be handled with some clever use of swapping Array values around and reducing the Array size to exclude values. There's plenty of threads on this topic already.

But who needs all that, here's a map that showcases a working system. I went a bit overboard and wrote some code to handle the random number generation stuff since it's much easier to do in code form. Then I sandwiched it into what should hopefully be an easy to use system that doesn't require any coding knowledge to use.

All you have to do is type "r" in-game and you'll see 5 random items appear in the shop from a set of 15. You will always get 5 new items.

Here's a short summary on how it works (about to sleep so I won't go into great detail):
  • The 1st time you use the system: It gets 5 random numbers and removes them from the possible future rolls.
  • The 2nd time you use the system: It gets 5 random numbers, tracks them, resets the possible rolls back to normal, and then removes the tracked numbers.
  • Repeat this pattern.
 

Attachments

  • Random Item System 2.w3m
    21.3 KB · Views: 3
Last edited:
Level 2
Joined
Mar 20, 2024
Messages
9
You can use different techniques to exclude repeats from occurring. The first thought that comes to mind would be making your Random Number generation exclude numbers that have been picked already, which can be handled with some clever use of swapping Array values around and reducing the Array size to exclude values. There's plenty of threads on this topic already.

But who needs all that, here's a map that showcases a working system. I went a bit overboard and wrote some code to handle the random number generation stuff since it's much easier to do in code form. Then I sandwiched it into what should hopefully be an easy to use system that doesn't require any coding knowledge to use.

All you have to do is type "r" in-game and you'll see 5 random items appear in the shop from a set of 15. You will always get 5 new items.

Here's a short summary on how it works (about to sleep so I won't go into great detail):
  • The 1st time you use the system: It gets 5 random numbers and removes them from the possible future rolls.
  • The 2nd time you use the system: It gets 5 random numbers, tracks them, resets the possible rolls back to normal, and then removes the tracked numbers.
  • Repeat this pattern.
Wow holy crap this is awesome!!! Am I able to just copy paste or import this into my map? And will it work if I just replace the "type R" event with "casts ability = reroll"? Can I also make this function only affect the shop owned by the player who casts reroll? I think what I am asking is: will the script be fine if I change the events and conditions of the Triggers surrounding it?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
Wow holy crap this is awesome!!! Am I able to just copy paste or import this into my map? And will it work if I just replace the "type R" event with "casts ability = reroll"? Can I also make this function only affect the shop owned by the player who casts reroll? I think what I am asking is: will the script be fine if I change the events and conditions of the Triggers surrounding it?
Yeah, just copy the folder and paste it into your map. Also, you can change the Events to whatever you want. You just need to make sure that you update the Event Responses if necessary. Note that this current design assumes that each Player has one personal Shop. So one Shop per Player and no Shop sharing.

Here's a quick explanation. In the map you can see these two variables being reused in two of the triggers:
  • Set VariableSet RIS_Player = (Triggering player)
  • Set VariableSet RIS_Item_Amount = 5
RIS is short for Random Item System, which tells you that these variable are meant to be used with this system and nowhere else. You'll often see naming conventions like these when using other people's systems.


In the Setup Players trigger I am using these variables to "register" a Player, which gives them their own unique "rng table" that we can use throughout the game. This only needs to happen once per Player:
  • Setup Players
    • Events
      • Time - Elapsed game time is 0.01 seconds
    • Conditions
    • Actions
      • -------- Run these actions when a Player picks a race: --------
      • Set VariableSet RIS_Player = Player 1 (Red)
      • Set VariableSet RIS_Item_Amount = Human_Item_Amount
      • Custom script: call RegisterPlayerItems( udg_RIS_Player, udg_RIS_Item_Amount )
So in your case the idea would be to run those three Actions in response to a Player picking their Race. So I assume it'd go into one or multiple of your race picking Dialog triggers. Change Player 1 (Red) to the Player that clicked the Dialog, which should be the (Triggering player).


In the Get Random Human Items trigger I am using these variables to get five (or whatever RIS_Item_Amount is set to) random numbers. These random numbers will be stored in an Array variable called RIS_Numbers which is immediately referenced to Add the matching Item-Types to the Shop:
  • Get Random Human Items
    • Events
      • Player - Player 1 (Red) types a chat message containing r as An exact match
    • Conditions
    • Actions
      • -------- Running this function will get us 5 random numbers with no repeats (also excludes our previous 5 random numbers). --------
      • -------- It fills the array RIS_Numbers with random numbers at each [index] from 1 to X: --------
      • Set VariableSet RIS_Player = (Triggering player)
      • Set VariableSet RIS_Item_Amount = 5
      • Custom script: call GetPlayerItems( udg_RIS_Player, udg_RIS_Item_Amount )
      • -------- --------
      • -------- Remove all items from the shop: --------
      • Neutral Building - Limit Goblin Merchant 0001 <gen> to 0 item slots
      • Neutral Building - Limit Goblin Merchant 0001 <gen> to 11 item slots
      • -------- --------
      • -------- Add 5 random unused items to the shop: --------
      • For each (Integer RIS_Loop) from 1 to RIS_Item_Amount, do (Actions)
        • Loop - Actions
          • -------- Add one of the new items: --------
          • Neutral Building - Add Human_Item_Type[RIS_Numbers[RIS_Loop]] to Goblin Merchant 0001 <gen> with 1 in stock and a max stock of 1
By matching Item-Types I mean the random number is used to reference an [index] from our Human_Item_Type array variable that we setup beforehand. See the Setup Human Items trigger for more information. So if the random number rolls a 3 for example, it would add the Human_Item_Type[3] to the shop, which is Inferno Stone in this case. If you wanted this to work with let's say Undead items then you would simply change Human_Item_Type to Undead_Item_Type when adding the Item to the shop.


Regarding changing it to work with an ability cast, here's one way of doing it:
  • Get Random Human Items
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Reroll Shop (Human)
    • Actions
      • -------- Running this function will get us 5 random numbers with no repeats (also excludes our previous 5 random numbers). --------
      • -------- It fills the array RIS_Numbers with random numbers at each [index] from 1 to X: --------
      • Set VariableSet RIS_Player = (Owner of (Triggering unit))
      • Set VariableSet RIS_Item_Amount = 5
      • Custom script: call GetPlayerItems( udg_RIS_Player, udg_RIS_Item_Amount )
      • -------- --------
      • -------- Remove all items from the shop: --------
      • Neutral Building - Limit (Triggering unit) to 0 item slots
      • Neutral Building - Limit (Triggering unit) to 11 item slots
      • -------- --------
      • -------- Add 5 random unused items to the shop: --------
      • For each (Integer RIS_Loop) from 1 to RIS_Item_Amount, do (Actions)
        • Loop - Actions
          • -------- Add one of the new items: --------
          • Neutral Building - Add Human_Item_Type[RIS_Numbers[RIS_Loop]] to (Triggering unit) with 1 in stock and a max stock of 1
Note how I changed the Goblin Merchant to (Triggering unit) which is an Event Response equal to the unit that cast the ability. I also set RIS_Player to (Owner of (Triggering unit)) which means it's referencing the owner of the casting unit aka the shop owner. You could use (Triggering player) here as well, I just wanted to showcase how you would adapt the trigger to work with different Events -> Not every Event can use every Event Response.
 
Last edited:
Level 2
Joined
Mar 20, 2024
Messages
9
Yeah, just copy the folder and paste it in into your map. Also, you can change the Events to whatever you want. You just need to make sure that you update the Event Responses if necessary. Note that this current design assumes that each Player has one personal Shop. So one Shop per Player and no Shop sharing.

Here's a quick explanation. In the map you can see these two variables being reused in two of the triggers:
  • Set VariableSet RIS_Player = (Triggering player)
  • Set VariableSet RIS_Item_Amount = 5
RIS is short for Random Item System, which tells you that these variable are meant to be used with this system and nowhere else. You'll often see naming conventions like these when using other people's systems.


In the Setup Players trigger I am using these variables to "register" a Player, which gives them their own unique "rng table" that we can use throughout the game. This only needs to happen once per Player:
  • Setup Players
    • Events
      • Time - Elapsed game time is 0.01 seconds
    • Conditions
    • Actions
      • -------- Run these actions when a Player picks a race: --------
      • Set VariableSet RIS_Player = Player 1 (Red)
      • Set VariableSet RIS_Item_Amount = Human_Item_Amount
      • Custom script: call RegisterPlayerItems( udg_RIS_Player, udg_RIS_Item_Amount )
So in your case the idea would be to run those three Actions in response to a Player picking their Race. So I assume it'd go into one or multiple of your race picking Dialog triggers. Change Player 1 (Red) to the Player that clicked the Dialog, which should be the (Triggering player).


In the Get Random Human Items trigger I am using these variables to get five (or whatever RIS_Item_Amount is set to) random numbers. These random numbers will be stored in an Array variable called RIS_Numbers which is immediately referenced to Add the matching Item-Types to the Shop:
  • Get Random Human Items
    • Events
      • Player - Player 1 (Red) types a chat message containing r as An exact match
    • Conditions
    • Actions
      • -------- Running this function will get us 5 random numbers with no repeats (also excludes our previous 5 random numbers). --------
      • -------- It fills the array RIS_Numbers with random numbers at each [index] from 1 to X: --------
      • Set VariableSet RIS_Player = (Triggering player)
      • Set VariableSet RIS_Item_Amount = 5
      • Custom script: call GetPlayerItems( udg_RIS_Player, udg_RIS_Item_Amount )
      • -------- --------
      • -------- Remove all items from the shop: --------
      • Neutral Building - Limit Goblin Merchant 0001 <gen> to 0 item slots
      • Neutral Building - Limit Goblin Merchant 0001 <gen> to 11 item slots
      • -------- --------
      • -------- Add 5 random unused items to the shop: --------
      • For each (Integer RIS_Loop) from 1 to RIS_Item_Amount, do (Actions)
        • Loop - Actions
          • -------- Add one of the new items: --------
          • Neutral Building - Add Human_Item_Type[RIS_Numbers[RIS_Loop]] to Goblin Merchant 0001 <gen> with 1 in stock and a max stock of 1
By matching Item-Types I mean the random number is used to reference an [index] from our Human_Item_Type array variable that we setup beforehand. See the Setup Human Items trigger for more information. So if the random number rolls a 3 for example, it would add the Human_Item_Type[3] to the shop, which is Inferno Stone in this case. If you wanted this to work with let's say Undead items then you would simply change Human_Item_Type to Undead_Item_Type when adding the Item to the shop.


Regarding changing it to work with an ability cast, here's one way of doing it:
  • Get Random Human Items
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Reroll Shop (Human)
    • Actions
      • -------- Running this function will get us 5 random numbers with no repeats (also excludes our previous 5 random numbers). --------
      • -------- It fills the array RIS_Numbers with random numbers at each [index] from 1 to X: --------
      • Set VariableSet RIS_Player = (Owner of (Triggering unit))
      • Set VariableSet RIS_Item_Amount = 5
      • Custom script: call GetPlayerItems( udg_RIS_Player, udg_RIS_Item_Amount )
      • -------- --------
      • -------- Remove all items from the shop: --------
      • Neutral Building - Limit (Triggering unit) to 0 item slots
      • Neutral Building - Limit (Triggering unit) to 11 item slots
      • -------- --------
      • -------- Add 5 random unused items to the shop: --------
      • For each (Integer RIS_Loop) from 1 to RIS_Item_Amount, do (Actions)
        • Loop - Actions
          • -------- Add one of the new items: --------
          • Neutral Building - Add Human_Item_Type[RIS_Numbers[RIS_Loop]] to (Triggering unit) with 1 in stock and a max stock of 1
Note how I changed the Goblin Merchant to (Triggering unit) which is an Event Response equal to the unit that cast the ability. I also set RIS_Player to (Owner of (Triggering unit)) which means it's referencing the owner of the casting unit aka the shop owner. You could use (Triggering player) here as well, I just wanted to showcase how you would adapt the trigger to work with different Events -> Not every Event can use every Event Response.
You are a genius. Thank you so much for putting in the time and effort for this. This is fantastic!!!
 
Level 2
Joined
Mar 20, 2024
Messages
9
Yeah, just copy the folder and paste it in into your map. Also, you can change the Events to whatever you want. You just need to make sure that you update the Event Responses if necessary. Note that this current design assumes that each Player has one personal Shop. So one Shop per Player and no Shop sharing.

Here's a quick explanation. In the map you can see these two variables being reused in two of the triggers:
  • Set VariableSet RIS_Player = (Triggering player)
  • Set VariableSet RIS_Item_Amount = 5
RIS is short for Random Item System, which tells you that these variable are meant to be used with this system and nowhere else. You'll often see naming conventions like these when using other people's systems.


In the Setup Players trigger I am using these variables to "register" a Player, which gives them their own unique "rng table" that we can use throughout the game. This only needs to happen once per Player:
  • Setup Players
    • Events
      • Time - Elapsed game time is 0.01 seconds
    • Conditions
    • Actions
      • -------- Run these actions when a Player picks a race: --------
      • Set VariableSet RIS_Player = Player 1 (Red)
      • Set VariableSet RIS_Item_Amount = Human_Item_Amount
      • Custom script: call RegisterPlayerItems( udg_RIS_Player, udg_RIS_Item_Amount )
So in your case the idea would be to run those three Actions in response to a Player picking their Race. So I assume it'd go into one or multiple of your race picking Dialog triggers. Change Player 1 (Red) to the Player that clicked the Dialog, which should be the (Triggering player).


In the Get Random Human Items trigger I am using these variables to get five (or whatever RIS_Item_Amount is set to) random numbers. These random numbers will be stored in an Array variable called RIS_Numbers which is immediately referenced to Add the matching Item-Types to the Shop:
  • Get Random Human Items
    • Events
      • Player - Player 1 (Red) types a chat message containing r as An exact match
    • Conditions
    • Actions
      • -------- Running this function will get us 5 random numbers with no repeats (also excludes our previous 5 random numbers). --------
      • -------- It fills the array RIS_Numbers with random numbers at each [index] from 1 to X: --------
      • Set VariableSet RIS_Player = (Triggering player)
      • Set VariableSet RIS_Item_Amount = 5
      • Custom script: call GetPlayerItems( udg_RIS_Player, udg_RIS_Item_Amount )
      • -------- --------
      • -------- Remove all items from the shop: --------
      • Neutral Building - Limit Goblin Merchant 0001 <gen> to 0 item slots
      • Neutral Building - Limit Goblin Merchant 0001 <gen> to 11 item slots
      • -------- --------
      • -------- Add 5 random unused items to the shop: --------
      • For each (Integer RIS_Loop) from 1 to RIS_Item_Amount, do (Actions)
        • Loop - Actions
          • -------- Add one of the new items: --------
          • Neutral Building - Add Human_Item_Type[RIS_Numbers[RIS_Loop]] to Goblin Merchant 0001 <gen> with 1 in stock and a max stock of 1
By matching Item-Types I mean the random number is used to reference an [index] from our Human_Item_Type array variable that we setup beforehand. See the Setup Human Items trigger for more information. So if the random number rolls a 3 for example, it would add the Human_Item_Type[3] to the shop, which is Inferno Stone in this case. If you wanted this to work with let's say Undead items then you would simply change Human_Item_Type to Undead_Item_Type when adding the Item to the shop.


Regarding changing it to work with an ability cast, here's one way of doing it:
  • Get Random Human Items
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Reroll Shop (Human)
    • Actions
      • -------- Running this function will get us 5 random numbers with no repeats (also excludes our previous 5 random numbers). --------
      • -------- It fills the array RIS_Numbers with random numbers at each [index] from 1 to X: --------
      • Set VariableSet RIS_Player = (Owner of (Triggering unit))
      • Set VariableSet RIS_Item_Amount = 5
      • Custom script: call GetPlayerItems( udg_RIS_Player, udg_RIS_Item_Amount )
      • -------- --------
      • -------- Remove all items from the shop: --------
      • Neutral Building - Limit (Triggering unit) to 0 item slots
      • Neutral Building - Limit (Triggering unit) to 11 item slots
      • -------- --------
      • -------- Add 5 random unused items to the shop: --------
      • For each (Integer RIS_Loop) from 1 to RIS_Item_Amount, do (Actions)
        • Loop - Actions
          • -------- Add one of the new items: --------
          • Neutral Building - Add Human_Item_Type[RIS_Numbers[RIS_Loop]] to (Triggering unit) with 1 in stock and a max stock of 1
Note how I changed the Goblin Merchant to (Triggering unit) which is an Event Response equal to the unit that cast the ability. I also set RIS_Player to (Owner of (Triggering unit)) which means it's referencing the owner of the casting unit aka the shop owner. You could use (Triggering player) here as well, I just wanted to showcase how you would adapt the trigger to work with different Events -> Not every Event can use every Event Response.
One more quick question that applies to some other game functions I am trying to build.

Is there a way to have an Integer Comparison check how many items are being sold in a shop?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
One more quick question that applies to some other game functions I am trying to build.

Is there a way to have an Integer Comparison check how many items are being sold in a shop?
I don't think there's any existing function to do so, but you can track this information yourself.

For example here's how you could achieve this with our current shop setup. I added a new Shop_Item_Count variable that tracks the number of items:
  • Get Random Human Items
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Reroll Shop (Human)
    • Actions
      • -------- Running this function will get us 5 random numbers with no repeats (also excludes our previous 5 random numbers). --------
      • -------- It fills the array RIS_Numbers with random numbers at each [index] from 1 to X: --------
      • Set VariableSet RIS_Player = (Owner of (Triggering unit))
      • Set VariableSet RIS_Item_Amount = 5
      • Custom script: call GetPlayerItems( udg_RIS_Player, udg_RIS_Item_Amount )
      • -------- --------
      • -------- [NEW] Track how many items are in this shop: --------
      • Set VariableSet Shop_Item_Count[(Custom value of (Triggering unit))] = RIS_Item_Amount
      • -------- --------
      • -------- Remove all items from the shop: --------
      • Neutral Building - Limit (Triggering unit) to 0 item slots
      • Neutral Building - Limit (Triggering unit) to 11 item slots
      • -------- --------
      • -------- Add 5 random unused items to the shop: --------
      • For each (Integer RIS_Loop) from 1 to RIS_Item_Amount, do (Actions)
        • Loop - Actions
          • -------- Add one of the new items: --------
          • Neutral Building - Add Human_Item_Type[RIS_Numbers[RIS_Loop]] to (Triggering unit) with 1 in stock and a max stock of 1
Then when you purchase an Item from a Shop, assuming that the Items always have a max stock of 1, you would update this change in count:
  • Shop Sells Item
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
      • Shop_Item_Count[(Custom value of (Triggering unit))] Greater than 0
    • Actions
      • -------- This assumes that purchased items are always removed from the shop (1 max stock): --------
      • Set VariableSet Shop_Item_Count[(Custom value of (Triggering unit))] = (Shop_Item_Count[(Custom value of (Triggering unit))] - 1)
Note that this trigger requires the use of a Unit Indexer - a powerful system for attaching any type of data to Units. This is because the trigger relies on the Custom Value of the Unit, which the system will automatically Set for you. This happens whenever a new unit is created as well as for any pre-placed units at the start of the game. In other words, the system does all of the hard work for you, all you have to do is learn how to use it which involves: Creating and understanding Array variables + using Custom Value as the [index] in said Arrays.

For a more elaborate system that takes into account varying Max Stocks you'd want to rely on a Hashtable. That's a bit too advanced to get into just yet.
 
Last edited:
Top