02.01.2010, 23:33
You only need to split the string
if you use it
at OnPlayerText
at OnPlayerCommandText
pawn Code:
new day, month, year = -1 = month = day;
for(new c = 0/* Startpoint */, s = c; text[c] != EOS; c++) //the text should start at the date
if(text[c] == '/')
{
if(day == -1)
{
if((c - s) > 2) break;
for(day = 0; s < c; s++)
day = day * 10 + (text - '0');
s++;
}
else if(month == -1)
{
if((c - s) > 2) break;
for(month = 0; s < c; s++)
month = month * 10 + (text - '0');
s++;
}
}
else if(text[c] == ' ')
{
if(month == -1 || day == -1) break;
else if((c - s) > 4) break;
for(year = 0; s < c; s++)
year = year * 10 + (text - '0');
break;
}
else if(!('0' <= text[c] <= '9')) break;
if(year == -1 || month == -1 || day == -1) return 0;
at OnPlayerText
pawn Code:
if(PlayerTypesDate[playerid])
{
if(!('0' <= text[0] <= '9')) return SendClientMessage(playerid, 0xFFFFFFAA, "Enter the date in the format dd/mm/yyyy");
//code above - c = 0
}
pawn Code:
if(strcmp("/command", cmdtext, true, 8 /* strlen("/command") */) == 0)
{
if(cmdtext[8/* strlen("/command") */] != ' ' || cmdtext[9/* strlen("/command") + 1 */] == EOS)
return SendClientMessage(playerid, 0xFFFFFFAA, "Enter the date in the format dd/mm/yyyy");
//code above - c = 9 /* strlen("/command") + 1 */
}