When adding a parameter to a /ask command, it doesn't work
#1

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?
Reply
#2

Are there in 'params' more than one word?
Reply
#3

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
Reply
#4

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;
}
Reply
#5

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.
Reply
#6

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

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

I was wrong...
nvm
Reply
#9

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.
Reply
#10

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


Forum Jump:


Users browsing this thread: 3 Guest(s)