SA-MP Forums Archive
Separate the cmdtext into word - 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: Separate the cmdtext into word (/showthread.php?tid=377731)



Separate the cmdtext into word - Angala - 15.09.2012

Hi, I want to read the cmdtxt but separate by words, for example:

/call 34 Angala Unity I want to see you in Unity. Bye.

When the player send this I want to send a message (I want to see you in Unity. Bye.) with title (Unity) the sender name(Angala) to the playerid (34)

To do that I need to separate all the cmdtext, I have done a code to put the cmdtext in varibles like:

cmd1 = "/call"
cmd2 = "34"
cmd3 = "Angala"
cmd4 = "Car"
cmd5 = "I want to see you in Unity. Bye."

This is the code:

Код:
new ind = 0, tempind = 0, cmdN = 1, cmd1[50], cmd2[50], cmd3[50], cmd4[50], cmd5[200];
EmpWhile:
while(cmdtext[ind] != ' ') //This is to put on ind the number of chars before a space.
{
if(ind + 1 >= strlen(cmdtext)) //If ind is more than the length the while exit.
{
goto FinWhile;
}
ind = ind + 1;
}
while(tempind != ind) //here tempind is the first char, ind is the las char.
{
//cmdN is a variable that have the word that is reading 1, 2, 3, 4, or 5.
if(cmdN == 1) {cmd1[tempind] = cmdtext[tempind];} 
if(cmdN == 2) {cmd2[tempind] = cmdtext[tempind];}
if(cmdN == 3) {cmd3[tempind] = cmdtext[tempind];}
if(cmdN == 4) {cmd4[tempind] = cmdtext[tempind];}
//if cmdN is 5, ind value is the maximun value of cmdtext, because cmd5 is the rest of cmdtext.
if(cmdN == 5) {cmd5[tempind] = cmdtext[tempind]; ind = strlen(cmdtext);}
tempind = tempind + 1;
}
cmdN = cmdN + 1;
ind = ind + 1;
goto EmpWhile;
FinWhile:
//this is because if the cmdtext is only one word it came here without put somthing on cmd1
while(tempind != ind)
{
if(cmdN == 1) {cmd1[tempind] = cmdtext[tempind];}
tempind = tempind + 1;
}
After the code I have put a control code with messages:

Код:
SendClientMessage(playerid, COLOR_VERDE, cmd1);
SendClientMessage(playerid, COLOR_VERDE, cmd2);
SendClientMessage(playerid, COLOR_VERDE, cmd3);
SendClientMessage(playerid, COLOR_VERDE, cmd4);
SendClientMessage(playerid, COLOR_VERDE, cmd5);
The problem is, if I enter the comand "/call 34 Angala Unity I want to see you in Unity. Bye." I only see the cmd1 that is "/call" the rest of variables are empty

What is the error? or if you know how to do the thing I want to do, please help me


Respuesta: Re: Separate the cmdtext into word - Angala - 15.09.2012

Quote:
Originally Posted by ******
Посмотреть сообщение
Look up sscanf - that's how 99% of people do this now as that's exactly what it was designed to simplify.
Yes, I have seen this on wiki.samp, but I dont understand exactly how it run :S
Also I have seen that is a very big code, I want to make this so I understand all the code on my server.