SA-MP Forums Archive
When adding a parameter to a /ask command, it doesn't work - 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: When adding a parameter to a /ask command, it doesn't work (/showthread.php?tid=351635)



When adding a parameter to a /ask command, it doesn't work - stormchaser206 - 16.06.2012

OK, I compile it with no errors, but ingame, for example, when i type "/ask Example", it says nothing. But if i just do "/ask", it says "Usage: /ask (Question)".

Code:
pawn Код:
dcmd_ask(playerid, params[])
{
    new string[100];
    new pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, sizeof(pName));
    if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "Usage: /ask (Your Question)");
    else
    {   for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(PlayerInfo[i][Helper] == 1)
            {
                if(IsPlayerConnected(i))
                {
                    format(string, sizeof(string), "-| You have successfully asked a question | Question: %s |-", params[1]);
                    SendClientMessage(playerid, COLOR_AQUA, string);
                    format(string, sizeof(string), "-| %s(%d) has asked a question | Question: %s |-", pName, playerid, params[1]);
                    SendClientMessage(i, COLOR_AQUA, string);
                    return 0;
                }
                else SendClientMessage(playerid, COLOR_RED, "ERROR: There are no helpers online to help.");
            }
        }
    }
    return 1;
}
Any help here?


Re: When adding a parameter to a /ask command, it doesn't work - ViniBorn - 16.06.2012

Are there in 'params' more than one word?


Re: When adding a parameter to a /ask command, it doesn't work - stormchaser206 - 16.06.2012

Quote:
Originally Posted by Viniborn
Посмотреть сообщение
Are there in 'params' more than one word?
?

EDIT: What are you talking about?
On scripting its params[], the real world its parameters


Re: When adding a parameter to a /ask command, it doesn't work - SnG.Scot_MisCuDI - 16.06.2012

pawn Код:
dcmd_ask(playerid, params[])
{
    new string[100];
    new pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, sizeof(pName));
    if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "Usage: /ask (Your Question)");
    else
    {   for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(PlayerInfo[i][Helper] == 1)
            {
                if(IsPlayerConnected(i))
                {
                    format(string, sizeof(string), "-| You have successfully asked a question | Question: %s |-", params);
                    SendClientMessage(playerid, COLOR_AQUA, string);
                    format(string, sizeof(string), "-| %s(%d) has asked a question | Question: %s |-", pName, playerid, params);
                    SendClientMessage(i, COLOR_AQUA, string);
                    return 0;
                }
                else SendClientMessage(playerid, COLOR_RED, "ERROR: There are no helpers online to help.");
            }
        }
    }
    return 1;
}



Re: When adding a parameter to a /ask command, it doesn't work - stormchaser206 - 16.06.2012

Quote:
Originally Posted by SnG.Scot_MisCuDI
Посмотреть сообщение
pawn Код:
dcmd_ask(playerid, params[])
{
    new string[100];
    new pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, sizeof(pName));
    if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "Usage: /ask (Your Question)");
    else
    {   for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(PlayerInfo[i][Helper] == 1)
            {
                if(IsPlayerConnected(i))
                {
                    format(string, sizeof(string), "-| You have successfully asked a question | Question: %s |-", params);
                    SendClientMessage(playerid, COLOR_AQUA, string);
                    format(string, sizeof(string), "-| %s(%d) has asked a question | Question: %s |-", pName, playerid, params);
                    SendClientMessage(i, COLOR_AQUA, string);
                    return 0;
                }
                else SendClientMessage(playerid, COLOR_RED, "ERROR: There are no helpers online to help.");
            }
        }
    }
    return 1;
}
It doesn't work, same result.


Re: When adding a parameter to a /ask command, it doesn't work - iggy1 - 16.06.2012

It's because you are returning inside the loop, so it only gets executed once.

A better way to do it would be this.

pawn Код:
dcmd_ask(playerid, params[])
{
    new string[128];
    new pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, sizeof(pName));
   
    if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "Usage: /ask (Your Question)");
    else
    {
        SendClientMessage(playerid, COLOR_AQUA, "-| You have successfully asked a question");
        format(string, sizeof(string), "-| %s(%d) has asked a question | Question: %s |-", pName, playerid, params);
        SendClientMessageToAll(COLOR_AQUA, string);
    }
    return 1;
}



Re: When adding a parameter to a /ask command, it doesn't work - Aprezt - 16.06.2012

if(sscanf(params, "s[225]", result)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /question [ Text ]");


Re: When adding a parameter to a /ask command, it doesn't work - Djole1337 - 16.06.2012

I was wrong...
nvm


Re: When adding a parameter to a /ask command, it doesn't work - stormchaser206 - 16.06.2012

Quote:
Originally Posted by iggy1
Посмотреть сообщение
It's because you are returning inside the loop, so it only gets executed once.

A better way to do it would be this.

pawn Код:
dcmd_ask(playerid, params[])
{
    new string[128];
    new pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, sizeof(pName));
   
    if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "Usage: /ask (Your Question)");
    else
    {
        SendClientMessage(playerid, COLOR_AQUA, "-| You have successfully asked a question");
        format(string, sizeof(string), "-| %s(%d) has asked a question | Question: %s |-", pName, playerid, params);
        SendClientMessageToAll(COLOR_AQUA, string);
    }
    return 1;
}
I did the loop so only helpers could see the "-| %s(%d) has asked a question" thing.


Re: When adding a parameter to a /ask command, it doesn't work - iggy1 - 16.06.2012

Try this one, you should look for foreach.inc it only loops through connected players so you never have to do redundant connection checks.

pawn Код:
dcmd_ask(playerid, params[])
{
    new string[128];
    new pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, sizeof(pName));
    if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "Usage: /ask (Your Question)");
    else
    {
        new cHelperCount=0;
       
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(!IsPlayerConnected(i))continue;
           
            if(PlayerInfo[i][Helper] == 1)
            {
                format(string, sizeof(string), "-| %s(%d) has asked a question | Question: %s |-", pName, playerid, params);
                SendClientMessage(i, COLOR_AQUA, string);
                cHelperCount++;
            }
        }
       
        if(!cHelperCount) {
            SendClientMessage(playerid, COLOR_RED, "ERROR: There are no helpers online to help.");
        }
        else
        {
            format(string, sizeof(string), "-| You have successfully asked a question | Question: %s |-", params);
            SendClientMessage(playerid, COLOR_AQUA, string);
        }
    }
    return 1;
}