the richest guys in the server?
#1

argg .. ok lets start .. i was wondering if u could get the richest guys in the server and return a sepcific function on them .. now i dont know how to do it .. can anyone tell me how ?
well i ust did this ... lol i dont know how to make it that those guys are the richest .. anyway
Код:
for(new i = 0; i < MAX_PLAYERS; i++)
		if(IsPlayerConnected(i))
		{
			if(GetPlayerMoney(i) > ?????????????????)
		}
Reply
#2

.. what about 5 richest guys in the server ?
Reply
#3

what ever the value i cash is
Reply
#4

Here is something better.

pawn Код:
forward GetRichestPlayer();
public GetRichestPlayer()
{
    new Maxed = 0;
    new Player = 0;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(GetPlayerMoney(i) > Maxed) { Maxed = GetPlayerMoney(i); }
        }
    }
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(GetPlayerMoney(i) == Maxed) { Player = i; }
        }
    }
    return Player;
}
also this can help if want get any other max value from all players
Reply
#5

pawn Код:
stock GetRichestPlayer()
{
    new maxc,maxpid,tcs;

    for(new a=0; a<MAX_PLAYERS; a++)
    {
        if(!IsPlayerConnected(a)) continue;
        tcs = GetPlayerMoney(a);
        if(tsc > maxc)
        {
            maxpid = a;
            maxc = tsc;
        }
    }
    return maxpid;
}
1 loop > 2 loops.
Reply
#6

Quote:
Originally Posted by nemesis-
Посмотреть сообщение
pawn Код:
stock GetRichestPlayer()
{
    new maxc,maxpid,tcs;

    for(new a=0; a<MAX_PLAYERS; a++)
    {
        if(!IsPlayerConnected(a)) continue;
        tcs = GetPlayerMoney(a);
        if(tsc > maxc)
        {
            maxpid = a;
            maxc = tsc;
        }
    }
    return maxpid;
}
1 loop > 2 loops.
Why so many variables?

pawn Код:
stock GetRichestPlayer()
{
    new richestplayer = INVALID_PLAYER_ID;

    for(new playerid; playerid < MAX_PLAYERS; playerid++)
    {
        if(IsPlayerConnected(playerid))
        {
            if(richestplayer != INVALID_PLAYER_ID)
            {
                if(GetPlayerMoney(richestplayer) < GetPlayerMoney(playerid))
                {
                    richestplayer = playerid;
                }
            }
            else
            {
                richestplayer = playerid;
            }
        }
    }

    return richestplayer;
}
Reply
#7

@Finn,
Quote:

if(richestplayer != INVALID_PLAYER_ID)

?

Код:
new richest = INVALID_PLAYER_ID, data[2];
foreach(Player,i)
{
     data[0] = GetPlayerMoney(i);
     if(data[0] && data[0] > data[1]) richest = i;
}
This would do the job.
Reply
#8

Quote:
Originally Posted by Sergei
Посмотреть сообщение
@Finn
It checks if the variable richestplayer is set to INVALID_PLAYER_ID or not.

My code can be done via foreach aswell, didn't know the OP is using it;

pawn Код:
stock GetRichestPlayer()
{
    new richestplayer = INVALID_PLAYER_ID;

    foreach(Player, playerid)
    {
        if(richestplayer != INVALID_PLAYER_ID)
        {
            if(GetPlayerMoney(richestplayer) < GetPlayerMoney(playerid))
            {
                richestplayer = playerid;
            }
        }
        else
        {
            richestplayer = playerid;
        }
    }

    return richestplayer;
}

//Or as you guys seem to like shorter code:
stock GetRichestPlayer()
{
    new r = INVALID_PLAYER_ID;
    foreach(Player, i)
    {
        if(r == INVALID_PLAYER_ID || GetPlayerMoney(r) < GetPlayerMoney(i))
        {
            r = i;
        }
    }
    return r;
}
Reply
#9

Quote:
Originally Posted by Sergei
Посмотреть сообщение
@Finn,

?

Код:
new richest = INVALID_PLAYER_ID, data[2];
foreach(Player,i)
{
     data[0] = GetPlayerMoney(i);
     if(data[0] && data[0] > data[1]) richest = i;
}
This would do the job.
Yours doesn't even work. You aren't assigning data[1]. Your use of the array for data[] is also slower than individual variables.

The OP can't even code this function and you expect him to add in foreach?

Quote:
Originally Posted by Finn
Посмотреть сообщение
Why so many variables?

pawn Код:
stock GetRichestPlayer()
{
    new richestplayer = INVALID_PLAYER_ID;

    for(new playerid; playerid < MAX_PLAYERS; playerid++)
    {
        if(IsPlayerConnected(playerid))
        {
            if(richestplayer != INVALID_PLAYER_ID)
            {
                if(GetPlayerMoney(richestplayer) < GetPlayerMoney(playerid))
                {
                    richestplayer = playerid;
                }
            }
            else
            {
                richestplayer = playerid;
            }
        }
    }

    return richestplayer;
}
3 embedded ifs and 2 calls to GetPlayerMoney? Mine is still far more efficient.
Reply
#10

Quote:
Originally Posted by nemesis-
Посмотреть сообщение
Yours doesn't even work. You aren't assigning data[1]. Your use of the array for data[] is also slower than individual variables.

The OP can't even code this function and you expect him to add in foreach?
Foreach is easier to use, so yeah I'm sure he will understand it earlier than for(). And there won't be any different if you use two variables or double cell array in that small loop.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)