• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] Randomized Structures and Lists

Status
Not open for further replies.
Level 3
Joined
May 22, 2012
Messages
50
Randomized Structures (Solved) and Lists (Not Solved)

First part was solved! Here's how it works.
  • Mine Array
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set RandomMineArray[1] = Build Stone Mine <gen>
      • Set RandomMineArray[2] = Build Stone Mine <gen>
      • Set RandomMineArray[3] = Build Stone Mine <gen>
      • Set RandomMineArray[4] = Build Coal Mine <gen>
      • Set RandomMineArray[5] = Build Coal Mine <gen>
      • Set RandomMineArray[6] = Build Copper Mine <gen>
  • Mine Randomizer
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • Trigger - Turn off RandomMineArray[LastTriggerActivated]
      • Set LastTriggerActivated = (Random integer number between 1 and 6)
      • Trigger - Turn on RandomMineArray[LastTriggerActivated]
  • Build Stone Mine
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Constructed structure)) Equal to Mine
    • Actions
      • Wait (Random real number between 10.00 and 30.00) seconds
      • Unit - Replace (Constructed structure) with a Stone Mine using The old unit's relative life and mana
The wait actually doesn't make it not work. The wait gives you a chance to move the units out of the way... though, I suggest changing it to something like 5, or 10.
I also had to get rid of the replace action, as that removes the mine's value. Instead, remove the unit, then create the new one you want where the old one was.
I didn't include the duplicate triggers for creating the mines. They're all the same, except they each replace the Mine into a different unit. In my case, I had three different triggers, one for each new type of mine.

Hello everyone! I really love this website, and remember the help I've gotten before. Anyway, let's get to the question!

I'm creating a map (WOH!) and want to be able to make 'randomized mines'. The idea here is this: Unit constructs Mine. Wait 30-180 seconds. Replace Constructed Building with MineTypeA, MineTypeB, MineTypeC, ETC.

I basically have this already:

  • Randomized Mines
  • Events
  • Do every 3 seconds
  • Conditions
  • None
  • Actions
  • Turn off IronMineTrigger
  • Turn on StoneMineTrigger
  • Wait 1 second
  • Turn off StoneMineTrigger
  • Turn on CoalMineTrigger
  • Wait 1 second
  • Turn off CoalMineTrigger
  • Turn on IronMineTrigger
I'm not sure if that would work... and it might 'leak' or something. The idea is that whenever "IronMineTrigger" or any other is on, that it will turn a regular mine into that type as long as that one is turned on. So, if I wait five seconds after the game starts, I'll be able to get a CoalMine (AKA, it's random to everyone... except for those that know what I'm doing).

I don't know if that's the best way to do it... or if it would even work at all. So, if any of you can figure it out, THANKS!


The second issue wasn't solved.

The second trigger I need is a 'list'. I've tried using a scoreboard, but that doesn't quiet work right because the items on the list move around when the values change. The idea is that when I mine from a CoalMine and the unit returns the 'coal', that it'll increase the amount of coal I own in the list. Then, when I construct certain buildings, or use certain units, it will 'eat' at that value.

Again, thanks everyone! I come up with some really hard Triggers, and can't quiet get them to work right. I'm sorry for bugging all of you... thanks!

I forgot to mention, but I don't know how to make it so when unitA mines from CoalMine and returns the gold back to the townhall, the owner of unitA gains xResources. (In my map it's not really gold... it's stone. :3)
 
Last edited:
Level 3
Joined
May 22, 2012
Messages
50
http://www.hiveworkshop.com/forums/miscellaneous-tutorials-456/how-easily-post-triggers-163285/

Using waits is a bad idea. You can also make this random.
Create a looping trigger. Every 5 seconds.
Then randomly turn one of those triggers on.
To do this you store the triggers in a trigger array.
Then pick random number from 1 to number of triggers in array.
Then turn the old trigger off. Then turn the new trigger on using that number.

Thanks for the help! I'm not very good at making triggers.. but I managed to get the every 5 seconds and turning on the array... but, I don't know how to assign a trigger to one of those numbers.
 
Thanks for the help! I'm not very good at making triggers.. but I managed to get the every 5 seconds and turning on the array... but, I don't know how to assign a trigger to one of those numbers.

Store the separate triggers into the trigger array.

Example:
  • Set triggerArray[1] = trigger 1
  • Set triggerArray[2] = trigger 2
 
Level 3
Joined
May 22, 2012
Messages
50
Alright. I have the triggers saved into an array... but turning them on and off isn't quiet working. I tried something like this, but it's not using the array, so I don't think it is going to work.
  • Events
    • Time - Every 5.00 seconds of game time
  • Conditions
  • Actions
    • Trigger - Turn on RandomMineArray[(Random integer number between 1 and 6)]
    • For each (Integer A) from 1 to 3, do (Actions)
      • Loop - Actions
        • Trigger - Turn on StoneMine
        • Trigger - Turn off CoalMine
        • Trigger - Turn off CopperMine
    • For each (Integer A) from 4 to 5, do (Actions)
      • Loop - Actions
        • Trigger - Turn on CoalMine
        • Trigger - Turn off StoneMine
        • Trigger - Turn off CopperMine
    • For each (Integer A) from 6 to 6, do (Actions)
      • Loop - Actions
        • Trigger - Turn on CopperMine
        • Trigger - Turn off StoneMine
        • Trigger - Turn off CoalMine
 
