another little question /changename cmd error special characters
#1

Hello, i dont know if i should make a thread for each question. Anyway here it goes...


I am making a /changename cmd wich is almost finished. The only missing part is the
part to detect if the player types a special character and give an error in that case. Because
if i /changename \\test, the .ini file will get bugged or it will delete itself, so i want to send a message saying "error"
when a player types "#$%&()=......" i could block this characters with the code bellow. However
i want to make it to detect the " and the \, wich i cannot use the same method as i used bellow because it
wont compile properly.


code used for the other special characters:
Код:
			if(strfind(tmp, "б", true) != -1 || strfind(tmp, "а", true) != -1 || strfind(tmp, "г", true) != -1 || strfind(tmp, "в", true) != -1) //returns 4 (!= -1 because -1 would be 'not found')
            {
            SendClientMessage(playerid, COLOR_CREAM, "ERROR.");
            return 1;
            }
			if(strfind(tmp, "й", true) != -1 || strfind(tmp, "и", true) != -1 || strfind(tmp, "к", true) != -1) //returns 4 (!= -1 because -1 would be 'not found')
            {
            SendClientMessage(playerid, COLOR_CREAM, "ERROR.");
            return 1;
            }
			if(strfind(tmp, "й", true) != -1 || strfind(tmp, "и", true) != -1 || strfind(tmp, "к", true) != -1) //returns 4 (!= -1 because -1 would be 'not found')
            {
            SendClientMessage(playerid, COLOR_CREAM, "ERROR.");
            return 1;
            }
			if(strfind(tmp, "у", true) != -1 || strfind(tmp, "т", true) != -1 || strfind(tmp, "х", true) != -1 || strfind(tmp, "ф", true) != -1) //returns 4 (!= -1 because -1 would be 'not found')
            {
            SendClientMessage(playerid, COLOR_CREAM, "ERROR.");
            return 1;
            }
			if(strfind(tmp, "ъ", true) != -1 || strfind(tmp, "щ", true) != -1 || strfind(tmp, "ы", true) != -1) //returns 4 (!= -1 because -1 would be 'not found')
            {
            SendClientMessage(playerid, COLOR_CREAM, "ERROR.");
            return 1;
            }
			if(strfind(tmp, "*", true) != -1 || strfind(tmp, "+", true) != -1 || strfind(tmp, "-", true) != -1 || strfind(tmp, "є", true) != -1) //returns 4 (!= -1 because -1 would be 'not found')
            {
            SendClientMessage(playerid, COLOR_CREAM, "ERROR.");
            return 1;
            }
			if(strfind(tmp, ",", true) != -1 || strfind(tmp, ";", true) != -1 || strfind(tmp, ":", true) != -1 || strfind(tmp, "<", true) != -1) //returns 4 (!= -1 because -1 would be 'not found')
            {
            SendClientMessage(playerid, COLOR_CREAM, "ERROR.");
            return 1;
            }
			if(strfind(tmp, ">", true) != -1 || strfind(tmp, "!", true) != -1 || strfind(tmp, "#", true) != -1 || strfind(tmp, "#", true) != -1) //returns 4 (!= -1 because -1 would be 'not found')
            {
            SendClientMessage(playerid, COLOR_CREAM, "ERROR.");
            return 1;
            }
			if(strfind(tmp, "$", true) != -1 || strfind(tmp, "%", true) != -1 || strfind(tmp, "&", true) != -1 || strfind(tmp, "/", true) != -1) //returns 4 (!= -1 because -1 would be 'not found')
            {
            SendClientMessage(playerid, COLOR_CREAM, "ERROR.");
            return 1;
            }
			if(strfind(tmp, "=", true) != -1 || strfind(tmp, "?", true) != -1 || strfind(tmp, "«", true) != -1 || strfind(tmp, "»", true) != -1) //returns 4 (!= -1 because -1 would be 'not found')
            {
            SendClientMessage(playerid, COLOR_CREAM, "ERROR.");
            return 1;
            }
			if(strfind(tmp, "'", true) != -1 || strfind(tmp, "Є", true) != -1 || strfind(tmp, "}", true) != -1 || strfind(tmp, "{", true) != -1) //returns 4 (!= -1 because -1 would be 'not found')
            {
            SendClientMessage(playerid, COLOR_CREAM, "ERROR.");
            return 1;
            }
			if(strfind(tmp, "з", true) != -1 || strfind(tmp, "Ш", true) != -1 || strfind(tmp, "Ж", true) != -1 || strfind(tmp, "Е", true) != -1) //returns 4 (!= -1 because -1 would be 'not found')
            {
            SendClientMessage(playerid, COLOR_CREAM, "ERROR.");
            return 1;
            }
Reply
#2

pawn Код:
~ strfind ( tmp , "\"" , true )//To "
~ strfind ( tmp , "\\" , true )//To \
Reply
#3

try this
pawn Код:
#define N_CENSORED 2 //number of censored words
#define N_CENSORED_LEN 32 //length of max string
static const Censored[N_CENSORED_LEN][(N_CENSORED_LEN + 1) char] = {
    !"а",
    !"б",
    !"й",
    !"и",
    !"у",
    !"т",
    !"ъ",
    !"щ",
};

stock ContainsCensored(const input[]) {
    for(new i = 0; i != N_CENSORED; ++i) {
        if(strfind(input, Censored[i], true) != -1)  return 1;
    }
    return 0;
}

//...
if(ContainsCensored(inputtext)) {
    SendClientMessage(playerid, COLOR_TOMATO, "Error: The text cannot contain swearwords/some characters!");
}
Reply
#4

Solved. thanks both
@LeMoi that wasn't what i was looking for but it came out usefull aswell.

@Juniiro3 that did the trick <3.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)