eh, first take a look here:
Code:
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
new gVersion[] = "0.1";
const TLEN = MAX_TEXT_LENGTH;
const DLEN = MAX_DATA_LENGTH;
const NLEN = MAX_NAME_LENGTH;
const CLEN = MAX_COMMAND_LENGTH;
const SECINMIN = 60;
const SECINHOUR = SECINMIN * 60;
const SECINDAY = SECINHOUR * 24;
const SECINMONTH = SECINDAY * 30;
const MAX_NAMES = 2000;
const MAX_MATCHES = 3;
new FILENAME[] = "seen_plugin.txt"; // here for save stuff
new namecount=0;
new namelist[MAX_NAMES][NLEN];
new timelist[MAX_NAMES];
new matches[MAX_MATCHES];
new oldest = 0x7fffffff;
new roundstart = 0;
const ROUND_START_LIMIT = 10;
public hook_say(HLCommand,HLData,HLUserName,UserIndex)
{
new Data[MAX_DATA_LENGTH];
new cmd[MAX_TEXT_LENGTH];
new name[MAX_TEXT_LENGTH];
convert_string(HLData,Data,MAX_DATA_LENGTH);
strsplit( Data, " ^"", cmd, MAX_TEXT_LENGTH, name, MAX_TEXT_LENGTH );
if (streq(cmd,"seen")) {
new text[TLEN];
new count;
if ( findonline(name) )
return PLUGIN_CONTINUE;
count += findseen(name);
switch ( count )
{
case 1:
{
new idx = matches[0];
new str[TLEN];
timeago(timelist[idx],str,TLEN);
snprintf(text,TLEN,"%s was here %s ago",
namelist[idx],str);
say(text);
}
case 2..MAX_MATCHES:
{
for (new i=0;i<count;i++)
{
new idx = matches[i];
new str[TLEN];
timeago(timelist[idx],str,TLEN);
snprintf(text,TLEN, "%s was here %s ago", namelist[idx],str);
say(text);
}
}
default: {
snprintf(text,TLEN,
"Be more specific. '%s' matches %d names",
name,count);
say(text);
}
}
}
return PLUGIN_CONTINUE;
}
stock abs( x )
{
if ( x < 0 )
return -x;
return x;
}
stock timeago(when,str[],len)
{
new a,b;
new s[2][] = { "s", "" };
new diff = abs(systemtime() - when);
if (diff < SECINMIN) {
snprintf(str,len, "%d second%s",
diff, s[diff==1]);
}
else if (diff < SECINHOUR) {
a = diff/SECINMIN;
b = diff%SECINMIN;
snprintf(str,len, "%d minute%s and %d second%s",
a, s[a==1], b, s[b==1]);
}
else if (diff < SECINDAY) {
a = diff/SECINHOUR;
b = (diff%SECINHOUR)/SECINMIN;
snprintf(str,len, "%d hour%s and %d minute%s",
a, s[a==1], b, s[b==1]);
}
else if (diff < SECINMONTH) {
a = diff/SECINDAY;
b = (diff%SECINDAY)/SECINHOUR;
snprintf(str,len, "%d day%s and %d hour%s",
a, s[a==1], b, s[b==1]);
}
else {
a = diff/SECINMONTH;
b = (diff%SECINMONTH)/SECINDAY;
snprintf(str,len, "%d month%s and %d day%s",
a, s[a==1], b, s[b==1]);
}
}
stock findseen(name[]){
new i;
new count = 0;
for (i=0;i<namecount;i++) {
if(!strcasecmp(namelist[i],name)) {
matches[0] = i;
return 1;
}
}
for (i=0;i<namecount;i++) {
if(-1!=strcasestr(namelist[i],name)) {
matches[count++] = i;
if ( count == MAX_MATCHES )
return MAX_MATCHES+1;
}
}
return count;
}
stock findonline(name[]){
new i;
new players = maxplayercount();
new count=0;
new player[NLEN];
new text[TLEN];
for (i=1;i<=players;i++) {
if(playerinfo(i,player,MAX_NAME_LENGTH)) {
if (!strcasecmp(player,name)) {
snprintf(text,TLEN,"%s is online now",player);
say(text);
return 1;
}
}
}
for (i=1;i<=players;i++) {
if(playerinfo(i,player,MAX_NAME_LENGTH)) {
if (strcasestr(player,name)!=-1) {
snprintf(text,TLEN,"%s is online now",player);
say(text);
count++;
if ( count == MAX_MATCHES )
return MAX_MATCHES+1;
}
}
}
return count;
}
stock storetime( name[] ) {
new i;
new now = systemtime();
new firstavail=-1;
new str[TLEN];
for (i=0;i<namecount;i++) {
if(!strcmp(name,namelist[i])) {
timelist[i] = now;
snprintf(str,TLEN,"%s\%d",namelist[i],timelist[i]);
writefile(FILENAME,str,i+1);
break;
}
else if ( (timelist[i]==0) && (firstavail == -1) )
firstavail = i;
}
if ( i==namecount ) {
if ( namecount>=MAX_NAMES ) {
if ( firstavail != -1 )
i = firstavail;
else
return PLUGIN_CONTINUE;
}
else
namecount++;
strcpy(namelist[i],name,NLEN);
timelist[i]=now;
snprintf(str,TLEN,"%s\%d",name,now);
writefile(FILENAME,str,i+1);
}
return 1;
}
public plugin_disconnect(HLUserName,UserIndex)
{
new name[NLEN];
convert_string(HLUserName,name,DLEN);
storetime(name);
return PLUGIN_CONTINUE;
}
public plugin_connect(HLUserName,HLIP,UserIndex)
{
new name[NLEN];
new now = systemtime();
if ( now > roundstart + ROUND_START_LIMIT ) {
convert_string(HLUserName,name,DLEN);
storetime(name);
}
return PLUGIN_CONTINUE;
}
stock loadnames() {
new i;
new str[TLEN];
new num[NLEN];
new t;
new empty=0;
roundstart = systemtime();
for (i=0;i<MAX_NAMES;i++) {
if ( !readfile(FILENAME,str,i+1,TLEN) )
break;
strsplit(str,"\",namelist[i],NLEN,num,NLEN);
t = strtonum(num);
timelist[i]=t;
if ( t==0 )
empty++;
else if ( t < oldest )
oldest = t;
}
namecount = i;
if ( i < MAX_NAMES )
empty += MAX_NAMES - i;
if ( empty < MAX_NAMES / 10 ) {
new cleared = 0;
new now = systemtime();
new limit = oldest + ((now-oldest) / 5);
for (i=0;i<namecount;i++) {
if ( timelist[i] < limit ) {
timelist[i] = 0;
cleared++;
}
}
snprintf(str,TLEN,"%d seen slots cleared",cleared);
log(str);
}
}
public plugin_init() {
plugin_registerinfo("eh","who else",gVersion);
plugin_registercmd("say","hook_say",0);
loadnames();
return PLUGIN_CONTINUE;
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
*/
If have anybody a suggestion to optimize this, i'm not sure if is the best coding to save on file etc
On server it's works, buy anyway
Thanks