Here is how I calculate top 3 players in my 4738Z game mod:
Code
rule("Calculate top players")
{
event
{
Ongoing - Global;
}
conditions
{
Global.StartFlag == 3;
Global.FinishFlag == False;
}
actions
{
Global.Top1 = First Of(Sorted Array(All Players(All Teams), Distance Between(Current Array Element, Global.BaseFinishLocation)));
If(Entity Exists(Global.Top1) == False);
Global.Top1 = Custom String("free slot");
Global.Top2 = Custom String("free slot");
Global.Top3 = Custom String("free slot");
Else;
Global.Top2 = First Of(Sorted Array(Remove From Array(All Players(All Teams), Global.Top1), Distance Between(Current Array Element,
Global.BaseFinishLocation)));
If(Entity Exists(Global.Top2) == False);
Global.Top2 = Custom String("free slot");
Global.Top3 = Custom String("free slot");
Else;
Global.Top3 = First Of(Sorted Array(Remove From Array(Remove From Array(All Players(All Teams), Global.Top1), Global.Top2),
Distance Between(Current Array Element, Global.BaseFinishLocation)));
If(Entity Exists(Global.Top3) == False);
Global.Top3 = Custom String("free slot");
End;
End;
End;
Wait(1, Ignore Condition);
If(Entity Exists(Global.Top1) == True && Global.LastTop1 != Global.Top1);
Global.LastTop1 = Global.Top1;
Big Message(All Players(All Teams), Custom String("{0} leads the race!", Global.LastTop1));
End;
Loop If Condition Is True;
}
}
More info about me and my game mods you can find here.
Feel free to comment my ideas.