2018-08-17 17:56:16 +02:00
#define LOGHELPER_VERSION 5
2017-08-04 03:07:07 +02:00
#include <sourcemod>
#include <sdktools>
2018-08-17 17:56:16 +02:00
char g_team_list [ 16 ][ 64 ];
2017-08-04 03:07:07 +02:00
// Call this on map start to cache team names in g_team_list
2018-08-17 17:56:16 +02:00
stock void GetTeams ( bool insmod = false )
2017-08-04 03:07:07 +02:00
{
if ( ! insmod )
{
2018-08-17 17:56:16 +02:00
int max_teams_count = GetTeamCount ();
for ( int team_index = 0 ; ( team_index < max_teams_count ); team_index ++ )
2017-08-04 03:07:07 +02:00
{
2018-08-17 17:56:16 +02:00
char team_name [ 64 ];
2017-08-04 03:07:07 +02:00
GetTeamName ( team_index , team_name , sizeof ( team_name ));
if ( strcmp ( team_name , " " ) != 0 )
{
g_team_list [ team_index ] = team_name ;
}
}
}
else
{
// they really need to get their act together... GetTeamName() would be awesome since they can't even keep their team indexes consistent
2018-08-17 17:56:16 +02:00
char mapname [ 64 ];
2017-08-04 03:07:07 +02:00
GetCurrentMap ( mapname , sizeof ( mapname ));
if ( strcmp ( mapname , " ins_karam " ) == 0 || strcmp ( mapname , " ins_baghdad " ) == 0 )
{
g_team_list [ 1 ] = " Iraqi Insurgents " ;
g_team_list [ 2 ] = " U.S. Marines " ;
}
else
{
g_team_list [ 1 ] = " U.S. Marines " ;
g_team_list [ 2 ] = " Iraqi Insurgents " ;
}
g_team_list [ 0 ] = " Unassigned " ;
g_team_list [ 3 ] = " SPECTATOR " ;
}
}
2018-08-17 17:56:16 +02:00
stock void LogPlayerEvent ( int client , const char [] verb , const char [] event , bool display_location = false , const char [] properties = " " )
2017-08-04 03:07:07 +02:00
{
if ( IsValidPlayer ( client ))
{
2018-08-17 17:56:16 +02:00
char player_authid [ 32 ];
if ( ! GetClientAuthId ( client , AuthId_Engine , player_authid , sizeof ( player_authid ), false ))
2017-08-04 03:07:07 +02:00
{
strcopy ( player_authid , sizeof ( player_authid ), " UNKNOWN " );
}
if ( display_location )
{
2018-08-17 17:56:16 +02:00
float player_origin [ 3 ];
2017-08-04 03:07:07 +02:00
GetClientAbsOrigin ( client , player_origin );
2018-08-17 17:56:16 +02:00
LogToGame ( " \" %N<%d><%s><%s> \" %s \" %s \" %s (position \" %d %d %d \" ) " , client , GetClientUserId ( client ), player_authid , g_team_list [ GetClientTeam ( client )], verb , event , properties , RoundFloat ( player_origin [ 0 ]), RoundFloat ( player_origin [ 1 ]), RoundFloat ( player_origin [ 2 ]));
2017-08-04 03:07:07 +02:00
}
else
{
2018-08-17 17:56:16 +02:00
LogToGame ( " \" %N<%d><%s><%s> \" %s \" %s \" %s " , client , GetClientUserId ( client ), player_authid , g_team_list [ GetClientTeam ( client )], verb , event , properties );
2017-08-04 03:07:07 +02:00
}
}
}
2018-08-17 17:56:16 +02:00
stock void LogPlyrPlyrEvent ( int client , int victim , const char [] verb , const char [] event , bool display_location = false , const char [] properties = " " )
2017-08-04 03:07:07 +02:00
{
if ( IsValidPlayer ( client ) && IsValidPlayer ( victim ))
{
2018-08-17 17:56:16 +02:00
char player_authid [ 32 ];
if ( ! GetClientAuthId ( client , AuthId_Engine , player_authid , sizeof ( player_authid ), false ))
2017-08-04 03:07:07 +02:00
{
strcopy ( player_authid , sizeof ( player_authid ), " UNKNOWN " );
}
2018-08-17 17:56:16 +02:00
char victim_authid [ 32 ];
if ( ! GetClientAuthId ( victim , AuthId_Engine , victim_authid , sizeof ( victim_authid ), false ))
2017-08-04 03:07:07 +02:00
{
strcopy ( victim_authid , sizeof ( victim_authid ), " UNKNOWN " );
}
if ( display_location )
{
2018-08-17 17:56:16 +02:00
float player_origin [ 3 ];
2017-08-04 03:07:07 +02:00
GetClientAbsOrigin ( client , player_origin );
2018-08-17 17:56:16 +02:00
float victim_origin [ 3 ];
2017-08-04 03:07:07 +02:00
GetClientAbsOrigin ( victim , victim_origin );
LogToGame ( " \" %N<%d><%s><%s> \" %s \" %s \" against \" %N<%d><%s><%s> \" %s (position \" %d %d %d \" ) (victim_position \" %d %d %d \" ) " , client , GetClientUserId ( client ), player_authid , g_team_list [ GetClientTeam ( client )], verb , event , victim , GetClientUserId ( victim ), victim_authid , g_team_list [ GetClientTeam ( victim )], properties , RoundFloat ( player_origin [ 0 ]), RoundFloat ( player_origin [ 1 ]), RoundFloat ( player_origin [ 2 ]), RoundFloat ( victim_origin [ 0 ]), RoundFloat ( victim_origin [ 1 ]), RoundFloat ( victim_origin [ 2 ]));
}
else
{
LogToGame ( " \" %N<%d><%s><%s> \" %s \" %s \" against \" %N<%d><%s><%s> \" %s " , client , GetClientUserId ( client ), player_authid , g_team_list [ GetClientTeam ( client )], verb , event , victim , GetClientUserId ( victim ), victim_authid , g_team_list [ GetClientTeam ( victim )], properties );
}
}
}
2018-08-17 17:56:16 +02:00
stock void LogKill ( int attacker , int victim , const char [] weapon , bool display_location = false , const char [] properties = " " )
2017-08-04 03:07:07 +02:00
{
if ( IsValidPlayer ( attacker ) && IsValidPlayer ( victim ))
{
2018-08-17 17:56:16 +02:00
char attacker_authid [ 32 ];
if ( ! GetClientAuthId ( attacker , AuthId_Engine , attacker_authid , sizeof ( attacker_authid ), false ))
2017-08-04 03:07:07 +02:00
{
strcopy ( attacker_authid , sizeof ( attacker_authid ), " UNKNOWN " );
}
2018-08-17 17:56:16 +02:00
char victim_authid [ 32 ];
if ( ! GetClientAuthId ( victim , AuthId_Engine , victim_authid , sizeof ( victim_authid ), false ))
2017-08-04 03:07:07 +02:00
{
strcopy ( victim_authid , sizeof ( victim_authid ), " UNKNOWN " );
}
if ( display_location )
{
2018-08-17 17:56:16 +02:00
float attacker_origin [ 3 ];
2017-08-04 03:07:07 +02:00
GetClientAbsOrigin ( attacker , attacker_origin );
2018-08-17 17:56:16 +02:00
float victim_origin [ 3 ];
2017-08-04 03:07:07 +02:00
GetClientAbsOrigin ( victim , victim_origin );
LogToGame ( " \" %N<%d><%s><%s> \" killed \" %N<%d><%s><%s> \" with \" %s \" %s (attacker_position \" %d %d %d \" ) (victim_position \" %d %d %d \" ) " , attacker , GetClientUserId ( attacker ), attacker_authid , g_team_list [ GetClientTeam ( attacker )], victim , GetClientUserId ( victim ), victim_authid , g_team_list [ GetClientTeam ( victim )], weapon , properties , RoundFloat ( attacker_origin [ 0 ]), RoundFloat ( attacker_origin [ 1 ]), RoundFloat ( attacker_origin [ 2 ]), RoundFloat ( victim_origin [ 0 ]), RoundFloat ( victim_origin [ 1 ]), RoundFloat ( victim_origin [ 2 ]));
}
else
{
LogToGame ( " \" %N<%d><%s><%s> \" killed \" %N<%d><%s><%s> \" with \" %s \" %s " , attacker , GetClientUserId ( attacker ), attacker_authid , g_team_list [ GetClientTeam ( attacker )], victim , GetClientUserId ( victim ), victim_authid , g_team_list [ GetClientTeam ( victim )], weapon , properties );
}
}
}
2018-08-17 17:56:16 +02:00
stock void LogSuicide ( int victim , const char [] weapon , bool display_location = false , const char [] properties = " " )
{
if ( IsValidPlayer ( victim ))
{
char victim_authid [ 32 ];
if ( ! GetClientAuthId ( victim , AuthId_Engine , victim_authid , sizeof ( victim_authid ), false ))
{
strcopy ( victim_authid , sizeof ( victim_authid ), " UNKNOWN " );
}
if ( display_location )
{
float victim_origin [ 3 ];
GetClientAbsOrigin ( victim , victim_origin );
LogToGame ( " \" %N<%d><%s><%s> \" committed suicide with \" %s \" %s (victim_position \" %d %d %d \" ) " , victim , GetClientUserId ( victim ), victim_authid , g_team_list [ GetClientTeam ( victim )], weapon , properties , RoundFloat ( victim_origin [ 0 ]), RoundFloat ( victim_origin [ 1 ]), RoundFloat ( victim_origin [ 2 ]));
}
else
{
LogToGame ( " \" %N<%d><%s><%s> \" committed suicide with \" %s \" %s " , victim , GetClientUserId ( victim ), victim_authid , g_team_list [ GetClientTeam ( victim )], weapon , properties );
}
}
}
2017-08-04 03:07:07 +02:00
// For Psychostats "KTRAJ" kill trajectory log lines
2018-08-17 17:56:16 +02:00
stock void LogPSKillTraj ( int attacker , int victim , const char [] weapon )
2017-08-04 03:07:07 +02:00
{
if ( IsValidPlayer ( attacker ) && IsValidPlayer ( victim ))
{
2018-08-17 17:56:16 +02:00
char attacker_authid [ 32 ];
if ( ! GetClientAuthId ( attacker , AuthId_Engine , attacker_authid , sizeof ( attacker_authid ), false ))
2017-08-04 03:07:07 +02:00
{
strcopy ( attacker_authid , sizeof ( attacker_authid ), " UNKNOWN " );
}
2018-08-17 17:56:16 +02:00
char victim_authid [ 32 ];
if ( ! GetClientAuthId ( victim , AuthId_Engine , victim_authid , sizeof ( victim_authid ), false ))
2017-08-04 03:07:07 +02:00
{
strcopy ( victim_authid , sizeof ( victim_authid ), " UNKNOWN " );
}
2018-08-17 17:56:16 +02:00
float attacker_origin [ 3 ];
2017-08-04 03:07:07 +02:00
GetClientAbsOrigin ( attacker , attacker_origin );
2018-08-17 17:56:16 +02:00
float victim_origin [ 3 ];
2017-08-04 03:07:07 +02:00
GetClientAbsOrigin ( victim , victim_origin );
LogToGame ( " [KTRAJ] \" %N<%d><%s><%s> \" killed \" %N<%d><%s><%s> \" with \" %s \" (attacker_position \" %d %d %d \" ) (victim_position \" %d %d %d \" ) " , attacker , GetClientUserId ( attacker ), attacker_authid , g_team_list [ GetClientTeam ( attacker )], victim , GetClientUserId ( victim ), victim_authid , g_team_list [ GetClientTeam ( victim )], weapon , RoundFloat ( attacker_origin [ 0 ]), RoundFloat ( attacker_origin [ 1 ]), RoundFloat ( attacker_origin [ 2 ]), RoundFloat ( victim_origin [ 0 ]), RoundFloat ( victim_origin [ 1 ]), RoundFloat ( victim_origin [ 2 ]));
}
}
// Verb should always be "triggered" for this.
2018-08-17 17:56:16 +02:00
stock void LogTeamEvent ( int team , const char [] verb , const char [] event , const char [] properties = " " )
2017-08-04 03:07:07 +02:00
{
if ( team > - 1 )
{
LogToGame ( " Team \" %s \" %s \" %s \" %s " , g_team_list [ team ], verb , event , properties );
}
}
2018-08-17 17:56:16 +02:00
stock void LogKillLoc ( int attacker , int victim )
2017-08-04 03:07:07 +02:00
{
if ( attacker > 0 && victim > 0 )
{
2018-08-17 17:56:16 +02:00
float attacker_origin [ 3 ];
2017-08-04 03:07:07 +02:00
GetClientAbsOrigin ( attacker , attacker_origin );
2018-08-17 17:56:16 +02:00
float victim_origin [ 3 ];
2017-08-04 03:07:07 +02:00
GetClientAbsOrigin ( victim , victim_origin );
LogToGame ( " World triggered \" killlocation \" (attacker_position \" %d %d %d \" ) (victim_position \" %d %d %d \" ) " , RoundFloat ( attacker_origin [ 0 ]), RoundFloat ( attacker_origin [ 1 ]), RoundFloat ( attacker_origin [ 2 ]), RoundFloat ( victim_origin [ 0 ]), RoundFloat ( victim_origin [ 1 ]), RoundFloat ( victim_origin [ 2 ]));
}
}
2018-08-17 17:56:16 +02:00
stock void LogTeamChange ( int client , int newteam , const char [] properties = " " )
2017-08-04 03:07:07 +02:00
{
2018-08-17 17:56:16 +02:00
if ( IsValidPlayer ( client ))
{
char player_authid [ 32 ];
if ( ! GetClientAuthId ( client , AuthId_Engine , player_authid , sizeof ( player_authid ), false ))
{
strcopy ( player_authid , sizeof ( player_authid ), " UNKNOWN " );
}
LogToGame ( " \" %N<%d><%s><%s> \" joined team \" %s \" %s " , client , GetClientUserId ( client ), player_authid , g_team_list [ GetClientTeam ( client )], g_team_list [ newteam ], properties );
}
}
stock void LogRoleChange ( int client , const char [] role , const char [] properties = " " )
{
if ( IsValidPlayer ( client ))
{
char player_authid [ 32 ];
if ( ! GetClientAuthId ( client , AuthId_Engine , player_authid , sizeof ( player_authid ), false ))
{
strcopy ( player_authid , sizeof ( player_authid ), " UNKNOWN " );
}
LogToGame ( " \" %N<%d><%s><%s> \" changed role to \" %s \" %s " , client , GetClientUserId ( client ), player_authid , g_team_list [ GetClientTeam ( client )], role , properties );
}
2017-08-04 03:07:07 +02:00
}
2018-08-17 17:56:16 +02:00
stock void LogMapLoad ()
2017-08-04 03:07:07 +02:00
{
2018-08-17 17:56:16 +02:00
char map [ 64 ];
2017-08-04 03:07:07 +02:00
GetCurrentMap ( map , sizeof ( map ));
LogToGame ( " Loading map \" %s \" " , map );
}
2018-08-17 17:56:16 +02:00
static stock bool IsValidPlayer ( int client )
2017-08-04 03:07:07 +02:00
{
if ( client > 0 && client <= MaxClients && IsClientInGame ( client ))
{
return true ;
}
return false ;
}