Woah! My CMDS are not working!
#1

I need a little help! My CMD's are not working - if I use them, I get no error - and when compiling no error too. No errors in console too.

Code of the commands:

Код:
//ALL THE BASIC CMDS (IMPORTANT ONES)
CMD:me(playerid, params[])
{
    new
        string[128],
        action[100];
    if(sscanf(params, "s[100]", action))
    {
        SendClientMessage(playerid, -1, "USAGE: /me [action]");
        return 1;
    }
    else
    {
        new pName[MAX_PLAYER_NAME];
        GetPlayerName(playerid,pName,sizeof(pName));
        format(string, sizeof(string), "* %s %s",pName, action);
    }
    return 1;
}
CMD:do(playerid, params[])
{
    new
        string[128],
        action[100];
    if(sscanf(params, "s[100]", action))
    {
        SendClientMessage(playerid, -1, "USAGE: /do [action]");
        return 1;
    }
    else
    {
        new pName[MAX_PLAYER_NAME];
        GetPlayerName(playerid,pName,sizeof(pName));
        format(string, sizeof(string), "* %s ((%s))",action, pName);
    }
    return 1;
}
// This shouldn't be inside ANY function. I personally insert mine BELOW OnGameModeInit - Not within it.
CMD:adminroof(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 3.0, 1847.7333,-1761.9608,13.5469))
    {
        SetPlayerPos(playerid, 1889.0286,-1782.9777,25.7911);//Naar boven
        SetPlayerInterior(playerid, 0);
        SendClientMessage(playerid, COLOR_GREEN, "*You use the elevator to get on the roof*");
        return 1;
    }
    SendClientMessage(playerid,0xFFFFFF00,"DEBUG: Not in range!");
    return 1;
}
CMD:admindown(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 3.0, 1889.0286,-1782.9777,25.7911))
    {
        SetPlayerPos(playerid, 1847.7333,-1761.9608,13.5469);//Naar beneden
        SetPlayerInterior(playerid, 0);
        SendClientMessage(playerid, COLOR_GREEN, "*You use the elevator to get down from the roof*");
		return 1;
    }
    SendClientMessage(playerid,0xFFFFFF00,"DEBUG: Not in range!");
    return 1;
}
Reply
#2

AFAIK, this only happens when you try to use TWO command processors together.
Reply
#3

yep, use only one
Reply
#4

Quote:
Originally Posted by Blackazur
Посмотреть сообщение
yep, use only one
Hmm - is sscanf plugin a command processor?
Reply
#5

Код:
//ALL THE BASIC CMDS (IMPORTANT ONES)
CMD:me(playerid, params[])
{
    new
        string[128],
        action[100];
    if(sscanf(params, "s[100]", action))
    {
        SendClientMessage(playerid, -1, "USAGE: /me [action]");
        return 1;
    }
    else
    {
        new pName[MAX_PLAYER_NAME];
        GetPlayerName(playerid,pName,sizeof(pName));
        format(string, sizeof(string), "* %s %s",pName, action);
        SendClientMessage(playerid,COLOR_HERE,string); // <<----------
    }
    return 1;
}
CMD:do(playerid, params[])
{
    new
        string[128],
        action[100];
    if(sscanf(params, "s[100]", action))
    {
        SendClientMessage(playerid, -1, "USAGE: /do [action]");
        return 1;
    }
    else
    {
        new pName[MAX_PLAYER_NAME];
        GetPlayerName(playerid,pName,sizeof(pName));
        format(string, sizeof(string), "* %s ((%s))",action, pName);
        SendClientMessage(playerid,COLOR_HERE,string); // <<----------
    }
    return 1;
}
// This shouldn't be inside ANY function. I personally insert mine BELOW OnGameModeInit - Not within it.
CMD:adminroof(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 3.0, 1847.7333,-1761.9608,13.5469))
    {
        SetPlayerPos(playerid, 1889.0286,-1782.9777,25.7911);//Naar boven
        SetPlayerInterior(playerid, 0);
        SendClientMessage(playerid, COLOR_GREEN, "*You use the elevator to get on the roof*");
        return 1;
    }
    SendClientMessage(playerid,0xFFFFFF00,"DEBUG: Not in range!");
    return 1;
}
CMD:admindown(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 3.0, 1889.0286,-1782.9777,25.7911))
    {
        SetPlayerPos(playerid, 1847.7333,-1761.9608,13.5469);//Naar beneden
        SetPlayerInterior(playerid, 0);
        SendClientMessage(playerid, COLOR_GREEN, "*You use the elevator to get down from the roof*");
		return 1;
    }
    SendClientMessage(playerid,0xFFFFFF00,"DEBUG: Not in range!");
    return 1;
}
You formatted, but forgot to send the client message.
Reply
#6

You don't need sscanf() for this params is already a string you only need to check if it's null. You should also work on your logic your using return; improperly it inflates your code uselessly.

pawn Код:
CMD:me(playerid, params[])
{
    new string[128];
    if(isnull(params)) SendClientMessage(playerid, -1, "USAGE: /me [action]");
    else
    {
        new pName[MAX_PLAYER_NAME];
        GetPlayerName(playerid,pName,sizeof(pName));
        format(string, sizeof(string), "* %s %s",pName, action);
        SendClientMessage(playerid,COLOR_HERE,string); // <<----------
    }
    return 1;
}
Reply
#7

There's nothing wrong with his returns that I know of.
Код:
CMD:adminroof(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 3.0, 1847.7333,-1761.9608,13.5469))
    {
        SetPlayerPos(playerid, 1889.0286,-1782.9777,25.7911);//Naar boven
        SetPlayerInterior(playerid, 0);
        SendClientMessage(playerid, COLOR_GREEN, "*You use the elevator to get on the roof*");
        return 1; // This is to prevent the code from further executing.
    }
    SendClientMessage(playerid,0xFFFFFF00,"DEBUG: Not in range!"); //If the IsPlayerInRangeOfPoint check fails, 
     // ..the script will fall through to this message and finally return. We don't want to see this when they're in range.
    return 1;
}
Read the comments.
Reply
#8

Quote:
Originally Posted by Enforcer501
Посмотреть сообщение
There's nothing wrong with his returns that I know of.
They will work but are not needed and out of place that is what is wrong. It messes up your program flow too take the following statement.

You tell me what makes more sense in practice.

This way.
pawn Код:
SomeCheck()
{
    if(a == 1)
    {
        DoSomeThing();
        return 1;
    }
    DoSomeThingElse();
    return 1;
}
Or This way

pawn Код:
SomeCheck()
{
    if(a == 1)
    {
        DoSomething();
    }
    else
    {
        DoSomethingElse();
    }
    return 1;
}
I don't know about you but the second makes more sense our functions are in alignment now instead of being offset by the return; in readability terms this is much better. Secondly there is only one return 1; it is the last function call in the scope of this function and will always be called once.

Quote:
Originally Posted by Enforcer501
Посмотреть сообщение
Read the comments.
return 1; // This is to prevent the code from further executing.
This is a bad reason;

This is how it should look.
pawn Код:
CMD:adminroof(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 3.0, 1847.7333,-1761.9608,13.5469))
    {
        SetPlayerPos(playerid, 1889.0286,-1782.9777,25.7911);//Naar boven
        SetPlayerInterior(playerid, 0);
        SendClientMessage(playerid, COLOR_GREEN, "*You use the elevator to get on the roof*");
    }
    else SendClientMessage(playerid,0xFFFFFF00,"DEBUG: Not in range!"); //If the IsPlayerInRangeOfPoint check fails,
    return 1;
}
Your only going to return 1; so the command processor knows the command was successful.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)