SA-MP Forums Archive
Woah! My CMDS are not working! - 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: Woah! My CMDS are not working! (/showthread.php?tid=444823)



Woah! My CMDS are not working! - Songason - 18.06.2013

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



Re: Woah! My CMDS are not working! - Littlehelper - 18.06.2013

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


AW: Woah! My CMDS are not working! - Blackazur - 18.06.2013

yep, use only one


Re: AW: Woah! My CMDS are not working! - Songason - 18.06.2013

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


Re: Woah! My CMDS are not working! - Enforcer501 - 18.06.2013

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


Re: Woah! My CMDS are not working! - Pottus - 18.06.2013

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



Re: Woah! My CMDS are not working! - Enforcer501 - 18.06.2013

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.


Re: Woah! My CMDS are not working! - Pottus - 18.06.2013

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.