How to make a unit group array?

Status
Not open for further replies.
Level 20
Joined
Jul 14, 2011
Messages
3,213
Hi!

How can I insert into a Unit (or Unit Group) Array all the players heroes?.

Game has a maximum of 5 players, (so maximum 5 heroes, since it's an RPG), and the Hero is Sold-Free on the beginning of the game. I'm planning to use Save-load later... so, again:

How can I insert sold heroes, or Loaded heroes into a Variable?

Of course, in common triggers (GUI)
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
You mean, creating 1 Group Array, and another 5 Groups (One for each Player) and set
First Group [1] = PlayerGroup 1
First Group [2] = PlayerGroup 2
First Group [3] = PlayerGroup 3
First Group [4] = PlayerGroup 4
First Group [5] = PlayerGroup 5
¿?

Somehow, I'm sure you can't mean that xD.
Where do I find the player ID to insert it into the Unit-Group array?

----
Can't I just create a Unit-Group called "Hero" and insert all the "Hero" units in there, independent of the player/owner of the unit, or something like that?
 
get player id of player? It's a native.

GetPlayerId(player)


There is a GUI equivalent.

edit
Oh crap, I thought you meant 5 heroes per player. Scrap the groups completely, just have a unit array and set the unit[playerId]=hero



Here's a great resource on save/load
http://www.hiveworkshop.com/forums/spells-569/save-load-snippets-v1-0-0-1-a-202714/

It also includes information as to the importance for being able to access the player's hero = ).


It's like a map filled with tutorials, demonstrations, useful scripts, etc.
 
Use unit array variable. Array values should depend on player id number.

So, in your trigger with event Unit - Sells unit, use following actions:
  • Custom script: set udg_Unit[GetPlayerId(GetOwningPlayer(GetSoldUnit()))] = GetSoldUnit()
OR
  • Set Unit[(Player number of (Owner of (Sold unit)))] = (Sold unit)
You might add them into some kind of unit group - what can help you latter when refering to 'heroes' picked.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
One question. if I set that
  • Set Unit[(Player number of (Owner of (Sold unit)))] = (Sold unit)
in one Trigger, other "Sold Units" from other triggers won't be added to that variable? I mean, only Sold Units from that trigger will be added to that variable array...? (I've had that question for over a week xD)

Another one: @Spinnaker, I'm not sure if I did understand what youd said
"You might add them into some kind of unit group"
You mean another variable of type Unit-Group?... What would that be for?
 
Status
Not open for further replies.
Top