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

[Trigger] Add Random Creep to Neutral Building

Status
Not open for further replies.
Level 11
Joined
Aug 11, 2009
Messages
594
Hi!

So basically I already have a code that adds 3 random creeps to a Tavern for the player to hire. However, it can sometimes add the same creep twice or more. I need help with a trigger which somehow removes the chance of adding the same creep more than once.

Current code:
  • Tavern Creeps 1
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Countdown Timer - Start Timer_Round as a One-shot timer that will expire in 30.00 seconds
      • Countdown Timer - Create a timer window for (Last started timer) with title (Start Round + (String(Integer_Round)))
      • For each (Integer B) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set Randomizer = (Random integer number between 1 and 29)
          • Neutral Building - Add Tier1[Randomizer] to Tavern[(Integer B)] with 1 in stock and a max stock of 1
          • Set Randomizer = (Random integer number between 1 and 29)
          • Neutral Building - Add Tier1[Randomizer] to Tavern[(Integer B)] with 1 in stock and a max stock of 1
          • Set Randomizer = (Random integer number between 1 and 29)
          • Neutral Building - Add Tier1[Randomizer] to Tavern[(Integer B)] with 1 in stock and a max stock of 1
(This was just something quick i put together so havnt bothered with effective code or leaks, no need to point those out. I only need help with the above question)

Thanks for taking your time to read! :)
 
Level 21
Joined
Nov 4, 2013
Messages
2,017
I suggest you use an array Boolean of size 29. Every time you set the Randomizer to a number, you set Boolean[Randomizer] = True. By If/Then/Else you check that if Boolean[Randomizer] = True, you skip the remaining actions and re-run the trigger. You should add this function just below the setting of randomizer. In this case, the timer stuff should be put into a different trigger. Oh right, in the loop actions, use only once this:

  • Set Randomizer = (Random integer number between 1 and 29)
  • Neutral Building - Add Tier1[Randomizer] to Tavern[(Integer B)] with 1 in stock and a max stock of 1
 
Level 11
Joined
Aug 11, 2009
Messages
594
Thanks I'll give it a try!

The loop 1 to 6 is for 6 different players and then the triggers you linked are for the 3 creeps to choose from for each player :)
 
Status
Not open for further replies.
Top