Is there a way to do this without a string?
#1

So im wanting to send a message via SendClientMessage instead of a string.

Heres what my SendClientMessage looks like.

pawn Код:
SendClientMessage(playerid,COLOR_GREEN,"You have sent %s to %s!",amount,name);
Im just getting

PHP код:
warning 202number of arguments does not match definition 
Im i setting this up wrong?
Reply
#2

No..
Reply
#3

Quote:
Originally Posted by PrawkC
Посмотреть сообщение
No..
This.

You would need to use format, as this includes variables.
Reply
#4

No.. it needs to be in string format...

pawn Код:
new string[258];
format(string, sizeof(string), "You have sent %s to %s!", amount, name);
SendClientMessage(playerid,COLOR_GREEN, string);
Reply
#5

My main problem was that i didnt know how to send a message to playerid and the receiver.

i am new to using sscanf btw.

Okay, So heres my current code.

pawn Код:
CMD:givecash(playerid,params[])
{
    new
        id,
        amount;
    if (sscanf(params, "ud", id, amount)) SendClientMessage(playerid,COLOR_RED,"Usage: /givecash <ID> <Amount>");
    else if (id == INVALID_PLAYER_ID) SendClientMessage(playerid,COLOR_RED,"Error: Player Not Connected!");
    else
    {
        GivePlayerMoney(id,amount);
        new string[19];
        new string1[19];
        format(string, sizeof(string), "You have sent %s to %s",amount,id);
        format(string1, sizeof(string1), "You have recieved % from %s",amount,id);
        SendClientMessage(playerid, COLOR_GREEN, string);
        SendClientMessage(id, COLOR_GREEN, string1);
    }
    return 1;
}
This dosnt show how much money the player has recieved and the name of the sender. Why so?
Reply
#6

pawn Код:
CMD:givecash(playerid,params[])
{
    new
        id,
        amount;
    if (sscanf(params, "ud", id, amount)) SendClientMessage(playerid,COLOR_RED,"Usage: /givecash <ID> <Amount>");
    else if (id == INVALID_PLAYER_ID) SendClientMessage(playerid,COLOR_RED,"Error: Player Not Connected!");
    else
    {
        GivePlayerMoney(id,amount);
        new string[19];
        new string1[19];
        format(string, sizeof(string), "You have sent %d to %s",amount,id);
        format(string1, sizeof(string1), "You have recieved %d from %s",amount,id);
        SendClientMessage(playerid, COLOR_GREEN, string);
        SendClientMessage(id, COLOR_GREEN, string1);
    }
    return 1;
}
You missed a S on one of the "%"?

Also read this:
Код:
%b  Inserts a number at this position in binary radix  
%c  Inserts a single character.  
%d  Inserts an integer (whole) number  
%f  Inserts a floating point number.  
%i  Inserts an integer.  
%s  Inserts a string.  
%x  Inserts a number in hexadecimal notation.  
%%  Inserts the literal '%'
From:
Reply
#7

Quote:
Originally Posted by Jack_Leslie
Посмотреть сообщение
pawn Код:
CMD:givecash(playerid,params[])
{
    new
        id,
        amount;
    if (sscanf(params, "ud", id, amount)) SendClientMessage(playerid,COLOR_RED,"Usage: /givecash <ID> <Amount>");
    else if (id == INVALID_PLAYER_ID) SendClientMessage(playerid,COLOR_RED,"Error: Player Not Connected!");
    else
    {
        GivePlayerMoney(id,amount);
        new string[19];
        new string1[19];
        format(string, sizeof(string), "You have sent %d to %s",amount,id);
        format(string1, sizeof(string1), "You have recieved %d from %s",amount,id);
        SendClientMessage(playerid, COLOR_GREEN, string);
        SendClientMessage(id, COLOR_GREEN, string1);
    }
    return 1;
}
The string size is to small as well and there is no need to create 2 different strings.
pawn Код:
CMD:givecash(playerid,params[])
{
    new
        id,
        amount;
    if(sscanf(params, "ud", id, amount)) SendClientMessage(playerid,COLOR_RED,"Usage: /givecash <ID> <Amount>");
    else if(id == INVALID_PLAYER_ID) SendClientMessage(playerid,COLOR_RED,"Error: Player Not Connected!");
    else
    {
        GivePlayerMoney(id,amount);
        new str[40+MAX_PLAYER_NAME];
        format(str, sizeof(str), "You have sent %d to %s",amount,id);
        SendClientMessage(playerid, COLOR_GREEN, str);
        format(str, sizeof(str), "You have recieved %d from %s",amount,id);
        SendClientMessage(id, COLOR_GREEN, str);
    }
    return 1;
}
Reply
#8

