SA-MP Forums Archive
Strcmp Help - 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)
+--- Thread: Strcmp Help (/showthread.php?tid=540805)



Strcmp Help - Joshayersm - 07.10.2014

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.


Re: Strcmp Help - Vince - 07.10.2014

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


Re: Strcmp Help - Stanford - 07.10.2014

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!


Re: Strcmp Help - Joshayersm - 07.10.2014

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.