Learning Sscanf
#3

Quote:
Originally Posted by mprofitt
pawn Код:
dcmd_givecash(playerid, params[])
{
    if (sscanf(params, "ud", giveplayerid, amount)) return SendClientMessage(playerid, 0xFF9900AA, "Usage: /givecash [playerid/partname] [amount]");
   
    new
        string[256],
        playername[MAX_PLAYER_NAME],
        giveplayerid,
        amount;
   
    if (giveplayerid == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF9900AA, "Player Not Found");
    else if (amount > GetPlayerMoney(playerid)) SendClientMessage(playerid, 0xFF9900AA, "You Don't Have Enough Money!");
    else if (giveplayerid == playerid) SendClientMessage(playerid,0xFF9900AA,"You Can't Give Money To Yourself!");
    else
    {
        GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
        GivePlayerMoney(giveplayerid, amount);
        GameTextForPlayer(giveplayerid,"~g~Money Recived",3000,5);
        format(string, sizeof(string), "You Recived $%d From Player %s(%d)",amount,playername,giveplayerid);
        SendClientMessage(giveplayerid,0x33CCFFAA,string);
       
        GivePlayerMoney(playerid, 0 - amount);
        GameTextForPlayer(playerid,"~y~Money Sent",3000,5);
        format(string, sizeof(string), "You Have Sent $%d To Player %s(%d)",amount,playername,playerid);
        SendClientMessage(playerid,0x33CCFFAA,string);
    }
    return 1;
}
Fail. Use this:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(givecash, 8, cmdtext);
    return 0;
}

dcmd_givecash(playerid, params[])
{
  new string[256];
  new playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
    new
        giveplayerid,
        amount;
    if (sscanf(params, "ud", giveplayerid, amount))return SendClientMessage(playerid, 0xFF9900AA, "Usage: /givecash [playerid/partname] [amount]");
    else if (giveplayerid == INVALID_PLAYER_ID)return SendClientMessage(playerid, 0xFF9900AA, "Player Not Found");
    else if (amount > GetPlayerMoney(playerid))return SendClientMessage(playerid, 0xFF9900AA, "You Don't Have Enough Money!");
    else if (giveplayerid == playerid)return SendClientMessage(playerid,0xFF9900AA,"You Can't Give Money To Yourself!");
    else
    {
        GivePlayerMoney(giveplayerid, amount);
        GameTextForPlayer(giveplayerid,"~g~Money Recived",3000,5);
        format(string, sizeof(string), "You Recived $%d From Player %s(%d)",amount,playername,giveplayerid);
        SendClientMessage(giveplayerid,0x33CCFFAA,string);
       
        GivePlayerMoney(playerid, 0 - amount);
        GameTextForPlayer(playerid,"~y~Money Sent",3000,5);
        format(string, sizeof(string), "You Have Sent $%d To Player %s(%d)",amount,playername,playerid);
        SendClientMessage(playerid,0x33CCFFAA,string);
    }
    return 1;
}
You just needed to use "return SendClientMessage" instead of "SendClientMessage", so it won't go further down the code. That's all.

Cheers.
Reply


Messages In This Thread
Learning Sscanf - by Lajko1 - 11.12.2009, 19:18
Re: Learning Sscanf - by mprofitt - 11.12.2009, 19:29
Re: Learning Sscanf - by DeathOnaStick - 11.12.2009, 19:32
Re: Learning Sscanf - by mprofitt - 11.12.2009, 19:38
Re: Learning Sscanf - by DeathOnaStick - 11.12.2009, 19:50
Re: Learning Sscanf - by dice7 - 11.12.2009, 19:56
Re: Learning Sscanf - by DeathOnaStick - 11.12.2009, 20:00
Re: Learning Sscanf - by dice7 - 11.12.2009, 20:02
Re: Learning Sscanf - by (.Aztec); - 11.12.2009, 20:12
Re: Learning Sscanf - by Malice - 11.12.2009, 23:52

Forum Jump:


Users browsing this thread: 1 Guest(s)