// statlog command v0.2
// Submitted by Wonder
// Syntax: statlog <userid or team identifier> <event>
block load
{
  es_xsetinfo _tempcore 0
  es_xexists _tempcore command statlog
  es es_xif (server_var(_tempcore) == 0) do
  {
    es_xregcmd statlog corelib/statlog/statlog "Logs useful information for stat trackers (like HLstatsX) and sends events to scripts."
  }
  es_xsetinfo _sl_game 0
  es_xsetinfo _sl_a1 0
  es_xsetinfo _sl_a2 0
  es_xsetinfo _sl_name 0
  es_xsetinfo _sl_steamid 0
  es_xsetinfo _sl_team 0
  es_xsetinfo _sl_oldesc 0
  es_xsetinfo _sl_script 0
  es_xsetinfo _statlog_userid 0
  es_xsetinfo _statlog_event 0
}
block statlog
{
  es_xgetgame _sl_game
  es es_xif (Counter-Strike in server_var(_sl_game)) do
  {
    es_xgetargv _sl_a1 1
    es es_xif (server_var(_sl_a1) == #t) do
    {
      es_xgetargv _sl_a2 2
      isnull _tempcore _sl_a2
      es es_xif (server_var(_tempcore) == 0) do
      {
        es_xcopy _sl_oldesc eventscripts_escapechars
        es_xsetinfo eventscripts_escapechars "<> _-E"
        es es_xlogq Team TERRORIST triggered server_var(_sl_a2)
        es_xcopy eventscripts_escapechars _sl_oldesc
        es_xcreatescriptlist _statlog_scripts
        es es_xforeachkey _sl_script in _statlog_scripts "es_xsetinfo _statlog_userid #t;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
        es_xkeygroupdelete _statlog_scripts
      }
      es_xelse do
      {
        es_xdbgmsg 0 [statlog] You must provide an event!
      }
    }
    es_xelse do
    {
      es es_xif (server_var(_sl_a1) == #ct) do
      {
        es_xgetargv _sl_a2 2
        isnull _tempcore _sl_a2
        es es_xif (server_var(_tempcore) == 0) do
        {
          es_xcopy _sl_oldesc eventscripts_escapechars
          es_xsetinfo eventscripts_escapechars "<> _-C"
          es es_xlogq Team CT triggered server_var(_sl_a2)
          es_xcopy eventscripts_escapechars _sl_oldesc
          es_xcreatescriptlist _statlog_scripts
          es es_xforeachkey _sl_script in _statlog_scripts "es_xsetinfo _statlog_userid #ct;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
          es_xkeygroupdelete _statlog_scripts
        }
        es_xelse do
        {
          es_xdbgmsg 0 [statlog] You must provide an event!
        }
      }
      es_xelse do
      {
        es_xsetinfo _tempcore 0
        es es_xexists _tempcore userid server_var(_sl_a1)
        es es_xif (server_var(_tempcore) == 1) do
        {
          es_xgetargv _sl_a2 2
          isnull _tempcore _sl_a2
          es es_xif (server_var(_tempcore) == 0) do
          {
            es es_xgetplayername _sl_name server_var(_sl_a1)
            es es_xgetplayersteamid _sl_steamid server_var(_sl_a1)
            es es_xgetplayerteam _sl_team server_var(_sl_a1)
            es es_xif (server_var(_sl_team) == 2) do
            {
              es es_xformat _tempcore %1<%2><%3><TERRORIST> server_var(_sl_name) server_var(_sl_a1) server_var(_sl_steamid)
              es_xcopy _sl_oldesc eventscripts_escapechars
              es_xsetinfo eventscripts_escapechars "<> _-"
              es es_xlogq server_var(_tempcore) triggered server_var(_sl_a2)
              es_xcopy eventscripts_escapechars _sl_oldesc
              es_xcreatescriptlist _statlog_scripts
              es es_xforeachkey _sl_script in _statlog_scripts "es_xgetargv _statlog_userid 1;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
              es_xkeygroupdelete _statlog_scripts
            }
            es_xelse do
            {
              es es_xif (server_var(_sl_team) == 3) do
              {
                es es_xformat _tempcore %1<%2><%3><CT> server_var(_sl_name) server_var(_sl_a1) server_var(_sl_steamid)
                es_xcopy _sl_oldesc eventscripts_escapechars
                es_xsetinfo eventscripts_escapechars "<> _-"
                es es_xlogq server_var(_tempcore) triggered server_var(_sl_a2)
                es_xcopy eventscripts_escapechars _sl_oldesc
                es_xcreatescriptlist _statlog_scripts
                es es_xforeachkey _sl_script in _statlog_scripts "es_xgetargv _statlog_userid 1;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
                es_xkeygroupdelete _statlog_scripts
              }
              es_xelse do
              {
                es_xdbgmsg 0 [statlog] The player must be on a team to log stats!
              }
            }
          }
          es_xelse do
          {
            es_xdbgmsg 0 [statlog] You must provide an event!
          }
        }
        es_xelse do
        {
          es_xdbgmsg 0 [statlog] Inexistant userid provided!
        }
      }
    }
  }
  es_xelse do
  {
    es es_xif ("Day of Defeat" in server_var(_sl_game)) do
    {
      es_xgetargv _sl_a1 1
      es es_xif (server_var(_sl_a1) == #a) do
      {
        es_xgetargv _sl_a2 2
        isnull _tempcore _sl_a2
        es es_xif (server_var(_tempcore) == 0) do
        {
          es_xcopy _sl_oldesc eventscripts_escapechars
          es_xsetinfo eventscripts_escapechars "<> _-A"
          es es_xlogq Team Allies triggered server_var(_sl_a2)
          es_xcopy eventscripts_escapechars _sl_oldesc
          es_xcreatescriptlist _statlog_scripts
          es es_xforeachkey _sl_script in _statlog_scripts "es_xsetinfo _statlog_userid #a;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
          es_xkeygroupdelete _statlog_scripts
        }
        es_xelse do
        {
          es_xdbgmsg 0 [statlog] You must provide an event!
        }
      }
      es_xelse do
      {
        es es_xif (server_var(_sl_a1) == #x) do
        {
          es_xgetargv _sl_a2 2
          isnull _tempcore _sl_a2
          es es_xif (server_var(_tempcore) == 0) do
          {
            es_xcopy _sl_oldesc eventscripts_escapechars
            es_xsetinfo eventscripts_escapechars "<> _-A"
            es es_xlogq Team Axis triggered server_var(_sl_a2)
            es_xcopy eventscripts_escapechars _sl_oldesc
            es_xcreatescriptlist _statlog_scripts
            es es_xforeachkey _sl_script in _statlog_scripts "es_xsetinfo _statlog_userid #x;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
            es_xkeygroupdelete _statlog_scripts
          }
          es_xelse do
          {
            es_xdbgmsg 0 [statlog] You must provide an event!
          }
        }
        es_xelse do
        {
          es_xsetinfo _tempcore 0
          es es_xexists _tempcore userid server_var(_sl_a1)
          es es_xif (server_var(_tempcore) == 1) do
          {
            es_xsetinfo _tempcore 0
            es es_xexists _tempcore userid server_var(_sl_a1)
            es es_xif (server_var(_tempcore) == 1) do
            {
              es_xgetargv _sl_a2 2
              isnull _tempcore _sl_a2
              es es_xif (server_var(_tempcore) == 0) do
              {
                es es_xgetplayername _sl_name server_var(_sl_a1)
                es es_xgetplayersteamid _sl_steamid server_var(_sl_a1)
                es es_xgetplayerteam _sl_team server_var(_sl_a1)
                es es_xif (server_var(_sl_team) == 2) do
                {
                  es es_xformat _tempcore %1<%2><%3><Allies> server_var(_sl_name) server_var(_sl_a1) server_var(_sl_steamid)
                  es_xcopy _sl_oldesc eventscripts_escapechars
                  es_xsetinfo eventscripts_escapechars "<> _-"
                  es es_xlogq server_var(_tempcore) triggered server_var(_sl_a2)
                  es_xcopy eventscripts_escapechars _sl_oldesc
                  es_xcreatescriptlist _statlog_scripts
                  es es_xforeachkey _sl_script in _statlog_scripts "es_xgetargv _statlog_userid 1;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
                  es_xkeygroupdelete _statlog_scripts
                }
                es_xelse do
                {
                  es es_xif (server_var(_sl_team) == 3) do
                  {
                    es es_xformat _tempcore %1<%2><%3><Axis> server_var(_sl_name) server_var(_sl_a1) server_var(_sl_steamid)
                    es_xcopy _sl_oldesc eventscripts_escapechars
                    es_xsetinfo eventscripts_escapechars "<> _-"
                    es es_xlogq server_var(_tempcore) triggered server_var(_sl_a2)
                    es_xcopy eventscripts_escapechars _sl_oldesc
                    es_xcreatescriptlist _statlog_scripts
                    es es_xforeachkey _sl_script in _statlog_scripts "es_xgetargv _statlog_userid 1;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
                    es_xkeygroupdelete _statlog_scripts
                  }
                  es_xelse do
                  {
                    es_xdbgmsg 0 [statlog] The player must be on a team to log stats!
                  }
                }
              }
              es_xelse do
              {
                es_xdbgmsg 0 [statlog] You must provide an event!
              }
            }
            es_xelse do
            {
              es_xdbgmsg 0 [statlog] Inexistant userid provided!
            }
          }
        }
      }
    }
    es_xelse do
    {
      es es_xif (server_var(_sl_game) == "Half-Life 2 Deathmatch") do
      {
        es_xgetargv _sl_a1 1
        es_xsetinfo _tempcore 0
        es es_xexists _tempcore userid server_var(_sl_a1)
        es es_xif (server_var(_tempcore) == 1) do
        {
          es_xgetargv _sl_a2 2
          isnull _tempcore _sl_a2
          es es_xif (server_var(_tempcore) == 0) do
          {
            es es_xgetplayername _sl_name server_var(_sl_a1)
            es es_xgetplayersteamid _sl_steamid server_var(_sl_a1)
            es es_xformat _tempcore %1<%2><%3><Unassigned> server_var(_sl_name) server_var(_sl_a1) server_var(_sl_steamid)
            es_xcopy _sl_oldesc eventscripts_escapechars
            es_xsetinfo eventscripts_escapechars "<> _-"
            es es_xlogq server_var(_tempcore) triggered server_var(_sl_a2)
            es_xcopy eventscripts_escapechars _sl_oldesc
            es_xcreatescriptlist _statlog_scripts
            es es_xforeachkey _sl_script in _statlog_scripts "es_xgetargv _statlog_userid 1;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
            es_xkeygroupdelete _statlog_scripts
          }
          es_xelse do
          {
            es_xdbgmsg 0 [statlog] You must provide an event!
          }
        }
        es_xelse do
        {
          es_xdbgmsg 0 [statlog] Inexistant userid provided!
        }
      }
      es_xelse do
      {
        es es_xif (server_var(_sl_game) == Deathmatch) do
        {
          es_xgetargv _sl_a1 1
          es_xsetinfo _tempcore 0
          es es_xexists _tempcore userid server_var(_sl_a1)
          es es_xif (server_var(_tempcore) == 1) do
          {
            es_xgetargv _sl_a2 2
            isnull _tempcore _sl_a2
            es es_xif (server_var(_tempcore) == 0) do
            {
              es es_xgetplayername _sl_name server_var(_sl_a1)
              es es_xgetplayersteamid _sl_steamid server_var(_sl_a1)
              es es_xformat _tempcore %1<%2><%3><Unassigned> server_var(_sl_name) server_var(_sl_a1) server_var(_sl_steamid)
              es_xcopy _sl_oldesc eventscripts_escapechars
              es_xsetinfo eventscripts_escapechars "<> _-"
              es es_xlogq server_var(_tempcore) triggered server_var(_sl_a2)
              es_xcopy eventscripts_escapechars _sl_oldesc
              es_xcreatescriptlist _statlog_scripts
              es es_xforeachkey _sl_script in _statlog_scripts "es_xgetargv _statlog_userid 1;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
              es_xkeygroupdelete _statlog_scripts
            }
            es_xelse do
            {
              es_xdbgmsg 0 [statlog] You must provide an event!
            }
          }
          es_xelse do
          {
            es_xdbgmsg 0 [statlog] Inexistant userid provided!
          }
        }
        es_xelse do
        {
          es es_xif (server_var(_sl_game) == "Team Deathmatch") do
          {
            es_xgetargv _sl_a1 1
            es es_xif (server_var(_sl_a1) == #c) do
            {
              es_xgetargv _sl_a2 2
              isnull _tempcore _sl_a2
              es es_xif (server_var(_tempcore) == 0) do
              {
                es_xcopy _sl_oldesc eventscripts_escapechars
                es_xsetinfo eventscripts_escapechars "<> _-C"
                es es_xlogq Team Combine triggered server_var(_sl_a2)
                es_xcopy eventscripts_escapechars _sl_oldesc
                es_xcreatescriptlist _statlog_scripts
                es es_xforeachkey _sl_script in _statlog_scripts "es_xsetinfo _statlog_userid #c;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
                es_xkeygroupdelete _statlog_scripts
              }
              es_xelse do
              {
                es_xdbgmsg 0 [statlog] You must provide an event!
              }
            }
            es_xelse do
            {
              es es_xif (server_var(_sl_a1) == #r) do
              {
                es_xgetargv _sl_a2 2
                isnull _tempcore _sl_a2
                es es_xif (server_var(_tempcore) == 0) do
                {
                  es_xcopy _sl_oldesc eventscripts_escapechars
                  es_xsetinfo eventscripts_escapechars "<> _-R"
                  es es_xlogq Team Rebels triggered server_var(_sl_a2)
                  es_xcopy eventscripts_escapechars _sl_oldesc
                  es_xcreatescriptlist _statlog_scripts
                  es es_xforeachkey _sl_script in _statlog_scripts "es_xsetinfo _statlog_userid #r;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
                  es_xkeygroupdelete _statlog_scripts
                }
                es_xelse do
                {
                  es_xdbgmsg 0 [statlog] You must provide an event!
                }
              }
              es_xelse do
              {
                es_xsetinfo _tempcore 0
                es es_xexists _tempcore userid server_var(_sl_a1)
                es es_xif (server_var(_tempcore) == 1) do
                {
                  es_xgetargv _sl_a2 2
                  isnull _tempcore _sl_a2
                  es es_xif (server_var(_tempcore) == 0) do
                  {
                    es es_xgetplayername _sl_name server_var(_sl_a1)
                    es es_xgetplayersteamid _sl_steamid server_var(_sl_a1)
                    es es_xgetplayerteam _sl_team server_var(_sl_a1)
                    es es_xif (server_var(_sl_team) == 2) do
                    {
                      es es_xformat _tempcore %1<%2><%3><Combine> server_var(_sl_name) server_var(_sl_a1) server_var(_sl_steamid)
                      es_xcopy _sl_oldesc eventscripts_escapechars
                      es_xsetinfo eventscripts_escapechars "<> _-"
                      es es_xlogq server_var(_tempcore) triggered server_var(_sl_a2)
                      es_xcopy eventscripts_escapechars _sl_oldesc
                      es_xcreatescriptlist _statlog_scripts
                      es es_xforeachkey _sl_script in _statlog_scripts "es_xgetargv _statlog_userid 1;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
                      es_xkeygroupdelete _statlog_scripts
                    }
                    es_xelse do
                    {
                      es es_xif (server_var(_sl_team) == 3) do
                      {
                        es es_xformat _tempcore %1<%2><%3><Rebels> server_var(_sl_name) server_var(_sl_a1) server_var(_sl_steamid)
                        es_xcopy _sl_oldesc eventscripts_escapechars
                        es_xsetinfo eventscripts_escapechars "<> _-"
                        es es_xlogq server_var(_tempcore) triggered server_var(_sl_a2)
                        es_xcopy eventscripts_escapechars _sl_oldesc
                        es_xcreatescriptlist _statlog_scripts
                        es es_xforeachkey _sl_script in _statlog_scripts "es_xgetargv _statlog_userid 1;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
                        es_xkeygroupdelete _statlog_scripts
                      }
                      es_xelse do
                      {
                        es_xdbgmsg 0 [statlog] The player must be on a team to log stats!
                      }
                    }
                  }
                  es_xelse do
                  {
                    es_xdbgmsg 0 [statlog] You must provide an event!
                  }
                }
                es_xelse do
                {
                  es_xdbgmsg 0 [statlog] Inexistant userid provided!
                }
              }
            }
          }
          es_xelse do
          {
            es es_xif (server_var(_sl_game) == "Half-Life 2 CTF") do
            {
              es_xgetargv _sl_a1 1
              es es_xif (server_var(_sl_a1) == #c) do
              {
                es_xgetargv _sl_a2 2
                isnull _tempcore _sl_a2
                es es_xif (server_var(_tempcore) == 0) do
                {
                  es_xcopy _sl_oldesc eventscripts_escapechars
                  es_xsetinfo eventscripts_escapechars "<> _-C"
                  es es_xlogq Team Combine triggered server_var(_sl_a2)
                  es_xcopy eventscripts_escapechars _sl_oldesc
                  es_xcreatescriptlist _statlog_scripts
                  es es_xforeachkey _sl_script in _statlog_scripts "es_xsetinfo _statlog_userid #c;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
                  es_xkeygroupdelete _statlog_scripts
                }
                es_xelse do
                {
                  es_xdbgmsg 0 [statlog] You must provide an event!
                }
              }
              es_xelse do
              {
                es es_xif (server_var(_sl_a1) == #r) do
                {
                  es_xgetargv _sl_a2 2
                  isnull _tempcore _sl_a2
                  es es_xif (server_var(_tempcore) == 0) do
                  {
                    es_xcopy _sl_oldesc eventscripts_escapechars
                    es_xsetinfo eventscripts_escapechars "<> _-R"
                    es es_xlogq Team Rebels triggered server_var(_sl_a2)
                    es_xcopy eventscripts_escapechars _sl_oldesc
                    es_xcreatescriptlist _statlog_scripts
                    es es_xforeachkey _sl_script in _statlog_scripts "es_xsetinfo _statlog_userid #r;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
                    es_xkeygroupdelete _statlog_scripts
                  }
                  es_xelse do
                  {
                    es_xdbgmsg 0 [statlog] You must provide an event!
                  }
                }
                es_xelse do
                {
                  es_xsetinfo _tempcore 0
                  es es_xexists _tempcore userid server_var(_sl_a1)
                  es es_xif (server_var(_tempcore) == 1) do
                  {
                    es_xgetargv _sl_a2 2
                    isnull _tempcore _sl_a2
                    es es_xif (server_var(_tempcore) == 0) do
                    {
                      es es_xgetplayername _sl_name server_var(_sl_a1)
                      es es_xgetplayersteamid _sl_steamid server_var(_sl_a1)
                      es es_xgetplayerteam _sl_team server_var(_sl_a1)
                      es es_xif (server_var(_sl_team) == 2) do
                      {
                        es es_xformat _tempcore %1<%2><%3><Combine> server_var(_sl_name) server_var(_sl_a1) server_var(_sl_steamid)
                        es_xcopy _sl_oldesc eventscripts_escapechars
                        es_xsetinfo eventscripts_escapechars "<> _-"
                        es es_xlogq server_var(_tempcore) triggered server_var(_sl_a2)
                        es_xcopy eventscripts_escapechars _sl_oldesc
                        es_xcreatescriptlist _statlog_scripts
                        es es_xforeachkey _sl_script in _statlog_scripts "es_xgetargv _statlog_userid 1;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
                        es_xkeygroupdelete _statlog_scripts
                      }
                      es_xelse do
                      {
                        es es_xif (server_var(_sl_team) == 3) do
                        {
                          es es_xformat _tempcore %1<%2><%3><Rebels> server_var(_sl_name) server_var(_sl_a1) server_var(_sl_steamid)
                          es_xcopy _sl_oldesc eventscripts_escapechars
                          es_xsetinfo eventscripts_escapechars "<> _-"
                          es es_xlogq server_var(_tempcore) triggered server_var(_sl_a2)
                          es_xcopy eventscripts_escapechars _sl_oldesc
                          es_xcreatescriptlist _statlog_scripts
                          es es_xforeachkey _sl_script in _statlog_scripts "es_xgetargv _statlog_userid 1;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
                          es_xkeygroupdelete _statlog_scripts
                        }
                        es_xelse do
                        {
                          es_xdbgmsg 0 [statlog] The player must be on a team to log stats!
                        }
                      }
                    }
                    es_xelse do
                    {
                      es_xdbgmsg 0 [statlog] You must provide an event!
                    }
                  }
                  es_xelse do
                  {
                    es_xdbgmsg 0 [statlog] Inexistant userid provided!
                  }
                }
              }
            }
            es_xelse do
            {
              es es_xif (SourceForts in server_var(_sl_game)) do
              {
                es_xgetargv _sl_a1 1
                es es_xif (server_var(_sl_a1) == #b) do
                {
                  es_xgetargv _sl_a2 2
                  isnull _tempcore _sl_a2
                  es es_xif (server_var(_tempcore) == 0) do
                  {
                    es_xcopy _sl_oldesc eventscripts_escapechars
                    es_xsetinfo eventscripts_escapechars "<> _-B"
                    es es_xlogq Team Blue triggered server_var(_sl_a2)
                    es_xcopy eventscripts_escapechars _sl_oldesc
                    es_xcreatescriptlist _statlog_scripts
                    es es_xforeachkey _sl_script in _statlog_scripts "es_xsetinfo _statlog_userid #b;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
                    es_xkeygroupdelete _statlog_scripts
                  }
                  es_xelse do
                  {
                    es_xdbgmsg 0 [statlog] You must provide an event!
                  }
                }
                es_xelse do
                {
                  es es_xif (server_var(_sl_a1) == #r) do
                  {
                    es_xgetargv _sl_a2 2
                    isnull _tempcore _sl_a2
                    es es_xif (server_var(_tempcore) == 0) do
                    {
                      es_xcopy _sl_oldesc eventscripts_escapechars
                      es_xsetinfo eventscripts_escapechars "<> _-R"
                      es es_xlogq Team Red triggered server_var(_sl_a2)
                      es_xcopy eventscripts_escapechars _sl_oldesc
                      es_xcreatescriptlist _statlog_scripts
                      es es_xforeachkey _sl_script in _statlog_scripts "es_xsetinfo _statlog_userid #r;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
                      es_xkeygroupdelete _statlog_scripts
                    }
                    es_xelse do
                    {
                      es_xdbgmsg 0 [statlog] You must provide an event!
                    }
                  }
                  es_xelse do
                  {
                    es_xsetinfo _tempcore 0
                    es es_xexists _tempcore userid server_var(_sl_a1)
                    es es_xif (server_var(_tempcore) == 1) do
                    {
                      es_xgetargv _sl_a2 2
                      isnull _tempcore _sl_a2
                      es es_xif (server_var(_tempcore) == 0) do
                      {
                        es es_xgetplayername _sl_name server_var(_sl_a1)
                        es es_xgetplayersteamid _sl_steamid server_var(_sl_a1)
                        es es_xgetplayerteam _sl_team server_var(_sl_a1)
                        es es_xif (server_var(_sl_team) == 2) do
                        {
                          es es_xformat _tempcore %1<%2><%3><Blue> server_var(_sl_name) server_var(_sl_a1) server_var(_sl_steamid)
                          es_xcopy _sl_oldesc eventscripts_escapechars
                          es_xsetinfo eventscripts_escapechars "<> _-"
                          es es_xlogq server_var(_tempcore) triggered server_var(_sl_a2)
                          es_xcopy eventscripts_escapechars _sl_oldesc
                          es_xcreatescriptlist _statlog_scripts
                          es es_xforeachkey _sl_script in _statlog_scripts "es_xgetargv _statlog_userid 1;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
                          es_xkeygroupdelete _statlog_scripts
                        }
                        es_xelse do
                        {
                          es es_xif (server_var(_sl_team) == 3) do
                          {
                            es es_xformat _tempcore %1<%2><%3><Red> server_var(_sl_name) server_var(_sl_a1) server_var(_sl_steamid)
                            es_xcopy _sl_oldesc eventscripts_escapechars
                            es_xsetinfo eventscripts_escapechars "<> _-"
                            es es_xlogq server_var(_tempcore) triggered server_var(_sl_a2)
                            es_xcopy eventscripts_escapechars _sl_oldesc
                            es_xcreatescriptlist _statlog_scripts
                            es es_xforeachkey _sl_script in _statlog_scripts "es_xgetargv _statlog_userid 1;es_xgetargv _statlog_event 2;es es_xformat _tempcore %1/_statlog server_var(_sl_script);es es_xdoblock server_var(_tempcore)"
                            es_xkeygroupdelete _statlog_scripts
                          }
                          es_xelse do
                          {
                            es_xdbgmsg 0 [statlog] The player must be on a team to log stats!
                          }
                        }
                      }
                      es_xelse do
                      {
                        es_xdbgmsg 0 [statlog] You must provide an event!
                      }
                    }
                    es_xelse do
                    {
                      es_xdbgmsg 0 [statlog] Inexistant userid provided!
                    }
                  }
                }
              }
              es_xelse do
              {
                es_xdbgmsg 0 [statlog] This mod is not supported in statlog!
              }
            }
          }
        }
      }
    }
  }
}


block statlog_test
{
  profile begin _statlog_test
  statlog #t lets_test_this
  profile end _statlog_test

  profile begin _statlog_test
  statlog #ct lets_test_this
  profile end _statlog_test

  es_xsetinfo auser 0
  es_xgetuserid auser
  es es_xif (server_var(auser) > 0) do
  {
    profile begin _statlog_test
    es statlog server_var(auser) lets_test_this
    profile end _statlog_test
  }
}
