SRL Archive - Help and Support

Check the logic in this procedure


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.

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.

Cstrike

2010-10-05 23:05:15

This idea would also be REALLY good for soul wars to keep the player in game.

Also I get lost at this part
High(Result)
//...
SetLength(Result, Length(Result) + 1);
How can you get the high of Result if it's not defined, wouldn't it return 0? Therefore it would only search from j=0 to j=0
I may be missing something