SA-MP Forums Archive
'Ask' Command Not Displaying Correctly? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: 'Ask' Command Not Displaying Correctly? (/showthread.php?tid=68979)



'Ask' Command Not Displaying Correctly? - Alec24 - 15.03.2009

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


Re: 'Ask' Command Not Displaying Correctly? - Zoopaman - 15.03.2009

question = bigstrtok(cmdtext,idx);

what's bigstrtok? maybe try the usual strtok?


Re: 'Ask' Command Not Displaying Correctly? - Danut - 15.03.2009

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



Re: 'Ask' Command Not Displaying Correctly? - Alec24 - 15.03.2009

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


Re: 'Ask' Command Not Displaying Correctly? - Alec24 - 15.03.2009

Anybody have any ideas?!?

Please help


Re: 'Ask' Command Not Displaying Correctly? - Weirdosport - 15.03.2009

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.


Re: 'Ask' Command Not Displaying Correctly? - Alec24 - 15.03.2009

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


Re: 'Ask' Command Not Displaying Correctly? - Weirdosport - 15.03.2009

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


Re: 'Ask' Command Not Displaying Correctly? - Alec24 - 15.03.2009

It still misses out the first word...


Re: 'Ask' Command Not Displaying Correctly? - Weirdosport - 15.03.2009

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