'Ask' Command Not Displaying Correctly?
#1

I have a command so people can ask questions to admins but when the message is sent the question is always missing the first word. Why?

Код:
if(strcmp(cmd, "/ask", true) == 0) // Available for everyone: ask a q to admins
	{
		tmp = strtok(cmdtext, idx);
		if(!strlen(tmp))
		{
			SendClientMessage(playerid, ORANGE, "USAGE: /ask [Question]");
			SendClientMessage(playerid, ORANGE, "FUNCTION: Will Ask The Specified Question To All Online Administrators.");
			return 1;
	 	}
		{
			GetPlayerName(playerid, sendername, sizeof(sendername));
			new question[128];
			question = bigstrtok(cmdtext,idx);
			if(!strlen(question)) return SendClientMessage(playerid, ORANGE, "USAGE: /ask [Question]");
			format(string, sizeof(string), "%s Asks A Question: '%s'", sendername,question);
			SendClientMessageToAdmins(ADMIN_RED, string,1);
			format(string, sizeof(string), "Your question has been sent to the current online admins. Thank you.");
			SendClientMessage(playerid, GREEN, string);
		}
		return 1;
	}
For example if you type /ask How do i get a bullet. It will say <name> Asks A Question: do i get a bullet
Reply
#2

question = bigstrtok(cmdtext,idx);

what's bigstrtok? maybe try the usual strtok?
Reply
#3

pawn Код:
stock bigstr(const string[], &idx)
{
  new length = strlen(string);
    while ((idx < length) && (string[idx] <= ' '))
    {
        idx++;
    }
    new offset = idx;
    new result[64];
    while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
    {
        result[idx - offset] = string[idx];
        idx++;
    }
    result[idx - offset] = EOS;
    return result;
}
Reply
#4

Danut, where do I put your code. Do i have to remove some of the old code. Please show me.
Reply
#5

Anybody have any ideas?!?

Please help
Reply
#6

Quote:
Originally Posted by AlecRae
Danut, where do I put your code. Do i have to remove some of the old code. Please show me.
He gave you a stock, meaning you put it at the bottom of your script, and reference to it from within your command.

I'm not sure if he intended for it to be bigstr, as the command is your script is bigstrtok, but i'd assume that's what he meant.

EDIT: Please refrain form double posting, edit the previous post instead.
Reply
#7

Can you please show me the code to use as i dont know how to reference it.
Reply
#8

Put the code Danut posted at the bottom of your script, and change "bigstrtok" in your code, to "bigstr"
Reply
#9

It still misses out the first word...
Reply
#10

That's because you use 2 strtok's one "hogs" the first word, and the second one takes what's left.

You have 2 things in there to detect if the player rights nothing.. see why that might be considered pointless? Try this:

pawn Код:
if(strcmp(cmd, "/ask", true) == 0) // Available for everyone: ask a q to admins
    {
        {
        question = bigstr(cmdtext,idx);
        if(!strlen(question)) return SendClientMessage(playerid, ORANGE, "USAGE: /ask [Question]");
        else
            {
            GetPlayerName(playerid, sendername, sizeof(sendername));
            new question[128];
            format(string, sizeof(string), "%s Asks A Question: '%s'", sendername,question);
            SendClientMessageToAdmins(ADMIN_RED, string,1);
            SendClientMessage(playerid, GREEN, "Your question has been sent to the current online admins. Thank you.");
            }
        }
        return 1;
    }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)