Firstly a group means a collection of soldiers, one with a flag. If you split a group you get 2 groups. A group will always have one guy with a flag, and every guy with a flag in the game belongs to a different group.
A GroupID in script is a pointer or handle which lets you access a single group (only one). It lets you tell the game which group you are referring to.
Army1 = Cavalry1 + Sword1: No, that will just give you an invalid ID in the Army1 variable. A group ID only stores 1 group.
"And what would happen if I give every group the same ID and use that ID later on?" - You can't give a group an ID. The engine assigns each group an ID when they are created and that ID never changes, unless the group gets linked into another one or all the soldiers in the group die (either way that group is considered dead because it has no members left).
Imagine you are the game engine, every time a group is created you hand the group a piece of paper with a number written on it (first group gets 1, second group gets 2, etc.). That number uniquely identifies the group, and you tell the script what the ID is if the group was created using Actions.GiveGroup. So when the script tells you "group 5 move to 57,23" you can find the group with ID 5, and tell them to move. That's all a group ID is, it makes it possible for the script and the game to identify a specific group.
If you want to store a collection of groups you can use an array to store every group's ID, which I'll show you in my example below.
"There are no real attack scripts" - I plan to add a function named something like "PlayerGetClosest###" (groups/houses/units). Then you can do your attack like this:
- Code:
var AIArmy: array of Integer;
procedure OnMissionStart;
begin
SetLength(AIArmy, 4); //Allocate space to store 4 items (groups in this case)
AIArmy[0] := Actions.GiveGroup(...); //Could also use GroupAt if you'd prefer to create the groups in the .DAT
AIArmy[1] := Actions.GiveGroup(...);
AIArmy[2] := Actions.GiveGroup(...);
AIArmy[3] := Actions.GiveGroup(...);
end;
procedure OnTick;
var TargetUnit: Integer; I: Integer;
begin
//AI gets reinforcements after 1 minute
if States.GameTime = 600 then
begin
SetLength(AIArmy, Length(AIArmy)+2); //Allocate space to store 2 extra items
//The last item in the array will be Length(AIArmy)-1, and the second last item -2
//these are the extra 2 spaces we added, in this case 4 and 5 because the array length is now 6 and before it was 4
AIArmy[Length(AIArmy)-2] := Actions.GiveGroup(...);
AIArmy[Length(AIArmy)-1] := Actions.GiveGroup(...);
end;
//Player's closest unit is attacked after 10 minutes
if States.GameTime = 6000 then
begin
TargetUnit := States.GetClosestUnit(0, 20, 30); //Player 0's closest unit to 20, 30
if TargetUnit <> -1 then //All the player's units might be dead
for I:=0 to Length(AIArmy)-1 do
if not States.GroupDead(AIArmy[I]) then
Actions.GroupOrderAttackUnit(AIArmy[I], TargetUnit);
end;
end;
Note that using a dynamic (resizable) array as a global variable won't work in r5116, but it will work in the next RC.
You don't have to use the array if you don't want to, I was just showing what's possible. You could also do something like:
AIGroup1 := Actions.GiveGroup(...);
AIGroup2 := Actions.GiveGroup(...);
AIGroup3 := Actions.GiveGroup(...);
and
Actions.GroupOrderAttackUnit(AIGroup1, TargetUnit);
Actions.GroupOrderAttackUnit(AIGroup2, TargetUnit);
Actions.GroupOrderAttackUnit(AIGroup3, TargetUnit);
Cheers,
Lewin.