Unique Random Unit - Possible?

Status
Not open for further replies.
Level 5
Joined
May 24, 2009
Messages
55
I would like to achieve this:
If an indexed unit-type has been created before, I don't want another unit of the same unit-type to be created again.
So that each unit-type will be spawned only once, a randomly rotated indexed unit-types.


I'm currently using something like this.
I've indexed a list of unit types from 1-7:
  • Set Unit-Type[1] = Footman Boss
  • Set Unit-Type[2] = Knight Boss
  • Set Unit-Type[3] = Rifleman Boss
  • Set Unit-Type[4] = Paladin Boss
  • Set Unit-Type[5] = Peon Boss
  • Set Unit-Type[6] = Worker Boss
  • Set Unit-Type[7] = Grunt Boss
Then I would like to create one unit with it's unit-type equal to one of the indexed unit-type number at random:
  • Unit - Create 1 Unit-Type[(Random integer number between 1 and 7)] for Player 12 (Brown) at (Position) facing (Degrees).
This is trigger is repeated at the end of every round to create a boss unit.

I've peeked at Ryoko's Dota-Template random hero system, but I fail to understand the triggers and it's variables. Any kind of help/solution/documentation links on this matter will be greatly appreciated.
 
Last edited:
Level 5
Joined
May 24, 2009
Messages
55
Thank you for the very quick response, I'm very amazed on how keen you are at giving
me your help, thank you again. Although you did give me a great idea on how to randomly
change the appearance of a unit, the Unit-Type is still very important for me, as those
indexed units are Boss units, and many triggers are tied to them. I'll fix my 1st post as to
emphasize on unit-type.

Nevertheless, thank you cookies4you for your precious attention, it is appreciated :)

edit: Alright, trying this instant Pharaoh, thanks for the quick reply!
edit2: I've used your method Pharaoh however, now trigger only spawned a random unit once the whole game.
 
Last edited:
Level 5
Joined
May 24, 2009
Messages
55
Thank you Hemlock, that's true, and Thank you Pharaoh, from your trigger I made something like this:

  • Events
    • Time - Every 1.00 seconds of game time
  • Conditions
    • Boss_Unit Equal to No unit
  • Actions
    • Set Chance = (Random Integer from 1 to 7)
    • Unit - Create 1 Unit-Type[Chance] at X for Player 1 (Red) facing default building degrees
    • Set Unit-Type[Chance] = Null
    • Set Boss_Unit = Last Created Unit
    • If (All Conditions are True) Then do (Then Actions) Else do (Else Actions)
      • If - Conditions
        • Boss_Unit Not Equal to No Unit
      • Then - Actions
        • Trigger - Turn of (This trigger)
      • Else - Actions
        • Do nothing
Might work just fine, so thank you again Pharaoh I was too quick to pass out judgement there my apologies, good thing Hemlock pointed this out to me.
 
Level 9
Joined
Nov 28, 2008
Messages
704
You should set up array of booleans. Beforehand, pick the variable and check if the boolean for that index is "true". If it is, pick again. Else, set the boolean to true and use that number.

You may need to use the custom script exitwhen true inside a huge For Integer A loop. If you need to know where or else expand on this idea, just ask :D.

Alternatively, I made a cJass script yesterday for something like this.. but if you're in GUI there is no way it's going to help you :p.

Oh, and another method would be to set up the array of ID's like you've been doing, and then create an integer Count variable equal to the highest index.

You then randomly pick a number between 1 and this Count variable. Use it, and then after, set the Id[Picked Number] = Id[Count], then reduce count by 1.
 
Level 12
Joined
Mar 10, 2008
Messages
869
Thank you Hemlock, that's true, and Thank you Pharaoh, from your trigger I made something like this:

  • Events
    • Time - Every 1.00 seconds of game time
  • Conditions
    • Boss_Unit Equal to No unit
  • Actions
    • Set Chance = (Random Integer from 1 to 7)
    • Unit - Create 1 Unit-Type[Chance] at X for Player 1 (Red) facing default building degrees
    • Set Unit-Type[Chance] = Null
    • Set Boss_Unit = Last Created Unit
    • If (All Conditions are True) Then do (Then Actions) Else do (Else Actions)
      • If - Conditions
        • Boss_Unit Not Equal to No Unit
      • Then - Actions
        • Trigger - Turn of (This trigger)
      • Else - Actions
        • Do nothing
Might work just fine, so thank you again Pharaoh I was too quick to pass out judgement there my apologies, good thing Hemlock pointed this out to me.

Don't use Do nothing, because then you will save 12.8% processing time.
 
Status
Not open for further replies.
Top