Bad Boy JH
2010-10-02 03:40:52
I am creating a Clan Wars - FreeForAll Auto Fighter, what it does is go into the fight area, and starts fighting the lowest level player, thats not in a fight, and is on screen, Rinse and Repeat.
This little snippet of code should sort players by there level, from lowest level to highest, and for equal levels it should use the closest player.
Edit: also could someone confirm what Interacting (as in TPlayer means), All i need to know is if it is 0 when not interacting (ie not fighting) and not 0 when fighting.
This little snippet of code should sort players by there level, from lowest level to highest, and for equal levels it should use the closest player.
Function SortPlayersLevel(Players: TPlayerArray): TPlayerArray;
var
i, j, k: Integer;
MyPos: TTile;
begin
MyPos := GetMyPos;
For i := 0 to High(Players) do
begin
For j := 0 to High(Result) do
if (Players[i].Level < Result[j].Level) or ((Players[i].Level < Result[j].Level) and (Distance(MyPos.x, MyPos.y, Players[i].Tile.x, Players[i].Tile.y) <= Distance(MyPos.x, MyPos.y, Result[i].Tile.x, Result[j].Tile.y))) then
begin
SetLength(Result, Length(Result) + 1);
For K := High(Result) downto j do
Result[K] := Result[K - 1];
Result[J] := Players[i]
end;
end;
end; Edit: also could someone confirm what Interacting (as in TPlayer means), All i need to know is if it is 0 when not interacting (ie not fighting) and not 0 when fighting.