PHP Code:
#include <amxmodx>
#include <amxmisc>
#define VERSION "1.2"
#define WORDS_MAX_LEN 35
new g_pWordsCS; // CS = Case Sensitive.
new g_pSentencesCS; // CS = Case Sensitive.
new g_WordsCounterFile[76];
new SInfo[32];
new const SetinfotKey[] = " key";
public plugin_init()
{
}
public plugin_precache()
{
if(!g_WordsCounterFile[0])
{
get_configsdir(g_WordsCounterFile, charsmax(g_WordsCounterFile));
add(g_WordsCounterFile, charsmax(g_WordsCounterFile), "/topsetinfo");
if(!dir_exists(g_WordsCounterFile))
{
mkdir(g_WordsCounterFile);
}
add(g_WordsCounterFile, charsmax(g_WordsCounterFile), "/topsetinfo.ini");
}
if(!file_exists(g_WordsCounterFile))
{
new f1 = fopen(g_WordsCounterFile, "w")
fclose(f1);
}
}
public client_connect(id)
{
get_user_info(id, SetinfoKey, SInfo, sizeof SInfo - 1);
if(strlen(SInfo) > 0)
{
CountWords(SInfo);
client_cmd(id, "wait;setinfo %s 0",SetinfoKey);
}
}
CountWords(string[])
{
if(!file_exists(g_WordsCounterFile))
{
static f1 ; f1 = fopen(g_WordsCounterFile, "w");
fclose(f1);
return -1;
}
static Split[256], Words[128][20];
static iCount;
copy(Split, charsmax(Split), string);
iCount = 0;
while(Split[0])
{
strbreak(Split, Words[iCount++], charsmax(Words[]), Split, charsmax(Split));
}
static size ; size = file_size(g_WordsCounterFile, 1);
if(!size)
{
return -1;
}
static data[106], word[35], szCount[9], buffer[41];
static line, txtlen, count, j;
line = 0;
while(line < size && read_file(g_WordsCounterFile, line, data, charsmax(data), txtlen))
{
trim(data);
if(!data[0] || data[0] == ';' || equal(data, "//", 2))
{
line++;
continue;
}
if(data[0] == '^"')
{
// Remove the first '^"' to separate between the senence and it's counting.
replace(data, charsmax(data), "^"", "");
strtok(data, word, charsmax(word), szCount, charsmax(szCount), '^"');
trim(szCount);
if(!szCount[0])
{
count = 0;
format(buffer, charsmax(buffer), "^"%s^" 0", word);
write_file(g_WordsCounterFile, buffer, line);
}
else
{
count = str_to_num(szCount);
}
if(get_pcvar_num(g_pSentencesCS) ? equal(word, string) : equali(word, string))
{
format(buffer, charsmax(buffer), "^"%s^" %d", word, (count + 1));
write_file(g_WordsCounterFile, buffer, line);
break;
}
line++;
continue;
}
strbreak(data, word, charsmax(word), szCount, charsmax(szCount));
if(!word[0])
{
return -1;
}
if(!szCount[0])
{
format(buffer, charsmax(buffer), "%s 0", word);
write_file(g_WordsCounterFile, buffer, line);
}
count = str_to_num(szCount);
for(j = 0 ; j < iCount ; j++)
{
if(get_pcvar_num(g_pWordsCS) ? equal(Words[j], word) : equali(Words[j], word))
{
format(buffer, charsmax(buffer), "%s %d", Words[j], ++count);
write_file(g_WordsCounterFile, buffer, line);
}
}
line++;
}
return 1;
}
Some of the code is copied from that word counter plugin ...
@Exolent : Come on it was more than a week since my last post .. others bump it 3 times a day