Author Topic: Function GetMostKilled(Team: Byte): Byte;  (Read 726 times)

0 Members and 1 Guest are viewing this topic.

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Function GetMostKilled(Team: Byte): Byte;
« on: May 02, 2010, 12:09:11 pm »
This function should result in the ID of the player who has the greater number of Deaths in a team.

Assuming the following score:

Kruger: 0/1 (Alpha)
Squiddy: 1/3 (Alpha)
Admiral: 41/6 (Alpha)

GetMostKilled(1) would result in Admiral's ID.

Although, I have no clue on how to do that.

Help! :(
www.soldatx.com.br - The brazilian Soldat community.

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: Function GetMostKilled(Team: Byte): Byte;
« Reply #1 on: May 02, 2010, 12:21:37 pm »
Should work, typed out of my brain, but you can only get the one with the most or lowest deaths.
If there are players with same death count the one with the higher ID will be the result.
Could be done for more positions too, but would get abit complex then..
Code: (pascal) [Select]
// Pos=1: most deaths; Pos=2: lowest deaths;
function GetMostKilled(Pos, Team: byte): byte;
var deaths: integer;
begin
  Result := 0;
  Deaths := iif(Pos=1, -1, 9000); // If we want the one with the lowest and would start at 0 deaths result would be always 0, thats why I put that
  for i := 1 to 32 do
    if (GetPlayerStat(i, 'Active') = true) and (GetPlayerStat(i, 'Team') = Team) then
      if ((GetPlayerStat(i, 'Deaths') > Deaths) and (Pos = 1)) or ((GetPlayerStat(i, 'Deaths') < Deaths) and (Pos = 2)) then begin
        Result := i;
        Deaths := GetPlayerStat(i, 'Deaths');
      end;
end;
Have fun with it ;P

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: Function GetMostKilled(Team: Byte): Byte;
« Reply #2 on: May 02, 2010, 12:25:26 pm »
Should work, typed out of my brain
[...]
Have fun with it ;P

Thanks a lot!

You forgot to "Var I: Byte" it, though :P

Thanks :D
www.soldatx.com.br - The brazilian Soldat community.