SA-MP Forums Archive
Command Help - 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: Command Help (/showthread.php?tid=306036)



Command Help - ReneG - 24.12.2011

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.


Re: Command Help - Jakku - 24.12.2011

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



Re: Command Help - ReneG - 24.12.2011

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


Re: Command Help - prisonliferp - 24.12.2011

Код:
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


Re: Command Help - Dark_Kostas - 24.12.2011

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


Re: Command Help - prisonliferp - 24.12.2011

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.


Re: Command Help - ReneG - 24.12.2011

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


Re: Command Help - prisonliferp - 24.12.2011

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


Re: Command Help - Dark_Kostas - 24.12.2011

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


Re: Command Help - Gh05t_ - 24.12.2011

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