• 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.

Random Command

Status
Not open for further replies.
Level 4
Joined
Aug 22, 2008
Messages
100
I believe this will do it:
  • Random Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Hero[0] = Paladin
      • Set Hero[1] = Archmage
      • Set Hero[2] = Mountain King
  • Random
    • Events
      • Whatever event you want the player to perform
    • Conditions
    • Actions
      • Unit - Create 1 Hero[(Random integer number between 0 and AmountofHeroes)] for "Your Player" at "Your Point" facing "Whatever"
With the first trigger you store all your different hero types in an array as the guy above said. Just ad more following this pattern if you want more heroes than this.
The second trigger will then when someone does something (maybe writes -random or something) the system will select a random number between 0 and the amount of heroes you have stored (-1 actually... just use between 0 and the last number you used to store a hero) It will then create that unit for whomever you want to have it (probably "triggering player"). Hope I helped :)
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
If you want to make it so that once a hero is picked, it can't be picked again by another player, do this:

  • Untitled Trigger 046
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set untypes[1] = Archmage
      • Set untypes[2] = Mountain King
      • Set untypes[3] = Blood Mage
      • Set untypes[4] = Paladin
      • Set i1 = 4
  • Untitled Trigger 047
    • Events
      • *some event*
    • Conditions
    • Actions
      • Set i = (Random integer number between 1 and i1)
      • Unit - Create 1 untypes[i] for *player* at *somewhere* facing Default building facing degrees
      • Set untypes[i] = untypes[i1]
      • Set i1 = (i1 - 1)
 
Level 5
Joined
Jul 30, 2012
Messages
93
  • Rastgele Hero Ayar
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set rastgelehero[1] = Aldos
      • Set rastgelehero[1] = Lava
      • Set rastgelehero[1] = Paladin
      • Set rastgelehero[1] = Ertomnis
      • Set rastgelehero[1] = Spider
      • Set rastgelehero[1] = Brigand
      • Set rastgelehero[1] = Blade Master
      • Set rastgelehero[1] = Bone Orc
      • Set rastgelehero[1] = Mammoth
      • Set rastgelehero[1] = Zergling
      • Set rastgelehero[1] = Rex
      • Set rastgelehero[1] = Growy
      • Set rastgelehero[1] = Phanttasos
      • Set rastgelehero[1] = Rennder
      • Set HeroSayisi = 14
  • Random Komutu
    • Events
      • Player - Player 1 (Red) types a chat message containing -rastgele as An exact match
    • Conditions
    • Actions
      • Set integerrandom = (Random integer number between 1 and HeroSayisi)
      • Unit - Create 1 rastgelehero[integerrandom] for (Picked player) at ((Picked player) start location) facing Default building facing degrees
      • Camera - Pan camera for (Owner of (Triggering unit)) to (Position of (Last created unit)) over 0.00 seconds
      • Selection - Select (Last created unit) for (Picked player)
      • Set rastgelehero[integerrandom] = rastgelehero[HeroSayisi]
      • Set HeroSayisi = (HeroSayisi - 1)
where's wrong ???
 
Level 28
Joined
Sep 26, 2009
Messages
2,520
That's because this line
  • Unit - Create 1 rastgelehero[integerrandom] for (Picked player) at ((Picked player) start location) facing Default building facing degrees
uses (Picked player). Use (triggering player) instead (found as "event response - Triggering player").

Also all locations set in these lines
  • Unit - Create 1 rastgelehero[integerrandom] for (Picked player) at ((Picked player) start location) facing Default building facing degrees
  • Camera - Pan camera for (Owner of (Triggering unit)) to (Position of (Last created unit)) over 0.00 seconds
leak.

