SA-MP Forums Archive
The player with the money - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: The player with the money (/showthread.php?tid=389782)



The player with the money - Ludek - 03.11.2012

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)


Re: The player with the money - Glad2BeHere - 03.11.2012

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;
}



Re: The player with the money - Ludek - 03.11.2012

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


Re: The player with the money - Abhishek. - 03.11.2012

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


Re: The player with the money - Backwardsman97 - 03.11.2012

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.


Re: The player with the money - Abhishek. - 03.11.2012

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


Re: The player with the money - Ludek - 11.11.2012

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);
}}



Re: The player with the money - Konstantinos - 11.11.2012

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;
}



Re: The player with the money - Ludek - 11.11.2012

Thank you


Re: The player with the money - Abhishek. - 11.11.2012

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