PDA

View Full Version : Array variable trouble


Lingonberryjam
08-22-2005, 06:00 AM
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

Laosh'Ra
08-22-2005, 09:58 AM
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.

Lingonberryjam
08-24-2005, 07:34 AM
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...

imported_Bort
08-24-2005, 01:18 PM
you should really have a variable set up trigger, not set the variables over and over.

So a trigger like this:

Event - Map intialisation
Conditions -
Actions - Set randomhero[1]=(hero)
Set randomhero[2]=(hero)
etc etc


and then your trigger:

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

Lingonberryjam
08-24-2005, 01:54 PM
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.

Los_Tacos
08-25-2005, 12:06 AM
(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.

Lingonberryjam
08-31-2005, 07:57 PM
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?

Los_Tacos
09-01-2005, 02:55 AM
(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.

Lingonberryjam
09-01-2005, 07:00 PM
Omg, sry. Its just that i havent had time to test it yet so i just wrote to get answer on didnt know it would work. :oops:

Thanks alot anyway.

Lingonberryjam
09-01-2005, 07:54 PM
Ok i think i've got it at last