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

Array variable trouble

Status
Not open for further replies.
Level 6
Joined
Feb 25, 2005
Messages
230
I have used arrays for a long time now, and it works perect. But now i have a problem. Im making a simple "choose random hero for player" trigger.
It works, and ive used a unit type array variable to create the random hero. But how do i make sure that the choosen hero does not get created again so 2 players gets the same hero? It's a bit of math for me to realize how to do it...

If it helps the trigger simply looks like this:

Event - A unit sells a unit

Conditions - (Unit-type of (Sold unit)) Equal to Random Hero

Actions
-------- Set variables --------
Set randomhero[1] = Hero1
Set randomhero[2] = Hero2
Set randomhero[3] = Hero3
Set randomhero[4] = Hero4
Set randomhero[5] = Hero5
Set randomhero[6] = Hero6
Set randomhero[7] = Hero7
Set randomhero[8] = Hero8
Set randomhero[9] = Hero9
Set randomhero[10] = Hero10
Set randomhero[11] = Hero11
Set randomhero[12] = Hero12
Set randomhero[13] = Hero13
Set randomhero[14] = Hero14
Set randomhero[15] = Hero15
Set randomhero[16] = Hero16
Set randomhero[17] = Hero17
Set randomhero[18] = Hero18
Set randomhero[19] = Hero19
Set randomhero[20] = Hero20
Set randomhero[21] = Hero21
Set randomhero[22] = Hero22
Set Numberofheroes = 22
-------- Give Hero --------
If (((Owner of (Sold unit)) is an ally of Player 1 (Red)) Equal to True) then do (Unit - Create 1 randomhero[(Random integer number between 1 and Numberofheroes)] for (Owner of (Sold unit)) at (Center of Southern Shop Spot <gen>) facing Default building facing degrees) else do (Do nothing)
If (((Owner of (Sold unit)) is an ally of Player 7 (Green)) Equal to True) then do (Unit - Create 1 randomhero[(Random integer number between 1 and Numberofheroes)] for (Owner of (Sold unit)) at (Center of Northern Shop Spot <gen>) facing Default building facing degrees) else do (Do nothing)
Unit - Remove (Sold unit) from the game
 
Level 6
Joined
Mar 18, 2005
Messages
153
make a boolean variable: e.g. if hero #17 is picked hero_is_picked[17]=true. if the variable was already true before: do nothing except just running the same trigger again! this will repeat the selection until the random picks a heronumber which isnt occupied already.
just 2 things u have to check:
1. make sure there are at least as much heroes as players or the game will freeze
2. dont put any effects/performance-needing actions in this trigger so theres no lag even if the trigger is executed 10 times.
 
Level 6
Joined
Feb 25, 2005
Messages
230
I dont really get it right. It's hard to understand excatly what you mean. Should i onle create a hero for 1 player in each trigger round and repeat 10 times? And should the boloean variable be an array variable? Please come up with the trigger code here instead...
 
Level 6
Joined
Aug 29, 2004
Messages
159
you should really have a variable set up trigger, not set the variables over and over.

So a trigger like this:
Code:
Event - Map intialisation
Conditions - 
Actions - Set randomhero[1]=(hero)
          Set randomhero[2]=(hero)
          etc etc

and then your trigger:
Code:
Event - A unit sells a unit
Conditions - unit-type of sold unit equal to Random Hero
Actions - set tempint[player number of owner of sold unit] = random number between 1 and x
        - If heropicked[Tempint[Playernumber of owner of sold unit]] equal to true
             then
          - run this trigger
             else
          - if owner of sold unit is an ally of player [1]
                then
             - create 1 randomhero[temptint[player number of owner of sold unit]] at centre of team1region
                else
             - create 1 randomhero[temptint[player number of owner of sold unit]] at centre of team2region 

          - remove sold unit from the game

there... that should work alright, i think, but dont complain if it doesnt

=][= Bort
 
Level 6
Joined
Feb 25, 2005
Messages
230
Thanks alot! It seems like this 1 will work, i havent tested it yet.

But if im making an allrandom mode it gets harder.I would need to compare that the player that gets a hero really is playing, "slot status playing", and make sure that the trigger only is used 10 times maximum... so the map dont freezes or crashes.

All ya good mapmakers take this as a challenge! :p Nah but please tell me how to make that one. The only differnce is that the event is string type, Blue types "-ar" as an exact match.
 
Level 7
Joined
Aug 5, 2005
Messages
218
(Part of this was copy/pasted from Bort's trigger and modified.)
Code:
Events:  Player 2 (Blue) types (-ar) as an exact match
Condtitions:
Actions:  For each integer A from 1 - 12 do:
If:   - Player (Integer A) slot status = is playing
      - Player (Integer A) controller = user
Then:   - set tempint[Integer A] = random number between 1 and x 
            - If heropicked[Tempint[Integer A]] equal to true 
             then 
              - run this trigger 
             else 
              - if owner of sold unit is an ally of player [1] 
                then 
                 - create 1 randomhero[temptint[Integer A]] at centre of team1region 
                else 
                 - create 1 randomhero[temptint[Integer A]] at centre of team2region 

              - remove sold unit from the game
Else: (nothing)
You shouldn't worry about it crashing if there are more heroes than there are players.
 
Level 6
Joined
Feb 25, 2005
Messages
230
There is a problem... :?
Its the simple thing that player 1 and 7 are creep computer players. How do i make the trigger skip those players in a smothy way?
 
Level 7
Joined
Aug 5, 2005
Messages
218
Los_Tacos said:
(Part of this was copy/pasted from Bort's trigger and modified.)
Events: Player 2 (Blue) types (-ar) as an exact match
Condtitions:
Actions: For each integer A from 1 - 12 do:
If: - Player (Integer A) slot status = is playing
- Player (Integer A) controller = user
Then: - set tempint[Integer A] = random number between 1 and x
- If heropicked[Tempint[Integer A]] equal to true
then
- run this trigger
else
- if owner of sold unit is an ally of player [1]
then
- create 1 randomhero[temptint[Integer A]] at centre of team1region
else
- create 1 randomhero[temptint[Integer A]] at centre of team2region

- remove sold unit from the game
Else: (nothing)
You shouldn't worry about it crashing if there are more heroes than there are players.
 
Status
Not open for further replies.
Top