SA-MP Forums Archive
Is there a way to do this without a string? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Is there a way to do this without a string? (/showthread.php?tid=273755)



Is there a way to do this without a string? - Shockey HD - 03.08.2011

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?


Re: Is there a way to do this without a string? - PrawkC - 03.08.2011

No..


Re: Is there a way to do this without a string? - Kush - 03.08.2011

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

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


Re: Is there a way to do this without a string? - Jack_Leslie - 03.08.2011

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



Re: Is there a way to do this without a string? - Shockey HD - 03.08.2011

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?


Re: Is there a way to do this without a string? - Jack_Leslie - 03.08.2011

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:
Код:
https://sampwiki.blast.hk/wiki/Format



Re: Is there a way to do this without a string? - PotH3Ad - 03.08.2011

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



Re: Is there a way to do this without a string? - Shockey HD - 03.08.2011

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.


Re: Is there a way to do this without a string? - iggy1 - 03.08.2011

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.


Re: Is there a way to do this without a string? - Shockey HD - 03.08.2011

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 :]