Show the trigger used to store the triggers into the array.

You do not need an integer loop here. Also never use integer A/B. They are slower and less efficient.

First you need another integer variable. Call it LastTriggerActivated.

  • Events
    • Time - Every 5.00 seconds of game time
  • Conditions
  • Actions
    • Trigger - Turn off RandomMineArray[LastTriggerActivated]
    • Set LastTriggerActivated = (Random integer number between 1 and 6)
    • Trigger - Turn on RandomMineArray[LastTriggerActivated]
  • [/hidden]
 
Level 3
Joined
May 22, 2012
Messages
50
Oh, wow. That is a lot more efficient. It helps a lot so I don't have to do the boring "Copy-Paste. Edit. Copy-Paste. Edit." Alright! I think I have it working. I figured it out just before you replied last, but that trigger you just posted took out several actions from the trigger.

Here's all the trigger I have (Minus the Coal and Copper ones, as they're duplicates of the Stone version):
  • Mine Array
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set RandomMineArray[1] = Build Stone Mine <gen>
      • Set RandomMineArray[2] = Build Stone Mine <gen>
      • Set RandomMineArray[3] = Build Stone Mine <gen>
      • Set RandomMineArray[4] = Build Coal Mine <gen>
      • Set RandomMineArray[5] = Build Coal Mine <gen>
      • Set RandomMineArray[6] = Build Copper Mine <gen>
  • Mine Randomizer
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • Trigger - Turn off RandomMineArray[LastTriggerActivated]
      • Set LastTriggerActivated = (Random integer number between 1 and 6)
      • Trigger - Turn on RandomMineArray[LastTriggerActivated]
  • Build Stone Mine
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Constructed structure)) Equal to Mine
    • Actions
      • Wait (Random real number between 10.00 and 30.00) seconds
      • Unit - Replace (Constructed structure) with a Stone Mine using The old unit's relative life and mana
I haven't tested it yet... but it worked before I edited the Mine Randomizer to match yours (Though, it should work still as it's pretty much the same, but your's is much cleaner.)

EDIT: Okay, I tested it.. and the bad news is: It works perfectly! Aside from one thing. The replace action isn't working so well, as it's deleting the value of resources inside the mines. I had it before where it would delete the mine, then create a new one... so I might just have to go back to that.

And I do realize that after it replaces the regular mine with another type, that it kind of 'jumps' out of the way. I've had this issue before with opening and closing gates, so I guess the only way to really make it work is to teleport any units inside of it away from the mine... or leave it, and watch as mines go all over the place. xD
 
Level 3
Joined
May 22, 2012
Messages
50
Alright. Now, another quicky (I hope) question: How would I say... make it so when unitA mines from mineB, upon return give owner of unitA xResources?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
You make a unit type array representing the different mine types. When construction is finished you replace the building with a type of mine that is a random index from the mine type array. Yes it really is this simple!

Want to bias mine types? No problem, simply list them multiple times in the array and increase the maximum random bound when choosing the random index.

All this takes is 2 triggers. One for data initialization and another for the actual building randomization.
 
Level 3
Joined
May 22, 2012
Messages
50
You make a unit type array representing the different mine types. When construction is finished you replace the building with a type of mine that is a random index from the mine type array. Yes it really is this simple!

Want to bias mine types? No problem, simply list them multiple times in the array and increase the maximum random bound when choosing the random index.

All this takes is 2 triggers. One for data initialization and another for the actual building randomization.

Thanks! But, deathismyfriend already solved that issue. Now all I need to know is 1: how to make a list so I can store numbers. 2: how to I make it so when a unit mines from a specific mine, that it increases one of said number.

Again, thanks community! I seriously can't believe this many people still love WCIII as much as I do!

EDIT: I forgot to say, but I meant when the unit returns to the townhall, that's when the player should receive the extra resources.

I also want to say that I updated the OP (Is that correct on this forum?) to address that one of the issues is fixed, and to update the other one.
 
If it is just a normal mine then it is a bit of a pain. If it is a structure you made with triggers you made to do the mining then.
For a normal mine you need to check every unit and see if it is mining. Then wait till it gets to the town hall or whatever and increase that number. You would have to make this MPI or MUI and use a hashtable to store if you have several different mines that you want to increase several different numbers.
 
Level 3
Joined
May 22, 2012
Messages
50
Uh...... I have no idea what you just said. LOL! I'm really sorry, I don't know how to program, or anything like that. Can you simplify it for me? lol

As for making it not a normal mine... I'm not sure I know how to do that. I might be able to figure it out. If that's the case, then that part should be easy.
 
Status
Not open for further replies.
Top