
   /* AMX Mod script.
   *
   * (c) Copyright 2002, OLO
   * This file is provided as is (no warranties).
   *
   * Credits:
   * This is a modified version of the
   * PsychoSounds Plugin by PsychoGuard.
   *
   */
   #include <amxmod>
   #define MAX_WORDS    20
   #define MAX_REPLY    20
   #define MAX_STR_LENGTH  64
   new words[MAX_WORDS][MAX_STR_LENGTH];
   new replys[MAX_REPLY][MAX_STR_LENGTH];
   new num_reply[MAX_WORDS];
   new word2reply[MAX_WORDS][MAX_REPLY];
   new word_count;
   new reply_count;
   reset_matrix() {
       word_count = 0;
       reply_count = 0;
       for (new i = 0; i < MAX_WORDS; i++) {
       num_reply[i] = 0;
       for (new j = 0; j < MAX_REPLY; j++) {
           word2reply[i][j] = 0;
       }
       }
   }
   public list_reply() {
       new line[256];
       for (new i = 0; i < word_count; i++) {
       format(line, 256, "%-20s ", words[i]);
       for (new j = 0; j < MAX_REPLY; j++) {
           if (word2reply[i][j]) {
           add(line, 256, replys[j]);
           add(line, 256, " ");
           }
       }
       server_print(line);
       }
   }
   public reply() {
       if (read_argc() != 3) {
       server_print("Usage: pd_reply <keyword> <reply>");
       return PLUGIN_HANDLED;
       }
       new keyword[MAX_STR_LENGTH];
       new rep[MAX_STR_LENGTH];
       read_argv(1, keyword, MAX_STR_LENGTH);
       read_argv(2, rep, MAX_STR_LENGTH);
       if (! add_reply(keyword, rep)) {
       log_message("[PD] Too many replys or words.");
       }
       return PLUGIN_HANDLED;
   }
   add_reply(keyword[], reply[]) {
       new word_index = find_word_or_append(keyword);
       new reply_index = find_reply_or_append(reply);
       if (word_index >= 0 && reply_index >= 0) {
       word2reply[word_index][reply_index] = 1;
       num_reply[word_index]++;
       return 1;
       }
       return 0;
   }
   find_word_or_append(word[]) {
       new index = find_word(word);
       if (index != -1) {
       return index;
       } else {
       if (word_count < MAX_WORDS) {
           copy(words[word_count], MAX_STR_LENGTH, word);
           word_count++;
           return word_count - 1;
       }
       }
       return -1;
   }
   find_word(word[]) {
       for (new i = 0; i < word_count; i++) {
       if (equal(word, words[i])) {
           return i;
       }
       }
       return -1;
   }
   find_reply_or_append(reply[]) {
       new index = find_reply(reply);
       if (index != -1) {
       return index;
       } else {
       if (reply_count < MAX_REPLY) {
           copy(replys[reply_count], MAX_STR_LENGTH, reply);
           reply_count++;
           return reply_count - 1;
       }
       }
       return -1;
   }
   find_reply(reply[]) {
       for (new i = 0; i < reply_count; i++) {
       if (equal(reply, replys[i])) {
           return i;
       }
       }
       return -1;
   }
   public handle_say(id) {
       new word[MAX_STR_LENGTH];
       read_argv(1, word, MAX_STR_LENGTH);
       new index = find_word(word);
       if (index == -1) {
       return PLUGIN_CONTINUE;
       }
       new random_reply = random_num(1, num_reply[index]);
       new current_reply = 0;
       for (new i = 0; i < reply_count; i++) {
      new hostname[64]
      get_cvar_string("hostname",hostname,63)
      replace(replys[i],64,"%hostname%",hostname)
      new currm[24]
      get_mapname(currm,23);
      replace(replys[i],64,"%currmap%",currm)
      new ctime[40]
      get_time("%m/%d/%Y - %H:%M:%S",ctime,39)
      replace(replys[i],64,"%time%",ctime)
      new mod[16]
      get_modname(mod,15)
      replace(replys[i],64,"%modname%",mod)
      new cnext[16]
      get_cvar_string("amx_nextmap",cnext,15)
      replace(replys[i],64,"%nextmap%",cnext);

      new tmlf[20]
      get_cvar_string("amx_timeleft",tmlf,19)
      replace(replys[i],64,"%timeleft%",tmlf);
      new reserved[20]
      get_cvar_string("amx_reserved_slots",reserved,19)
      replace(replys[i],64,"%rslots%",reserved);

      new bre[3] = "^n"
      if (get_cvar_num("pd_reply_private")==1) {
      replace(replys[i],64,"%break%"," ");
      } else{
      replace(replys[i],64,"%break%",bre);
      }
      if (word2reply[index][i]) {
           current_reply++;
           if (current_reply == random_reply) {
           if (get_cvar_num("pd_reply_private")==1) {
           client_print(0,print_chat,"<Server> %s", replys[i]);
           } else {
               new players[32];
               new player_count;
                       get_players(players, player_count, "");
               for (new p = 0; p < player_count; p++) {
           set_hudmessage(220,80,0,  0.05, 0.50, 2, 0.1, 4.0, 0.02, 0.02,
   4)
           show_hudmessage(players[p],"%s", replys[i]);
               }
           }
           }
       }
       }
       return PLUGIN_HANDLED;
   }
   public plugin_init() {
       register_plugin("Auto Reply", "0.2", "bardelot");
       register_srvcmd("pd_reply", "reply");
       register_clcmd("say", "handle_say");
       register_clcmd("amx_reply","list_reply",ADMIN_LEVEL_A,"amx_reply
   shows the commands in the reply.cfg file.")
       register_cvar("pd_reply_private", "0");
       reset_matrix();
       server_cmd("exec addons/amx/reply.cfg");
       return PLUGIN_CONTINUE;
   }
