pls help me with my string :)
#1

I just wanted to make a /afk <minutes> <reason> command and tried to split the string with sscanf.
but now when you do /afk 2 its working fine but by doing /afk 2 some reason you get : "kidul is away from keyboard for 97 minutes (Reason: ...kidul)"

here is my code:
Код:
command(afk, playerid, params[])
{
			new string[128];
			new pName[MAX_PLAYER_NAME];
			new minutes, reason;
			if(sscanf(params,"uz",minutes,reason)) return SendClientMessage(playerid,0xFF0000AA,"Usage: /afk <minutes> <reason>");
			GetPlayerName(playerid,pName,sizeof(pName));
			format(string,sizeof(string),"%s is away from keyboard for %i minutes (Reason: %s)",pName,minutes,reason);
			SendClientMessageToAll(0xFF0000AA,string);
      return 1;
}
Reply
#2

anyone ... ? sry for double post but my topic was going to be forgotten
Reply
#3

I'll write out the command, give me two minutes, and i'll edit the post.

pawn Код:
cmd(afk, playerid, params[])
{
    new string[128], name[MAX_PLAYER_NAME], minute, reason[128];
    if(!sscanf(params, "is", minutes, reason))
    {
      GetPlayerName(playerid, name, sizeof(name));
      format(string,sizeof(string),"%s is away from keyboard for %i minutes (Reason: %s)",name,minutes,reason);
      SendClientMessageToAll(0xFF0000AA,string);
    }
    else return SendClientMessage(playerid,0xFF0000AA,"Usage: /afk <minutes> <reason>");
    return 1;
}
The thing that you did wrong: You need to define reason as a string.

Yours:
pawn Код:
new reason;
Correct:
pawn Код:
new reason[128];
Reply
#4

thank you , stupid mistake :O
Reply
#5

now there is something wrong with the minutes if the length of the number of minutes is over 1 it will display something wrong
Reply
#6

Quote:
Originally Posted by sizeof(Sky));
I'll write out the command, give me two minutes, and i'll edit the post.

pawn Код:
cmd(afk, playerid, params[])
{
    new string[128], name[MAX_PLAYER_NAME], minute, reason[128];
    if(!sscanf(params, "is", minutes, reason))
    {
      GetPlayerName(playerid, name, sizeof(name));
      format(string,sizeof(string),"%s is away from keyboard for %d minutes (Reason: %s)",name,minutes,reason);
      SendClientMessageToAll(0xFF0000AA,string);
    }
    else return SendClientMessage(playerid,0xFF0000AA,"Usage: /afk <minutes> <reason>");
    return 1;
}
The new thing that you done wrong: Could be the %i in the format.

Yours:
pawn Код:
%i
Correct:
pawn Код:
%d
:P
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)