Only Short messages
#1

pawn Код:
CMD:ooc(playerid,params[])
{
    new nu[128],string[128],pname[MAX_PLAYER_NAME];
    if(sscanf(params,"s",nu)) SendClientMessage(playerid,0xFF0000FF,"Use: /o(oc) [Text]");
    else
    {
        GetPlayerName(playerid,pname,sizeof(pname));
        format(string,sizeof(string),"((%s: %s))",pname,nu);
        SendClientMessageToAll(0xFC6103FF,string);
    }
   
    return 1;
}
For some reason,the messages can't be long. Their size is like half of the chat lenght,why is that?
Reply
#2

pawn Код:
CMD:ooc(playerid,params[])
{
    new string[128], pname[MAX_PLAYER_NAME];
    if(isnull(params)) SendClientMessage(playerid, 0xFF0000FF, "Use: /o(oc) [Text]");
    else
    {
        GetPlayerName(playerid, pname, sizeof(pname));
        format(string, sizeof(string), "((%s: %s))",pname, params);
        SendClientMessageToAll(0xFC6103FF, string);
    }
   
    return 1;
}
Reply
#3

Try This

pawn Код:
CMD:ooc(playerid,params[])
{
    new
        string[128]
        pname[24]
     ;
    GetPlayerName(playerid,pname,sizeof(pname));
    //
    if(isnull(params)) SendClientMessage(playerid, 0xFF0000FF, "Use: /o(oc) [Text]");
    //
    format(string,sizeof(string),"((%s: %s))",pname,params);
    SendClientMessageToAll(-1,string);
    return 1;
}
Reply
#4

can you tell me more about "isnull"?
Reply
#5

isnull = if the player hasn't written anything.
Reply
#6

so how is it different from sscanf
Reply
#7

so your not sure about isnull i made you a sscanf one try this
pawn Код:
CMD:ooc(playerid,params[])
{
    new
        string[128],
        pname[24],
        message[128]
     ;
    GetPlayerName(playerid,pname,sizeof(pname));
    //
    if(sscanf(params, "s[128]",message)) return SendClientMessage(playerid, 0xFF0000FF, "Use: /o(oc) [Text]");
    //
    format(string,sizeof(string),"((%s: %s))",pname,message);
    SendClientMessageToAll(-1,string);
    return 1;
}
PS: i just re check your command you forgot to put a value on the integer you put you just did if(sscanf(params,"s",nu)) there is should be a value so it will count your characters or letters
Reply
#8

ahmmmm.... maybe increase the size of the string??
Reply
#9

Quote:
Originally Posted by dusk
Посмотреть сообщение
so how is it different from sscanf
Sscanf splits the parameters, if you only have a one-parameter command (which you do), you don't need sscanf. Using params directly is better in that case, as it's faster - you don't need to split.


Also to make it clear: "isnull" isn't a "method" for making multi-parameter commands. Isnull is a function that checks if the string that the player entered is empty. Isnull is just a check, nothing else.

Why would you use sscanf when you can just directly use "params"?


Here's a little example, a command with sscanf:
pawn Код:
CMD:asd(playerid, params[]) {
    new string[128];
    if(sscanf(params, "s[128]", string)) return SendClientMessage(playerid, -1, "You haven't entered anything after '/asd'");
    printf("%s", string);
    return 1;
}
In that command, we created a string variable, after that sscanf took out the string part from params[] - but it didn't have to, because there's nothing to take out as it's only string.
We're pretty much splitting params from params.

You could just do it this way:
pawn Код:
CMD:asd(playerid, params[]) {
    if(isnull(params)) return SendClientMessage(playerid, -1, "You haven't entered anything after '/asd'");
    printf("%s", params);
    return 1;
}
We just printed the params because we don't have to split anything from it anyway.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)