22.09.2013, 14:53
Hello. I've weird problem, because I want to compare string like cmdtext with regex value. As I (and PAWN) know - it's very hard (rather - impossible). But maybe I write what I want to do... So:
- I want to compare the regex string to a character array that contains the names of vehicles,
- I want to use the regex to short code and use it without loop,
Code which I've now:
Code of which I thought would work (but won't work):
How to do?
- I want to compare the regex string to a character array that contains the names of vehicles,
- I want to use the regex to short code and use it without loop,
Code which I've now:
pawn Код:
public OnPlayerCommandPerformed(playerid, cmdtext[], success) {
if(!success) {
for(new i; i < sizeof(gVehicleNames); i++) {
if(strlen(cmdtext) > 2 && !strcmp(cmdtext[1], gVehicleNames[i], true)) {
delete_free_space(cmdtext);
CreatePlayerVehicle(playerid, i + 400);
format(text, sizeof(text), "Vehicle {FF0000}%s{FFFFFF} created.", gVehicleNames[i]);
SendClientMessage(playerid, -1, text);
return true;
}
}
}
format(text, sizeof(text), "Server don't have a %s command.", cmdtext);
SendClientMessage(playerid, -1, text);
printf("%s wrote: %s", PlayerName(playerid), cmdtext);
return true;
}
pawn Код:
new RegEx: regex_string;
main() {
regex_build(\gVehicleNames\);
return false;
}
public OnPlayerCommandPerformed(playerid, cmdtext[], success) {
if(!success) {
if(strcmp(regex_string, cmdtext)) {
CreatePlayerVehicle(playerid, i + 400);
format(text, sizeof(text), "Vehicle {FF0000}%s{FFFFFF} created.", gVehicleNames[i]);
SendClientMessage(playerid, -1, text);
return true;
}
}
return true;
}