Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Filter include 1.4
- Made by: Haruka
- Usage:
- Load_Filter(const path_name[])
- ^ Load a filter into our list
- filter(const bad_word[], censored_output[], const delimeter_checks[] = " ", const delimteter_censor_str[] = "*", just_check = 1)
- ^ Check string and replace it into your variable
- IsTextContainsBad(const filter_content[], const parameter_content[])
- ^ Check if text contains bad (return false if not bad, true if string is contain bad word)
- Example:
- public OnGameModeInt()
- {
- Load_Filter("/core/bad_word/list.txt");
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- if(IsTextContainsBad(playername))
- return Kick(playerid);
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- filter(text, safetext);
- SendClientMessage(playerid, -1, "%s says: %s", GetName(playerid), safetext);
- return 0;
- }
- Note:
- This include may be slowest, because i don't know #emit stuff, you can translate this to #emit
- or amx thing like Slice did.
- And also this include still didn't tested yet, but i guaranted filter function works 100% legit
- With no false detection (also weak on number).
- And make sure your list are ALL UPPERCASE OTHERWISE IT WILL BROKK I GUESS?
- */
- #include <a_samp>
- #tryinclude <strlib>
- #if !defined STRLIB_INC
- #error The strlib library is required, get it here: github.com/oscar-broman/strlib
- #endif
- #if !defined MAX_BAD_WORDS
- #define MAX_BAD_WORDS (255)
- #endif
- #if defined MAX_WORDS
- #undef MAX_WORDS
- #define MAX_WORDS (32)
- #else
- #define MAX_WORDS (32)
- #endif
- // native filter(const bad_word[], censored_output[], const delimeter_checks[] = " ", const delimteter_censor_str[] = "*", just_check = 1)
- new gArrPenyaring[MAX_BAD_WORDS][128];
- forward Load_Filter(const path_name[]);
- public Load_Filter(const path_name[])
- {
- new
- loadx = 0,
- strBuilder[128],
- File:load_scripts = fopen(path_name, io_read);
- if (!load_scripts) {
- print("[FILTER.INC]: path not found, please put your path to scriptfiles/your_path");
- return 0;
- }
- while(fread(load_scripts, strBuilder))
- {
- if (!str_containSpecialChar(strBuilder)) {
- format(gArrPenyaring[loadx], sizeof(gArrPenyaring), strBuilder);
- loadx++;
- }
- }
- fclose(load_scripts);
- printf("[FILTER.INC]: Successfully load %d word filter into databases.", loadx);
- return 1;
- }
- stock bool:IsTextContainsBad(const filter_content[], const parameter_content[])
- {
- new gXChecker[1];
- if (!filter(filter_content, gXChecker, parameter_content, " ", 1))
- return false;
- return true;
- }
- stock filter(const bad_word[], censored_output[], const delimeter_checks[] = " ", const delimteter_censor_str[] = "*", just_check = 0)
- {
- new
- cell_count = 0,
- same_check = 0,
- xlen = 0;
- new
- str_same[24],
- seperator[10][64],
- lllxoop[64];
- if (sizeof(gArrPenyaring) < 1) {
- print("[FILTER.INC]: Put Load_Filter into OnGameModeInit or OnFilterScriptInit !");
- return 0;
- }
- strexplode(seperator, bad_word, delimeter_checks);
- if (bad_word[0] == 0 || strlen(bad_word) > 128)
- return 0;
- for (new i = 0; i < sizeof(seperator); i ++)
- {
- str_upper(seperator[i], strlen(seperator[i]));
- for (new k = 0; k < strlen(seperator[i]); k ++)
- {
- xlen = k + 1;
- if (seperator[i][k] == seperator[i][xlen]) {
- str_same[k] = seperator[i][xlen];
- xlen = k;
- break;
- }
- }
- same_check = strcount(seperator[i], str_same[xlen], .ignorecase = true, .count_overlapped = true);
- strdel(seperator[i], xlen, same_check);
- if (strfind(seperator[i], str_same[xlen], true, xlen+1) != -1)
- strdel(seperator[i], xlen+1, same_check+3);
- break;
- }
- for (new m = 0; m < sizeof(seperator); m ++) {
- if (m < sizeof(seperator)) {
- for (new j = 0; j < sizeof(gArrPenyaring); j ++) {
- if (strfind(gArrPenyaring[j], seperator[m], true) != -1) {
- cell_count++;
- }
- }
- }
- }
- if (!cell_count) {
- return 0;
- }
- if (!just_check)
- strins(censored_output, delimteter_censor_str, 0, sizeof(bad_word));
- return 1;
- }
- stock str_upper(str[], dest)
- {
- while(dest--)
- str[dest] = toupper(str[dest]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement