SA-MP Forums Archive
pls help me with my 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: pls help me with my string :) (/showthread.php?tid=107633)



pls help me with my string :) - KIDUL - 10.11.2009

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



Re: pls help me with my string :) - KIDUL - 10.11.2009

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


Re: pls help me with my string :) - (.Aztec); - 10.11.2009

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



Re: pls help me with my string :) - KIDUL - 10.11.2009

thank you , stupid mistake :O


Re: pls help me with my string :) - KIDUL - 10.11.2009

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


Re: pls help me with my string :) - oncedead - 10.11.2009

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