13.07.2014, 19:39
Sem sscanf ou qualquer processador de comandos:
(Nгo esqueзas de colocar no final do GameMode)
PHP код:
new
mycmd[] = "/test [testeprimeiro,testesegundo,testeterceiro][testequarto][testequinto]",
param[5][20]
;
strdel(mycmd, 0, (strfind(mycmd, "[")) + 1);
format(param[0], 20, getParam(mycmd, 0, ','));
format(param[1], 20, getParam(mycmd, 1, ','));
// ~>Aqui comeзa a putaria.
static
i, l_pos
;
i = 0;
while(mycmd[i] ^ '\0'){
if(mycmd[i] == ',') l_pos = i;
i ++;
}
strdel(mycmd, 0, l_pos + 1);
strmid(param[2], mycmd, 0, strfind(mycmd, "]"));
strdel(mycmd, 0,strfind(mycmd, "]") +2);
strmid(param[3], mycmd, 0, strfind(mycmd, "]"));
strdel(mycmd, 0,strfind(mycmd, "]") +2);
strdel(mycmd, strfind(mycmd, "]"), strlen(mycmd));
format(param[4], 20, mycmd);
// ===============================================
printf("Parвmetro 0 ----> %s", param[0]);
printf("Parвmetro 1 ----> %s", param[1]);
printf("Parвmetro 2 ----> %s", param[2]);
printf("Parвmetro 3 ----> %s", param[3]);
printf("Parвmetro 4 ----> %s", param[4]);
// ==============================================
pawn Код:
stock getParam(intstring[], parameter, delim){ // Suyann Dбcio
static
szStringOut[128],
Loop_Interator,
LastWorldSize,
String_Size,
Parameters
;
// Setting:
String_Size = strlen(intstring);
// Resetting:
szStringOut[0] = EOS;
Loop_Interator = 0 ;
LastWorldSize = 0 ;
Parameters = 0 ;
for ( ; Loop_Interator != String_Size; ++Loop_Interator){
if(intstring[Loop_Interator] == delim){
if(Parameters == parameter){
strmid(szStringOut, intstring,(parameter != 0 ? (LastWorldSize + 1) : (LastWorldSize)), Loop_Interator);
break;
}
Parameters ++;
LastWorldSize = Loop_Interator;
}
}
return szStringOut;
}