Look at this thread (http://www.hiveworkshop.com/forums/275043-post1.html) to learn how to remove them.

EDIT:
Made the trigger, it should look like this
  • Random Komutu
    • Events
      • Player - Player 1 (Red) types a chat message containing -rastgele as An exact match
    • Conditions
    • Actions
      • Set integerrandom = (Random integer number between 1 and HeroSayisi)
      • Set Temp_Point = ((Triggering player) start location)
      • Unit - Create 1 rastgelehero[integerrandom] for (Triggering player) at Temp_Point facing Default building facing degrees
      • Camera - Pan camera for (Triggering player) to Temp_Point over 0.00 seconds
      • Selection - Select (Last created unit) for (Triggering player)
      • Custom script: call RemoveLocation(udg_Temp_Point)
      • Custom script: set udg_Temp_Point = null
      • Set rastgelehero[integerrandom] = rastgelehero[HeroSayisi]
      • Set HeroSaysi = (HeroSayisi - 1)
The Temp_Point is a "point" variable.
Currently, your trigger will fire multiple times (up to 14 times), as long as Player1 writes the command (so he can have mutliple random heroes). There are a few additions if you want this trigger to fire only once:
SINGLE PLAYER
- If this is for singleplayer, the use
  • Trigger - Turn off (This trigger)
as the first action in that trigger


MULTI PLAYER
- If this is for multiplayer, you will need to copy
  • Player - Player 1 (Red) types a chat message containing -rastgele as An exact match
and change it for each player, lest only player 1 would be able to execute the -rastgele command.

You will also need to add boolean array (with array size equal to maximum number of players that can execute this command) and check it. In my case, I named the boolean "rastgele_used". You should use this condition and action to your trigger:
  • Random Komutu
    • Events
      • Player - Player 1 (Red) types a chat message containing -rastgele as An exact match
    • Conditions
      • rastgele_used[(Player number of (Triggering player))] Not equal to True
    • Actions
      • Set rastgele_used[(Player number of (Triggering player))] = True
      • <rest of the trigger>
What it does is it checks if triggering player already used this command once. If he did, the trigger won't even fire. If he didn't, the trigger will then fire, but also set the boolean to true, so one player won't be able to pick up multiple random heroes.
 
Last edited:
Level 5
Joined
Jul 30, 2012
Messages
93
Last form:

  • Random Komutu
    • Events
      • Player - Player 1 (Red) types a chat message containing -rastgele as An exact match
    • Conditions
    • Actions
      • Set integerrandom = (Random integer number between 1 and HeroSayisi)
      • Unit - Create 1 rastgelehero[integerrandom] for (Triggering player) at ((Triggering player) start location) facing Default building facing degrees
      • Player - Add -1 to (Triggering player) Current lumber
      • Camera - Pan camera for (Triggering player) to (Position of (Last created unit)) over 0.00 seconds
      • Selection - Select (Last created unit) for (Triggering player)
      • Set rastgelehero[integerrandom] = rastgelehero[HeroSayisi]
      • Set HeroSayisi = (HeroSayisi - 1)
Now, we can pick random hero it's okey.But the other players can randomed my hero, so we have a same hero.
And we can write -random more than 1.Then i have a 2 hero. :(
 
Level 28
Joined
Sep 26, 2009
Messages
2,520
Look at the edit I made in my previous post. It's explained there what to do to prevent multiple heroes for 1 player and also it doesn't have leaks.

Back to your post: What you tried to say is that you and your friend executed the command, but you both got the same type of hero?
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Avoid Duplicates:
  • Set rastgelehero[integerrandom] = rastgelehero[HeroSayisi]
  • Set HeroSayisi = HeroSayisi - 1
Edit: wait, you already did this. It should work, what exactly do you want? :p
Oh wait, I may understand what you want. If you do want duplicates to be allowed, you should remove these actions. endedit
Only 1 hero:
  • Conditions
    • HasHero[Player number of (triggering player)] Equal to False
  • Actions
    • Set HasHero[Player number of (triggering player)] = True
 
Level 5
Joined
Jul 30, 2012
Messages
93
I found this conditions somewhere and added it.It works well.

  • (Number of units in (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True))) Equal to 0
Now i have a last problem.The other players can chose or random hero which i randomed. :( I didn't understand how to fix with those ways so can someone do and upload to copy my map ?
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
I found this conditions somewhere and added it.It works well.

  • (Number of units in (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True))) Equal to 0
This condition leaks, though.
Only 1 hero:
  • Conditions
    • HasHero[Player number of (triggering player)] Equal to False
  • Actions
    • Set HasHero[Player number of (triggering player)] = True
If you do want to use your condition, then you need to put it inside an ITE, so you can remove the group leak.

Now i have a last problem.The other players can chose or random hero which i randomed. :( I didn't understand how to fix with those ways so can someone do and upload to copy my map ?
Yeah, sure.
Just one thing: with the triggers you showed us, players should not be able to have 2 of the same heroes.
 
Level 5
Joined
Jul 30, 2012
Messages
93
  • Random Komutu
    • Events
      • Player - Player 1 (Red) types a chat message containing -rastgele as An exact match
      • Player - Player 2 (Blue) types a chat message containing -rastgele as An exact match
      • Player - Player 3 (Teal) types a chat message containing -rastgele as An exact match
      • Player - Player 4 (Purple) types a chat message containing -rastgele as An exact match
      • Player - Player 5 (Yellow) types a chat message containing -rastgele as An exact match
      • Player - Player 6 (Orange) types a chat message containing -rastgele as An exact match
      • Player - Player 7 (Green) types a chat message containing -rastgele as An exact match
      • Player - Player 8 (Pink) types a chat message containing -rastgele as An exact match
      • Player - Player 9 (Gray) types a chat message containing -rastgele as An exact match
      • Player - Player 10 (Light Blue) types a chat message containing -rastgele as An exact match
    • Conditions
      • (Number of units in (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True))) Equal to 0
    • Actions
      • Set integerrandom = (Random integer number between 1 and HeroSayisi)
      • Unit - Create 1 rastgelehero[integerrandom] for (Triggering player) at ((Triggering player) start location) facing Default building facing degrees
      • Player - Add -1 to (Triggering player) Current lumber
      • Camera - Pan camera for (Triggering player) to (Position of (Last created unit)) over 0.00 seconds
      • Selection - Select (Last created unit) for (Triggering player)
      • Set rastgelehero[integerrandom] = rastgelehero[HeroSayisi]
      • Set HeroSayisi = (HeroSayisi - 1)
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Player - Make rastgelehero[integerrandom] Unavailable for training/construction by (Picked player)
I think still the other player can pick or random hero which i randomed.
 
Level 28
Joined
Sep 26, 2009
Messages
2,520
I posted the trigger already 2 posts back.
  • Random Komutu
    • Events
      • Player - Player 1 (Red) types a chat message containing -rastgele as An exact match
      • ....
      • Player - Player 10 (Light Blue) types a chat message containing -rastgele as An exact match
    • Conditions
      • rastgele_used[(Player number of (Triggering player))] Equal to False
    • Actions
      • Set rastgele_used[(Player number of (Triggering player))] = True
      • Player - Add -1 to (Triggering player) Current lumber
      • Set integerrandom = (Random integer number between 1 and HeroSayisi)
      • Set Temp_Point = ((Triggering player) start location)
      • Unit - Create 1 rastgelehero[integerrandom] for (Triggering player) at Temp_Point facing Default building facing degrees
      • Camera - Pan camera for (Triggering player) to Temp_Point over 0.00 seconds
      • Selection - Select (Last created unit) for (Triggering player)
      • Custom script: call RemoveLocation(udg_Temp_Point)
      • Custom script: set udg_Temp_Point = null
      • Set rastgelehero[integerrandom] = rastgelehero[HeroSayisi]
      • Set HeroSaysi = (HeroSayisi - 1)
rastgele_used is a boolean array with size 10
Temp_point is a point variable
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
  • Random Komutu
    • Events
      • Player - Player 1 (Red) types a chat message containing -rastgele as An exact match
      • Player - Player 2 (Blue) types a chat message containing -rastgele as An exact match
      • Player - Player 3 (Teal) types a chat message containing -rastgele as An exact match
      • Player - Player 4 (Purple) types a chat message containing -rastgele as An exact match
      • Player - Player 5 (Yellow) types a chat message containing -rastgele as An exact match
      • Player - Player 6 (Orange) types a chat message containing -rastgele as An exact match
      • Player - Player 7 (Green) types a chat message containing -rastgele as An exact match
      • Player - Player 8 (Pink) types a chat message containing -rastgele as An exact match
      • Player - Player 9 (Gray) types a chat message containing -rastgele as An exact match
      • Player - Player 10 (Light Blue) types a chat message containing -rastgele as An exact match
    • Conditions
      • (Number of units in (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True))) Equal to 0
    • Actions
      • Set integerrandom = (Random integer number between 1 and HeroSayisi)
      • Unit - Create 1 rastgelehero[integerrandom] for (Triggering player) at ((Triggering player) start location) facing Default building facing degrees
      • Player - Add -1 to (Triggering player) Current lumber
      • Camera - Pan camera for (Triggering player) to (Position of (Last created unit)) over 0.00 seconds
      • Selection - Select (Last created unit) for (Triggering player)
      • Set rastgelehero[integerrandom] = rastgelehero[HeroSayisi]
      • Set HeroSayisi = (HeroSayisi - 1)
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Player - Make rastgelehero[integerrandom] Unavailable for training/construction by (Picked player)
I think still the other player can pick or random hero which i randomed.
I don't think so.

