Command Help
#1

So I'm new to PAWN, and I'm just tinkering around with commands. I made a command called ''/cop'' that gives you a cop skin, refills your armour and health, and and gives you a deagle. So I got the command to work, but when ever I type it IG I see this.



I have no idea where that ''SERVER: Uknown Command" is coming from. All I do is type ''/cop'' once and it returns the ''You are now a cop!'' message as well as the Unknown Command Message.

Here is my code.
pawn Код:
if(strcmp("/cop", cmdtext, true, 10) ==0)
    {  
        IsPlayerAdmin(playerid)
        {
            SendClientMessage(playerid, 0x80FFFFFF, "You are now a cop!");
            SetPlayerHealth(playerid, 100);
            SetPlayerArmour(playerid, 100);
            GivePlayerWeapon(playerid, 24, 9999);
            SetPlayerSkin(playerid, 280);
            }
        }
        else { 
        {
            if(IsPlayerAdmin(playerid))
            {
                SendClientMessage(playerid, 0xFF0000FF, "You are not an Admin!")
            }
        }  
        return 1;
    }  
    return 0;      
}
/---------------------------------------------------------------------------------------------------------------------------------------------------\
/---------------------------------------------------------------------------------------------------------------------------------------------------\

Another thing, I was also trying to make this an Admin only command, but whenever I type ANY command I just get the ''You are not an Admin'' message. Same code was used above. Thank you.
Reply
#2

pawn Код:
if(strcmp("/cop", cmdtext, true, 10) ==0)
{
        if (IsPlayerAdmin(playerid))
        {
            SendClientMessage(playerid, 0x80FFFFFF, "You are now a cop!");
            SetPlayerHealth(playerid, 100);
            SetPlayerArmour(playerid, 100);
            GivePlayerWeapon(playerid, 24, 9999);
            SetPlayerSkin(playerid, 280);
        }
        else
        {
            SendClientMessage(playerid, 0xFF0000FF, "You are not an Admin!")
        }
    return 1;
}
Reply
#3

Thank you for the swift reply. but this didn't help me any. But nonetheless, thank you for your help. +Rep
Reply
#4

Код:
if(strcmp("/cop", cmdtext, true, 10) ==0)
{
        if (IsPlayerAdmin(playerid))
        {
            SendClientMessage(playerid, 0x80FFFFFF, "You are now a cop!");
            SetPlayerHealth(playerid, 100);
            SetPlayerArmour(playerid, 100);
            GivePlayerWeapon(playerid, 24, 9999);
            SetPlayerSkin(playerid, 280);
        }
        else
        {
            SendClientMessage(playerid, 0xFF0000FF, "You are not an Admin!")
            return 0;
        }
    return 1;
}
-Not pretty sure, try it out? :3

The return 0; makes sure that it doesn't give something back such as "Unknown command" -I think?

+Rep if I helped out :3
Reply
#5

If i remember right the forum has a "someone posted already" warning and someone already answered correctly
EDIT: No it doesn't have that anymore...

Also i prefer to do my commands like that.

pawn Код:
if(strcmp("/cop", cmdtext, true, 4) ==0)
{
    if (!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000FF, "You are not an Admin!")

    SetPlayerHealth(playerid, 100);
    SetPlayerArmour(playerid, 100);
    GivePlayerWeapon(playerid, 24, 9999);
    SetPlayerSkin(playerid, 280);

    SendClientMessage(playerid, 0x80FFFFFF, "You are now a cop!");
    return 1;
}
EDIT: Try this one. Should work
Reply
#6

The thing is Pal'...

His code was not correct, he didn't fix what he he wanted to work.

Therefor my post was fully legible.
Reply
#7

Quote:
Originally Posted by Dark_Kostas
Посмотреть сообщение
If i remember right the forum has a "someone posted already" warning and someone already answered correctly.

Also i prefer to do my commands like that.

pawn Код:
if(strcmp("/cop", cmdtext, true, 4) == 0)
{
    if (!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000FF, "You are not an Admin!")

    SetPlayerHealth(playerid, 100);
    SetPlayerArmour(playerid, 100);
    GivePlayerWeapon(playerid, 24, 9999);
    SetPlayerSkin(playerid, 280);

    SendClientMessage(playerid, 0x80FFFFFF, "You are now a cop!");
    return 1;
}
Thank you both for answering this solved my problem. I will do my command like this now. +Repped
Reply
#8

No problem mate, did you try if my code worked?
Reply
#9

Quote:
Originally Posted by prisonliferp
Посмотреть сообщение
No problem mate, did you try if my code worked?
Your code won't work because:

1st
if(strcmp("/cop", cmdtext, true, 10) ==0)

The length of the command text is not 10 but 4(and this was the main problem)

2nd
If you are not admin it will say the message but also Unknown Command cause you are using return 0
Reply
#10

Quote:
Originally Posted by Dark_Kostas
Посмотреть сообщение
Your code won't work because:

1st
if(strcmp("/cop", cmdtext, true, 10) ==0)

The length of the command text is not 10 but 4(and this was the main problem)
This does not in ANY way affect the code! The maximum length of the string is 10. You are not entitled to specify the exact length of the string.

pawn Код:
if (strcmp("/output", cmdtext, true, 20) == 0)
    {
        SendClientMessage(playerid, -1, "true");
        //print("true");
        return 1;
    }
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)