Dynamic Script Share Thread
I have decide to share my current and future scripts with the community. I have used a common name for the thread so all people can share scripts here.
GetGroups
Return all Group IDs from any player.
Parameter:
PlayerID (Integer) = The player you want to get all groups from.
SizeX (Word) = Map Size X.
SizeY (Word) = Map Size Y.
Since we can't access the map data while run-time, my function needs the size to know the size of your map.
Code:
- Code:
Function ElementExist(Integers: Array Of Integer; Element: Integer) : Boolean; Var I: Integer; Begin Result := False; For I := 0 To High(Integers) Do Begin If (Integers[I] = Element) Then Begin Result := True; Exit; End; End; End; Function GetGroups(PlayerID: Integer; SizeX, SizeY: Word) : Array Of Integer; Var X, Y: Byte; GroupID: Integer; Begin For X := 0 To SizeX Do Begin For Y := 0 To SizeY Do Begin GroupID := States.GroupAt(X, Y); If (GroupID <> -1) Then Begin If (States.GroupOwner(GroupID) = PlayerID) Then Begin If (ElementExist(Result, GroupID)) Then Begin Continue; End; SetLength(Result, Length(Result) + 1); Result[High(Result)] := GroupID; End; End; End; End; End;
- Code:
Procedure OnMissionStart(); Var Groups: Array Of Integer; I: Integer; Begin // Get all group IDs from player 2 and save it in the local array Groups. Groups := GetGroups(2, 144, 144); // Loop through all groups and order them to attack. Here the players house at 59, 131 will be attacked. For I := 0 to High(Groups) Do Begin Actions.GroupOrderAttackHouse(Groups[I], States.HouseAt(59, 131)); End; End;
Usage + Call it every second:
- Code:
Procedure OnTick(); Var Groups: Array Of Integer; I: Integer; Begin If (States.GameTime mod 10 = 0) Then Begin // Get all group IDs from player 2 and save it in the local array Groups. Groups := GetGroups(2, 144, 144); // Loop through all groups and order them to attack. Here the players house at 59, 131 will be attacked. For I := 0 to High(Groups) Do Begin Actions.GroupOrderAttackHouse(Groups[I], States.HouseAt(59, 131)); End; End; End;