Strcmp returns 0?
#1

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!
Reply
#2

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;
}
Reply
#3

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

use zcmd, ycmd or dcmd... its a lot easier
Reply
#5

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)
Reply
#6

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

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..
Reply
#8

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;
}
Reply
#9

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)