Strcmp Help
#1

So my issue is I'm trying to compare the option the player types in, with the faction name in the database, now that works. However the issue is, if it has the "else return SendClientMessage" (highlighted in red) then it won't work as I will type for example:
/factioninfo az
and faction info will come up with
Faction Name: Az
Faction ID: 0

However if I then type
/factioninfo yo
It will come up with that faction doesn't exist, even though it does.
Код:
CMD:factioninfo(playerid, params[])
{
	new string[128], factionname[32];
	if(sscanf(params, "s[32]", factionname)) return SendClientMessage(playerid, cred, "USAGE: /factioninfo [factionname]");
	for(new i = 0; i <= Total_Factions_Created; i++)
	{
		if(!strcmp(factionname, fInfo[i][Name], true))
		{
			SendClientMessage(playerid, cwhite, "================Faction Info================");
			format(string, sizeof(string), "Faction Name: %s", fInfo[i][Name]);
			SendClientMessage(playerid, cwhite, string);
			format(string, sizeof(string), "Faction ID: %d", i);
			SendClientMessage(playerid, cwhite, string);
		}
		else return SendClientMessage(playerid, cred, "That faction doesn't exist!");
	}
	return 1;
}
However if I then remove the "else return SendclientMessage" it won't do this, but it wont come up with an error if the faction doesn't exist, it just doesn't display anything.
So if there is no else return SendClientMessage
It will show both faction Az and faction Yo if I type them after /factioninfo.
But when I add the else return SendClientMessage it only shows faction Az.
Reply
#2

I'm moving this one up to the top of the list of "Most common mistakes".

http://forum.sa-mp.com/showthread.ph...op#post3010665
http://forum.sa-mp.com/showthread.ph...op#post3015450
http://forum.sa-mp.com/showthread.ph...op#post3035524
http://forum.sa-mp.com/showthread.ph...op#post3123865
http://forum.sa-mp.com/showthread.ph...op#post3191000
Reply
#3

pawn Код:
CMD:factioninfo(playerid, params[])
{
    new string[128], factionname[32], success = -1;
    if(sscanf(params, "s[32]", factionname)) return SendClientMessage(playerid, cred, "USAGE: /factioninfo [factionname]");
    for(new i = 0; i <= Total_Factions_Created; i++)
    {
        if(!strcmp(factionname, fInfo[i][Name], true))
        {
            SendClientMessage(playerid, cwhite, "================Faction Info================");
            format(string, sizeof(string), "Faction Name: %s", fInfo[i][Name]);
            SendClientMessage(playerid, cwhite, string);
            format(string, sizeof(string), "Faction ID: %d", i);
            SendClientMessage(playerid, cwhite, string);
            success = i;
            break;
        }
    }
    if(success == -1) return SendClientMessage(playerid, -1, "this faction doesn't exist!");
    return 1;
}
enjoy any feedback would be appreciated!
Reply
#4

Quote:
Originally Posted by Stanford
Посмотреть сообщение
pawn Код:
CMD:factioninfo(playerid, params[])
{
    new string[128], factionname[32], success = -1;
    if(sscanf(params, "s[32]", factionname)) return SendClientMessage(playerid, cred, "USAGE: /factioninfo [factionname]");
    for(new i = 0; i <= Total_Factions_Created; i++)
    {
        if(!strcmp(factionname, fInfo[i][Name], true))
        {
            SendClientMessage(playerid, cwhite, "================Faction Info================");
            format(string, sizeof(string), "Faction Name: %s", fInfo[i][Name]);
            SendClientMessage(playerid, cwhite, string);
            format(string, sizeof(string), "Faction ID: %d", i);
            SendClientMessage(playerid, cwhite, string);
            success = i;
            break;
        }
    }
    if(success == -1) return SendClientMessage(playerid, -1, "this faction doesn't exist!");
    return 1;
}
enjoy any feedback would be appreciated!
Ah I see now, thank you for your help.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)