Here's an example:

integerrandom = 10
Thus you randomed "Zergling" ( = rastgelehero[10]).
--> rastgelehero[integerrandom] = rastgelehero[HeroSayisi]
--> rastgelehero[10] = rastgelehero[14]
This means that rastgelehero[10] is now "Rennder".

The new random hero will be a number between 1 and 13 (the new value for HeroSayisi).
"Zergling" can never be randomed again.
 
Level 5
Joined
Jul 30, 2012
Messages
93
I don't think so.

Here's an example:

integerrandom = 10
Thus you randomed "Zergling" ( = rastgelehero[10]).
--> rastgelehero[integerrandom] = rastgelehero[HeroSayisi]
--> rastgelehero[10] = rastgelehero[14]
This means that rastgelehero[10] is now "Rennder".

The new random hero will be a number between 1 and 13 (the new value for HeroSayisi).
"Zergling" can never be randomed again.

I mean the other players mustn't chose my randomed hero. *-*

  • Random Komutu
    • Events
      • Player - Player 1 (Red) types a chat message containing -rastgele as An exact match
      • Player - Player 2 (Blue) types a chat message containing -rastgele as An exact match
      • Player - Player 3 (Teal) types a chat message containing -rastgele as An exact match
      • Player - Player 4 (Purple) types a chat message containing -rastgele as An exact match
      • Player - Player 5 (Yellow) types a chat message containing -rastgele as An exact match
      • Player - Player 6 (Orange) types a chat message containing -rastgele as An exact match
      • Player - Player 7 (Green) types a chat message containing -rastgele as An exact match
      • Player - Player 8 (Pink) types a chat message containing -rastgele as An exact match
      • Player - Player 9 (Gray) types a chat message containing -rastgele as An exact match
      • Player - Player 10 (Light Blue) types a chat message containing -rastgele as An exact match
    • Conditions
      • rastgele_used[(Player number of (Triggering player))] Equal to False
    • Actions
      • Set rastgele_used[(Player number of (Triggering player))] = True
      • Player - Add -1 to (Triggering player) Current lumber
      • Set integerrandom = (Random integer number between 1 and HeroSayisi)
      • Set Temp_Point = ((Triggering player) start location)
      • Unit - Create 1 rastgelehero[integerrandom] for (Triggering player) at Temp_Point facing Default building facing degrees
      • Camera - Pan camera for (Triggering player) to Temp_Point over 0.00 seconds
      • Selection - Select (Last created unit) for (Triggering player)
      • Custom script: call RemoveLocation(udg_Temp_Point)
      • Custom script: set udg_Temp_Point = null
      • Set rastgelehero[integerrandom] = rastgelehero[HeroSayisi]
      • Set HeroSayisi = (HeroSayisi - 1)
I did.Now the other players can chose hero from tavern or random same hero or not ?
 
Level 28
Joined
Sep 26, 2009
Messages
2,520
This trigger enables all players (1 to 10) to choose random hero you specified in the first trigger (rastgelehero[1]-[14]) through the -rastgele command, but prevents any type of hero to be selected again and prevents players from using the -rastgele command more than once.
 
Status
Not open for further replies.
Top