The player with the money
#1

Hi I would like to ask how can I do the command to detect a 1 player with the most money?

(Sorry for my ignorance of English, translated pres ****** translate)
Reply
#2

get zcmd
and sscanf2
pawn Код:
CMD:getcash(playerid, params[])
{
    new name[MAX_PLAYER_NAME+1];
    new playerb, string[128];
    GetPlayerName(playerb, name, sizeof(name));
    if(sscanf(params, "u", playerb)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /getcash [playerid]");
    format(string, sizeof(string), " Administrator %s has given you $%d",name, GetPlayerCash(playerb));
    SendClientMessage(playerb, COLOR_WHITE, string);
    return 1;
}
Reply
#3

I need to write only one player with the most the money, not how much money player
Reply
#4

pawn Код:
CMD:getplayerwithhighestcash(playerid,params[])
{
new name[MAX_PLAYER_NAME],highest,chighests,scores;
for(players=0;players<=MAX_PLAYERS;players++)
{
GetPlayerCash(players,chighests);
if(chighest>score)
{
score=players;
}
GetPlayerName(score,name,sizeof(name));
    format(string, sizeof(string), "Highest cash is with %s(%d)",name, GetPlayerCash(playerb));
    SendClientMessage(playerb, COLOR_WHITE, string);
return 1;
}
maybe this will work i dont know why i took so long
Reply
#5

pawn Код:
stock ReturnRichest()
{
    new
        tmp,
        richest = -1,
        amount;

    for(new i; i<MAX_PLAYERS; i++)
    {
        tmp = GetPlayerMoney(i);
        if(tmp > amount)
              richest = i;
    }
    return richest;
}
Try that out. The only logic error I could see would be if two players had the exact same amount of money.
Reply
#6

Quote:
Originally Posted by Backwardsman97
Посмотреть сообщение
pawn Код:
stock ReturnRichest()
{
    new
        tmp,
        richest = -1,
        amount;

    for(new i; i<MAX_PLAYERS; i++)
    {
        tmp = GetPlayerMoney(i);
        if(tmp > amount)
              richest = i;
    }
    return richest;
}
Try that out. The only logic error I could see would be if two players had the exact same amount of money.
well sir your amount will always be 0 and why i feel its some what like my logic :P
Reply
#7

I tried to do this in spite of the way but still I can not. you do not know what's wrong?

Код:
	for(new i; i < MAX_PLAYERS; i ++){
			if(GetPlayerMoney(i) > GetPlayerMoney(i)){
                        new msg[128];
		  	format(msg, sizeof(msg), "Player %s | Max money: $%d",PlayerName(i), GetPlayerMoney(i));
		   	SendClientMessageToAll(-1, msg);
}}
Reply
#8

pawn Код:
CMD:richest( playerid, params[ ] )
{
    new
        amount = 0,
        Richest[ MAX_PLAYER_NAME ],
        string[ 128 ]
    ;
    for( new x = 0; x < MAX_PLAYERS; x++ )
    {
        if( IsPlayerConnected( x ) && x != INVALID_PLAYER_ID && !IsPlayerNPC( x ) )
        {
            if( GetPlayerMoney( x ) > amount )
            {
                amount = GetPlayerMoney( x );
                GetPlayerName( x, Richest, MAX_PLAYER_NAME );
            }
        }
    }
    format( string, sizeof( string ), "The richest player is %s with $%d!", Richest, amount );
    SendClientMessage( playerid, 0xFFFF00FF, string );
    return 1;
}
Reply
#9

Thank you
Reply
#10

Quote:
Originally Posted by Ludek
Посмотреть сообщение
I tried to do this in spite of the way but still I can not. you do not know what's wrong?

Код:
	for(new i; i < MAX_PLAYERS; i ++){
			if(GetPlayerMoney(i) > GetPlayerMoney(i)){
                        new msg[128];
		  	format(msg, sizeof(msg), "Player %s | Max money: $%d",PlayerName(i), GetPlayerMoney(i));
		   	SendClientMessageToAll(-1, msg);
}}
well sir,
i would like to inform that your above codes a a bit epic fail coz you made a loop on the SendClientMessage so it will be sending message like MAX_PLAYERS times and make a object named msg[128] MAX_PLAYERS times and in your loop you just compared that the player have more cash than what he haves well it will be always falls.
sorrry if you didnt liked the way i told i was just informing you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)