/B Command
#1

Hi,

I tried making a command on my own, without anyone else's help although I found it to be quite hard. The command was actually kind of a success, as the only problem is that the name and the actual message has changed places when using the command IG.

pawn Код:
CMD:b(playerid, params[])
{
    new string[256], name[MAX_PLAYER_NAME+1];
    GetPlayerName(playerid, name, sizeof(name));
    if(sscanf(params, "s128", params[0])) return SendClientMessage(playerid, 0xF69521AA, "USAGE: /b [local OOC message]");
    format(string, sizeof(string), "(( %s says: %s ))", params[0], name);
    SendNearbyMessage(playerid, 15, string, 0xF69521AA, 0xF69521AA, 0xF69521AA, 0xF69521AA, 0xF69521AA);
    return 1;
}
I'm thinking there's a really small issue I've done in there, and I'm hoping any of you can see what it is.

Regards,
Reply
#2

Well there are three things with the command:

When using sscanf, you don't need to specify the cell of the params, since it will always be by default the first cell (0); hell you don't even need to check for one param if you use IsNull or something like that.
Secondly, the sscanf scan line is wrongly put, the size for the string must be in brackets [], so it should be s[128].
And finally, your formatted order:

Quote:

format(string, sizeof(string), "(( %s says: %s ))", params[0], name);

The formatting parameters correspond to in order to the placeholders you use, so it goes the first %s to params (which is the text), and the second %s to the player name, you should invert it and then you will fix it.
Reply
#3

pawn Код:
CMD:b(playerid, params[])
{
     new string[256], name[MAX_PLAYER_NAME];
     GetPlayerName(playerid, name, sizeof(name));
     if(!strlen(params)) return SendClientMessage(playerid, 0xF69521AA, "USAGE: /b [local OOC message]");
     format(string, sizeof(string), "(( %s says: %s ))",name,params);
     SendNearbyMessage(playerid, 15, string, 0xF69521AA, 0xF69521AA, 0xF69521AA, 0xF69521AA, 0xF69521AA);
     return 1;
}
Try this
Reply
#4

So, basically, this is the way it should be?

pawn Код:
CMD:b(playerid, params[])
{
    new string[256], name[MAX_PLAYER_NAME+1];
    GetPlayerName(playerid, name, sizeof(name));
    if(sscanf(params, "s[128]", params[0])) return SendClientMessage(playerid, 0xF69521AA, "USAGE: /b [local OOC message]");
    format(name, sizeof(string), "(( %s says: %s ))", params, string);
    SendNearbyMessage(playerid, 15, string, 0xF69521AA, 0xF69521AA, 0xF69521AA, 0xF69521AA, 0xF69521AA);
    return 1;
}
EDIT: Didn't see your post Rakshith, but could you try explaining what you did in that script?

EDIT2: Can someone tell me whether my script is right or not, and if not what the problem in it is? Just in order to attempt to learn some more of pawno.
Reply
#5

pawn Код:
format(name, sizeof(string), "(( %s says: %s ))", params, string);
pawn Код:
this should be like

format(string,sizeof(string), "(( %s says: %s ))", name,params)
Here the first %s defines the name of the user and the second %s defines the message.
EDIT : Instead of if(sscanf..... )) use if(!strlen(params))
Saying it only for this command..]
Reply
#6

You have the player's name and the text string backwards. You've defined the first %s to be the text, and the second to be name.

pawn Код:
format(string, sizeof(string), "(( %s says: %s ))", params[0], name);
It should be the other way

pawn Код:
format(string, sizeof(string), "(( %s says: %s ))", name, params[0]);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)