• 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] Unique Random

Status
Not open for further replies.
Level 10
Joined
Jun 21, 2007
Messages
643
I can't seem to get a trigger to work, the idea is that it generates 'start' locations, just an interger reference, for 10 players that all have to be unique, however I can't seem to work out how the loop would go to make sure each variable is unique and regenerate it if it wasn't.

The best way to describe it is as a grid where each player must start on a random square, but no 2 players can start on the same square.

Normally I would do this via a For loop and labels:

#label 1
curr_start = random(1, 100)
For Each i = 1 to 10
if curr_start[1] == existing_start
goto label 1
end if
next i

However, I have no idea how to put that into either JASS or GUI or even if its possible. I would have thought it could be put into GUI any help would be appreciated.

MadCD:infl_thumbs_up:
 
Level 9
Joined
May 27, 2006
Messages
498
You can`t replace the start locations by triggers, but you can create units at the place you wan`t to be the 'start location' when the game starts.

To make the trigger below work, use the object editor to create a dummy unit (flying unit without model, shadow, with 'locust' ability). Place the dummy on your map there where you want the "start location" to be. Then just choose this unit-type instead of 'StartLocationDummyUnit', and the trigger should work properly.

Variables:
TempPoint - point variable - used to store the position of dummy unit, so it can be removed and don`t cause leaks.

  • StartLocation
    • Events:
      • Map initialization
    • Conditions:
    • Actions:
      • For each (Integer A) from 1 to 10 do (Actions)
        • Unit Group - Pick every unit in (Random 1 units from (Units of type StartLocationDummyUnit)) and do (Actions)
          • Loop - Actions
            • Set TempPoint = (Position of (Picked unit))
            • Unit - Remove (Picked unit) from the game
            • Unit - Create 1 (Keep, Peasant, whatever you want) for (Player((Integer A))) at TempPoint facing (Default building facing degrees)
            • Camera - Pan camera for (Player((Integer A))) to TempPoint over 0.00 seconds.
            • Custom script: call RemoveLocation(udg_TempPoint)
 
Level 10
Joined
Jun 21, 2007
Messages
643
Wrong Track..

Sorry raft but you went off on completely the wrong track...

I'm not interested in generating units, its generating 10 unqiue random numbers that I can't seem to do in wc3. Even beyond that or refine it its simply checking whether 10 numbers are unique and regenerating them until they are.

Although thank you for the swift response.
 
Level 9
Joined
May 27, 2006
Messages
498
Well, i don`t think its possible to mark an integer as 'unique' or 'already used', to prevent from repeating them - you can do this with units by adding them to groups, but there are no 'integer groups' in GUI or Jass... But you can do it like that:
  • Actions:
    • Set Integer[1] = (Random integer number between 1 and 100)
    • Set Integer[2] = (Random integer number between 1 and 100)
    • If (Integer[2] equal to Integer[1] then do Set Integer[2] = (Integer[1] / 2) [or subtract or add or multiply] else (Do nothing))
    • Set Integer[3] = (Random integer number between 1 and 100)
    • If/Then/Else - Multiple functions
      • If - Conditions
        • Or - Any condition is true
          • Integer[3] equal to Integer[1]
          • Integer[3] equal to Integer[2]
      • Then - Actions
        • Set Integer[3] = ((Integer[1] + Integer[2]) / 4 )
      • Else - Actions
    • Set Integer[4] = (Random integer number between 1 and 100)
    • If/Then/Else - Multiple functions
    • ...
And so on.
 
Status
Not open for further replies.
Top