Quote:
Originally Posted by PotH3Ad
Посмотреть сообщение
The string size is to small as well and there is no need to create 2 different strings.
pawn Код:
CMD:givecash(playerid,params[])
{
    new
        id,
        amount;
    if(sscanf(params, "ud", id, amount)) SendClientMessage(playerid,COLOR_RED,"Usage: /givecash <ID> <Amount>");
    else if(id == INVALID_PLAYER_ID) SendClientMessage(playerid,COLOR_RED,"Error: Player Not Connected!");
    else
    {
        GivePlayerMoney(id,amount);
        new str[40+MAX_PLAYER_NAME];
        format(str, sizeof(str), "You have sent %d to %s",amount,id);
        SendClientMessage(playerid, COLOR_GREEN, str);
        format(str, sizeof(str), "You have recieved %d from %s",amount,id);
        SendClientMessage(id, COLOR_GREEN, str);
    }
    return 1;
}
That works, except it dosnt show the players name.
Reply
#9

Thats because your passing the playerid (the variable id) to "format" instead of the players name.
pawn Код:
CMD:givecash(playerid,params[])
{
    new
        id,
        amount;
    if(sscanf(params, "ud", id, amount)) SendClientMessage(playerid,COLOR_RED,"Usage: /givecash <ID> <Amount>");
    else if(id == INVALID_PLAYER_ID) SendClientMessage(playerid,COLOR_RED,"Error: Player Not Connected!");
    else
    {
        new
            szPName[MAX_PLAYER_NAME];
        GivePlayerMoney(id,amount);
        new str[40+MAX_PLAYER_NAME];
        GetPlayerName(id, szPName, MAX_PLAYER_NAME);
        format(str, sizeof(str), "You have sent %d to %s",amount,szPName);
        SendClientMessage(playerid, COLOR_GREEN, str);
        GetPlayerName(playerid, szPName, MAX_PLAYER_NAME);
        format(str, sizeof(str), "You have recieved %d from %s",amount,szPName);
        SendClientMessage(id, COLOR_GREEN, str);
    }
    return 1;
}
Its impossible to display a players name without using a string, because a players name IS a string.
Reply
#10

Yes, this is what i have

pawn Код:
CMD:givecash(playerid,params[])
{
    new
        id,
        amount;
    if(sscanf(params, "ud", id, amount)) SendClientMessage(playerid,COLOR_RED,"Usage: /givecash <ID> <Amount>");
    else if(id == INVALID_PLAYER_ID) SendClientMessage(playerid,COLOR_RED,"Error: Player Not Connected!");
    else
    {
        new name[MAX_PLAYER_NAME], PlayerName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        GetPlayerName(id, PlayerName, sizeof(PlayerName));
        GivePlayerMoney(id,amount);
        new str[40+MAX_PLAYER_NAME];
        format(str, sizeof(str), "You have sent %d to %s",amount,PlayerName);
        SendClientMessage(playerid, COLOR_GREEN, str);
        format(str, sizeof(str), "You have recieved %d from %s",amount,name);
        SendClientMessage(id, COLOR_GREEN, str);
    }
    return 1;
}
And it works :]
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)