SA-MP Forums Archive
What's wrong with this? - 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: What's wrong with this? (/showthread.php?tid=456670)



What's wrong with this? - Zach7 - 06.08.2013

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{

    if (strcmp("/weapon", cmdtext, true, 5) == 0)
    {
        GivePlayerWeapon (playerid, 26, 500);
        return 1;
    }
   
    if (strcmp("/armor", true) == 0)
{
    SetPlayerArmour(playerid, 100.0);
    SendClientMessage(playerid, 0xFFFFFF, "You now have 100 armor.");
    return 1;
    }
    return 0;
}
I'm just starting to learn this stuff :P

I get this error
pawn Код:
error 035: argument type mismatch (argument 2)



Re: What's wrong with this? - Konstantinos - 06.08.2013

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
   
    //if (strcmp("/weapon", cmdtext, true, 5) == 0)
    //if (strcmp("/weapon", cmdtext, true, 7) == 0) // 7 lenght, not 5. Lenght is option so this is easier and simplier
    if (!strcmp("/weapon", cmdtext, true)) // 7 lenght, not 5. Lenght is option so this is easier
    {
        GivePlayerWeapon (playerid, 26, 500);
        return 1;
    }
   
    //if (strcmp("/armor", true) == 0)
    if (!strcmp("/armor", cmdtext, true)) // comparing string1 with true, missing string2
    {
        SetPlayerArmour(playerid, 100.0);
        SendClientMessage(playerid, 0xFFFFFF, "You now have 100 armor.");
        return 1;
    }
    return 0;
}



Re: What's wrong with this? - Zach7 - 06.08.2013

I got it thanks! I understand the "true" thing

What is string1 and string2?


Re: What's wrong with this? - Konstantinos - 06.08.2013

The parameters.
pawn Код:
strcmp(string1, string2, false/true, sizeof(string1))
// compare string1 with string2 etc..



Re: What's wrong with this? - Zach7 - 06.08.2013

What does the == 0) at the end mean? Is that needed each time?


Re: What's wrong with this? - Konstantinos - 06.08.2013

Returns
-1 if string1 comes before string2
1 if string1 comes after string2
0 if the strings are the same (for the matched length).

So, we basically check if these two strings we compare return 0 (they're same).
pawn Код:
if(!strcmp("/armor", cmdtext, true))
// OR
if(strcmp("/armor", cmdtext, true) == 0)
// is the same thing



Re: What's wrong with this? - Zach7 - 06.08.2013

Sorry for these newbie questions :S

What is string1 and string2?
Is /armor a string?


Re: What's wrong with this? - Konstantinos - 06.08.2013

It's fine.

We compare 2 strings (a sequence of characters). The first string and the second string. Yes, you type "/armour" and that's a string so it compares if the text you typed (cmdtext "holds" it) is equal to "/armour", so do something.


Re: What's wrong with this? - hossa - 06.08.2013

i suggest you to use Zcmd because it's faster/easier and most of people use it.
and it's alot easier than Strcmp.
Good Luck in all ways.


Re: What's wrong with this? - Zach7 - 06.08.2013

Okay I guess I understand it :/ It is still a little confusing but thanks for the help Konstantinos, I rep +1 you