SA-MP Forums Archive
Strcmp returns 0? - 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 returns 0? (/showthread.php?tid=299306)



Strcmp returns 0? - Homerman - 25.11.2011

Hi.
I've got a simple command defined like

Код:
if(!strcmp("/lol", cmdtext, true, 11))
{
which works without any problem. However, when I use strcmp inside it, it always returns 0; - meaning it just pops up "SERVER: Unknown command".

Код:
if(!strcmp("/lol", cmdtext, true, 11))
{
    new tmp[256], idx;
 	tmp = strtok(cmdtext, idx);
	if(!strlen(tmp))
	{
	    SendClientMessage(playerid, RED, "Syntax: /lol something");
	    return 1;
	}
	if(strcmp(tmp, "something", true) == 0)
	{
 // SOMETHING INSIDE HERE
	}
return 1;
}
Looks like this (of course I edited it, this is not the whole command just preview.
Anybody knows what's the problem here please? Thanks!


Re: Strcmp returns 0? - Kostas' - 25.11.2011

pawn Код:
if(!strcmp("/lol", cmdtext, true, 4)) // This is 4, not 11
{
    new tmp[256], idx;
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp)) {
        SendClientMessage(playerid, RED, "Syntax: /lol something");
        return 1;
    }
    if(strcmp(tmp, "something", true) == 0) {
        // Code
        return 1
    }
    return 0;
}



Re: Strcmp returns 0? - Homerman - 25.11.2011

Shows two SERVER: Unknown command now.
I honestly can't understand what's wrong...


Re: Strcmp returns 0? - |_ⒾⓇⓄN_ⒹⓄG_| - 25.11.2011

use zcmd, ycmd or dcmd... its a lot easier


Re: Strcmp returns 0? - Homerman - 25.11.2011

Quote:
Originally Posted by |_ⒾⓇⓄN_ⒹⓄG_|
Посмотреть сообщение
use zcmd, ycmd or dcmd... its a lot easier
Thanks a lot mister Obvious, now I would like to solve my problem how it is now.
(sorry if I offended you tho, but what you just did is a pure smartass'ing)


Re: Strcmp returns 0? - Kostas' - 25.11.2011

Why did you put the command into the other. To be honest, I don't remember a lot about strcmp because I used it only for 1.5 week.
Try something like this
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp("/lol something", cmdtext, true, 14))
    {
        new tmp[256], idx;
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp)) return SendClientMessage(playerid, RED, "Syntax: /lol something");
        else {
            // Code
        }
        return 1;
    }
    return 0;
}



Re: Strcmp returns 0? - Homerman - 25.11.2011

Because I've got more those "something's" in the script, it's like /lol something1 or /lol something2 etc.
What you just did is not what I'm looking for..


Re: Strcmp returns 0? - Kostas' - 25.11.2011

Then sorry, but I can't help you.
Something last, in case you don't fix it, is to use someyhing like this
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new tmp[256], idx;
    tmp = strtok(cmdtext, idx);
    if(!strcmp("/lol something", cmdtext, true, 14)) {
        // Code
        return 1;
    }
    if(!strcmp("/lol anything", cmdtext, true, 13)) {
        // Code
        return 1;
    }
    if(!strcmp("/lol nothing", cmdtext, true, 12)) {
        // Code
        return 1;
    }
    // rest of Code
    return 0;
}



Re: Strcmp returns 0? - Homerman - 25.11.2011

Thanks for effort, I'll keep on searching then.


Re: Strcmp returns 0? - MP2 - 25.11.2011

https://sampwiki.blast.hk/wiki/Debugging