new matrix[128][128];stock Levenshtein_distance(string1[], string2[])//https://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#C{static x,y,s1len, s2len;s1len = strlen(string1);s2len = strlen(string2);matrix[0][0] = 0;for (x = 1; x <= s2len ; x++) matrix[x][0] = matrix[x-1][0] + 1; for(y = 1; y <= s1len; y++) matrix[0][y] = matrix[0][y-1] + 1; for (x = 1; x <= s2len ; x++){ for (y = 1; y <= s1len; y++) matrix[x][y] = MIN3(matrix[x-1][y] + 1,matrix[x][y-1] + 1,matrix[x-1][y-1] + _: !(string1[y-1] == string2[x-1]));}return(matrix[s2len][s1len]);}MIN3(a,b,c) return a<b?a<c?a:c:b<c?b:c;
main(){new result = Levenshtein_distance(\"fej\",\"fúj\");printf(\"%d\",result);//1 lesz,mivel 1 lépéssel lehet átalakítani.result = Levenshtein_distance(\"ember\",\"majom\");printf(\"%d\",result);//5 lesz,mivel az összes karaktert le kellene cserélni,result = Levenshtein_distance(\"test\",\"fesa\");printf(\"%d\",result);//2 lesz,mivel 2 karaktert kéne lecserélni.}
CMD:beszed(playerid,params[]){new string[128];format(string,128,\"beszed: %s\",params);SendClientMessage(playerid,-1,string);return 1;}public OnPlayerCommandPerformed(playerid, cmdtext[], success){ if(!success){ new magicnumber = floatround(strlen(cmdtext) * 0.4),i,buffer[32],best,bestmatch[32],match; while(GetPublicName(i, buffer)) { if(strcmp(buffer, \"cmd_\", false, 4) == 0) { strdel(buffer,0,3); buffer[0] = \'/\'; if( Levenshtein_distance(buffer,cmdtext) <= 3 && Levenshtein_distance(buffer,cmdtext) > best) { best = Levenshtein_distance(buffer,cmdtext); format(bestmatch,32,\"%s\",buffer); match = 1; } } i++; } if(match) { new string[64]; format(string,64,\"Erre gondoltál: %s ?\",bestmatch); SendClientMessage(playerid,-1,string); }else{ SendClientMessage(playerid,-1,\"Nincs ehhez hasonló parancs a szerveren.\"); }} return 1;}stock GetPublicName(idx, buffer[32])//Nero_3D { if(idx >= 0) { new publics, natives ; #emit lctrl 1 #emit const.alt 32 #emit sub.alt #emit stor.s.pri publics #emit add.c 4 #emit stor.s.pri natives #emit lref.s.pri natives #emit stor.s.pri natives #emit lref.s.pri publics #emit load.s.alt idx #emit shl.c.alt 3 #emit add #emit stor.s.pri publics if(publics < natives) { #emit lctrl 1 #emit move.alt #emit load.s.pri publics #emit add.c 4 #emit sub #emit stor.s.pri publics #emit lref.s.pri publics #emit sub #emit stor.s.pri natives for(idx = 0; ; natives += 4) { #emit lref.s.pri natives #emit stor.s.pri publics if((buffer[idx++] = publics & 0xFF) == EOS || (buffer[idx++] = publics >> 8 & 0xFF) == EOS || (buffer[idx++] = publics >> 16 & 0xFF) == EOS || (buffer[idx++] = publics >>> 24) == EOS) { return idx; } } } } return 0;}
Na ez egy igen hasznos szkript gratulálok!
Látszik te is érted a pawno-t. Köszönjük a publikálást.
Nagyon szépen kidolgoztad! Nekem nagyon tetszik ez a Script, gratulálok hozzá! Kapod a (+) -t