What's wrong with this?
#1

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

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

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

What is string1 and string2?
Reply
#4

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

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

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

Sorry for these newbie questions :S

What is string1 and string2?
Is /armor a string?
Reply
#8

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)