/**
* HLstatsX Community Edition - SourceMod plugin to generate advanced weapon logging
* http://www.hlxcommunity.com
* Copyright (C) 2009-2012 Nicholas Hastings (psychonic)
* Copyright (C) 2007-2008 TTS Oetzel & Goerz GmbH
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#define NAME "SuperLogs: Dino D-Day"
#define VERSION "1.0.0"
#define MAX_LOG_WEAPONS 47
#define MAX_WEAPON_LEN 12
#define PREFIX_LEN 7
// Some DDD Things
#define WEAPON_MG42 18
#define WEAPON_TREX 37
#define PLAYERCLASS_TREX 8
#define CUSTOMKILL_GOAT 5
new g_weapon_stats[MAXPLAYERS+1][MAX_LOG_WEAPONS][15];
new const String:g_weapon_list[MAX_LOG_WEAPONS][MAX_WEAPON_LEN] = {
"",
"mp40",
"thompson",
"shotgun",
"",
"pistol",
"",
"",
"garand",
"bar",
"luger",
"",
"piat",
"",
"mosin",
"k98",
"",
"",
"mg42",
"",
"k98sniper",
"",
"",
"",
"flechette",
"",
"",
"",
"",
"mp44",
"",
"",
"sten",
"p38",
"nagant",
"",
"",
"trex",
"",
"",
"trigger",
"stygimoloch",
"",
"",
"",
"carbine",
"greasegun",
};
new g_iNextHitgroup[MAXPLAYERS+1];
new bool:g_bLate;
new bool:g_bIgnoreLog;
PauseLogging() { g_bIgnoreLog = true; }
ResumeLogging() { g_bIgnoreLog = false; }
#include <loghelper>
#include <wstatshelper>
public Plugin:myinfo = {
name = NAME,
author = "psychonic and FeuerSturm",
description = "Advanced logging for Dino D-Day. Generates auxilary logging for use with log parsers such as HLstatsX and Psychostats",
version = VERSION,
url = "http://www.hlxce.com"
};
public APLRes:AskPluginLoad2( Handle:myself, bool:late, String:error[], err_max )
{
decl String:szGameDir[64];
GetGameFolderName( szGameDir, sizeof(szGameDir) );
if ( !!strcmp( szGameDir, "dinodday" ) )
{
strcopy( error, err_max, "This plugin is only supported on Dino D-Day" );
return APLRes_Failure;
}
g_bLate = late;
return APLRes_Success;
}
public OnPluginStart()
{
CreatePopulateWeaponTrie();
CreateConVar( "superlogs_dinodday_version", VERSION, NAME, FCVAR_NOTIFY|FCVAR_DONTRECORD );
hook_wstats();
HookEvent( "player_death", Event_PlayerDeathPre, EventHookMode_Pre );
HookEvent( "player_death", Event_PlayerDeath );
HookEvent( "player_spawn", Event_PlayerSpawn );
HookEvent( "round_end", Event_RoundEnd, EventHookMode_PostNoCopy );
AddGameLogHook( OnGameLog );
AddTempEntHook( "Shotgun Shot", OnFireBullets );
}
public OnAllPluginsLoaded()
{
for ( new i = 1; i <= MaxClients; i++ )
{
if ( IsClientInGame( i ) )
{
OnClientPutInServer( i )
}
}
}
public OnMapStart()
{
static bool:bLoggedMap = false;
if( g_bLate && !bLoggedMap )
{
LogMapLoad();
}
bLoggedMap = true;
GetTeams();
}
public OnClientPutInServer( client )
{
SDKHook( client, SDKHook_TraceAttackPost, OnTraceAttack );
SDKHook( client, SDKHook_OnTakeDamagePost, OnTakeDamage );
reset_player_stats( client );
}
public Action:OnFireBullets( const String:szName[], const clients[], clientCount, Float:flDelay )
{
new client = TE_ReadNum( "m_iPlayer" ) + 1;
new weapon_index = TE_ReadNum( "m_iWeaponID" );
if( weapon_index >= 0 )
{
if( GetEntProp(client, Prop_Send, "m_iPlayerClass") == PLAYERCLASS_TREX && weapon_index == WEAPON_MG42 )
{
weapon_index = WEAPON_TREX;
}
g_weapon_stats[client][weapon_index][LOG_HIT_SHOTS]++;
}
return Plugin_Continue;
}
public OnTraceAttack( victim, attacker, inflictor, Float:damage, damagetype, ammotype, hitbox, hitgroup )
{
if ( hitgroup > 0 && attacker > 0 && attacker <= MaxClients && victim > 0 && victim <= MaxClients )
{
g_iNextHitgroup[victim] = hitgroup;
}
}
public OnTakeDamage( victim, attacker, inflictor, Float:damage, damagetype )
{
if ( attacker > 0 && attacker <= MaxClients && victim > 0 && victim <= MaxClients )
{
decl String: weapon[MAX_WEAPON_LEN + PREFIX_LEN];
GetClientWeapon( attacker, weapon, sizeof(weapon) );
new weapon_index = get_weapon_index(weapon[PREFIX_LEN]);
new hitgroup = g_iNextHitgroup[victim];
if ( hitgroup < 8 )
{
hitgroup += LOG_HIT_OFFSET;
}
new bool:headshot = ( !IsPlayerAlive( victim ) && g_iNextHitgroup[victim] == HITGROUP_HEAD );
if ( weapon_index > -1 )
{
g_weapon_stats[attacker][weapon_index][LOG_HIT_HITS]++;
g_weapon_stats[attacker][weapon_index][LOG_HIT_DAMAGE] += RoundToNearest( damage );
g_weapon_stats[attacker][weapon_index][hitgroup]++;
if ( headshot )
{
g_weapon_stats[attacker][weapon_index][LOG_HIT_HEADSHOTS]++;
LogPlayerEvent( attacker, "triggered", "headshot" );
}
}
g_iNextHitgroup[victim] = 0;
}
}
public Action:OnGameLog( const String:szMessage[] )
{
if( g_bIgnoreLog )
return Plugin_Handled;
return Plugin_Continue;
}
public Action:Event_PlayerDeathPre( Handle:event, const String:name[], bool:dontBroadcast )
{
PauseLogging();
return Plugin_Continue;
}
public Event_PlayerDeath( Handle:event, const String:name[], bool:dontBroadcast )
{
ResumeLogging();
new victim = GetClientOfUserId( GetEventInt( event, "userid" ) );
if ( victim > 0 )
{
new attacker = GetClientOfUserId( GetEventInt( event, "attacker" ) );
decl String:weapon[MAX_WEAPON_LEN];
GetEventString( event, "weapon", weapon, sizeof(weapon) );
if( attacker > 0 && attacker != victim )
{
new weapon_index = get_weapon_index( weapon );
if ( weapon_index > -1 )
{
g_weapon_stats[attacker][weapon_index][LOG_HIT_KILLS]++;
g_weapon_stats[victim][weapon_index][LOG_HIT_DEATHS]++;
if ( GetClientTeam( attacker ) == GetClientTeam( victim ) )
{
g_weapon_stats[attacker][weapon_index][LOG_HIT_TEAMKILLS]++;
}
}
LogKill( attacker, victim, weapon, true );
}
else
{
new customkill = GetEventInt(event, "customkill");
if( customkill == CUSTOMKILL_GOAT )
{
LogPlayerEvent(attacker, "triggered", "kill_goat");
return;
}
LogPlayerEvent(victim, "committed suicide with", weapon);
}
dump_player_stats( victim );
}
}
public Event_PlayerSpawn( Handle:event, const String:name[], bool:dontBroadcast )
{
new client = GetClientOfUserId(G etEventInt( event, "userid" ) );
if ( client > 0 )
{
reset_player_stats( client );
}
}
public Event_RoundEnd( Handle:event, const String:name[], bool:dontBroadcast )
{
WstatsDumpAll();
}
public OnClientDisconnect( client )
{
OnPlayerDisconnect( client );
}