[Issue] Regex and string compare - how to do? - 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: [Issue] Regex and string compare - how to do? (
/showthread.php?tid=465483)
[Issue] Regex and string compare - how to do? -
Dystans - 22.09.2013
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:
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;
}
Code of which I thought would work (but won't work):
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;
}
How to do?