sscanf/strcmp problem... -
JamesS - 21.02.2013
Pff, again I've been on this for an hour again, again an hour wasted. Seems like I really need to learn some more about working with strings. Well, the image will speak for itself.
declaration, and the command...
Код:
enum MAIL_BOX{
bool:Owned,
Owner[MAX_PLAYER_NAME],
Messages
}
Код:
CMD:mail(playerid, params[])
{
new toplayer[MAX_PLAYER_NAME];
if(!sscanf(params, "s[17]", toplayer))
{
*new string[256];
* * new boxid, bool:found;
* * format(string, sizeof(string), "name to search for %s", toplayer);
* * SendClientMessage(playerid, COLOUR_YELLOW, string);
* * for(new i=0;i<MailBoxid;i++)
* * {
* * * * format(string, sizeof(string), "owner of mailbox %i %s", i, gMAIL_BOX[i][Owner]);
* * *SendClientMessage(playerid, COLOUR_YELLOW, string);
* * * * * *if(strcmp(toplayer, gMAIL_BOX[i][Owner], true, strlen(toplayer) == 0))
* * * * * *{
* * * * * * * *found = true;
* *boxid = i;
* *SendClientMessage(playerid, COLOUR_YELLOW, "found");
* }
* SendClientMessage(playerid, COLOUR_YELLOW, "not found!");
*}
* *if(found)
* *{
* * * *format(string, sizeof(string), "You succesfully sumbitted your mail to player %s", toplayer);
* * * *SendClientMessage(playerid, COLOUR_YELLOW, string);
* * * *gMAIL_BOX[boxid][Messages] += 1;
* *}
* *else SendClientMessage(playerid, COLOR_WHITE, "player not found'");
}
else SendClientMessage(playerid, COLOR_WHITE, "USAGE: '/sendmail [Name]'");
return 1;
}
Re: sscanf/strcmp problem... -
JamesS - 21.02.2013
Please, someone?
Re: sscanf/strcmp problem... -
JamesS - 21.02.2013
Someone sees what the problem is?
Re: sscanf/strcmp problem... -
Da_Noob - 21.02.2013
I don't really see the problem here. So, whenever you do /mail it shows those messages?
Name to search for blabla
Owner of mailbox is balbla
Player not found
Re: sscanf/strcmp problem... -
JamesS - 21.02.2013
The problem is, When I use /mail (name, for examle James_Williamson), a loop starts, and checks the owner of each mailbox. Now, when James_Williamson owns one of the mailboxes, I want the I to be saved in boxid, so I can work with that ID, but the strcmp doesn't seem to work; (clientmessage not found)..
Added those messages for myself, because I coudn't find what's wrong...
Re: sscanf/strcmp problem... -
Scenario - 21.02.2013
If you cared to read the information about the strcmp function, you would of also known that strcmp returns 0 when the statement is true.
https://sampwiki.blast.hk/wiki/Strcmp
Change:
pawn Код:
if(strcmp(toplayer, gMAIL_BOX[i][Owner], true, strlen(toplayer) == 0))
... to:
pawn Код:
if(!strcmp(toplayer, gMAIL_BOX[i][Owner], true))
* I removed the excess shit you don't need in your strcmp function.
Re: sscanf/strcmp problem... -
JamesS - 21.02.2013
Fixed, thanks guys.