Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 8th, 2012  |  syntax: PAWN  |  size: 7.55 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /**
  2.  * HLstatsX Community Edition - SourceMod plugin to generate advanced weapon logging
  3.  * http://www.hlxcommunity.com
  4.  * Copyright (C) 2009-2012 Nicholas Hastings (psychonic)
  5.  * Copyright (C) 2007-2008 TTS Oetzel & Goerz GmbH
  6.  *
  7.  * This program is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU General Public License
  9.  * as published by the Free Software Foundation; either version 2
  10.  * of the License, or (at your option) any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  20.  */
  21.  
  22. #pragma semicolon 1
  23.  
  24. #include <sourcemod>
  25. #include <sdktools>
  26. #include <sdkhooks>
  27.  
  28. #define NAME "SuperLogs: Dino D-Day"
  29. #define VERSION "1.0.0"
  30.  
  31. #define MAX_LOG_WEAPONS 47
  32. #define MAX_WEAPON_LEN 12
  33. #define PREFIX_LEN 7
  34.  
  35. // Some DDD Things
  36. #define WEAPON_MG42     18
  37. #define WEAPON_TREX     37
  38. #define PLAYERCLASS_TREX        8
  39. #define CUSTOMKILL_GOAT 5
  40.  
  41. new g_weapon_stats[MAXPLAYERS+1][MAX_LOG_WEAPONS][15];
  42. new const String:g_weapon_list[MAX_LOG_WEAPONS][MAX_WEAPON_LEN] = {
  43.                                                                         "",
  44.                                                                         "mp40",
  45.                                                                         "thompson",
  46.                                                                         "shotgun",
  47.                                                                         "",
  48.                                                                         "pistol",
  49.                                                                         "",
  50.                                                                         "",
  51.                                                                         "garand",
  52.                                                                         "bar",
  53.                                                                         "luger",
  54.                                                                         "",
  55.                                                                         "piat",
  56.                                                                         "",
  57.                                                                         "mosin",
  58.                                                                         "k98",
  59.                                                                         "",
  60.                                                                         "",
  61.                                                                         "mg42",
  62.                                                                         "",
  63.                                                                         "k98sniper",
  64.                                                                         "",
  65.                                                                         "",
  66.                                                                         "",
  67.                                                                         "flechette",
  68.                                                                         "",
  69.                                                                         "",
  70.                                                                         "",
  71.                                                                         "",
  72.                                                                         "mp44",
  73.                                                                         "",
  74.                                                                         "",
  75.                                                                         "sten",
  76.                                                                         "p38",
  77.                                                                         "nagant",
  78.                                                                         "",
  79.                                                                         "",
  80.                                                                         "trex",
  81.                                                                         "",
  82.                                                                         "",
  83.                                                                         "trigger",
  84.                                                                         "stygimoloch",
  85.                                                                         "",
  86.                                                                         "",
  87.                                                                         "",
  88.                                                                         "carbine",
  89.                                                                         "greasegun",
  90.                                                                 };
  91.  
  92. new g_iNextHitgroup[MAXPLAYERS+1];
  93.  
  94. new bool:g_bLate;
  95. new bool:g_bIgnoreLog;
  96.  
  97. PauseLogging() { g_bIgnoreLog = true; }
  98. ResumeLogging() { g_bIgnoreLog = false; }
  99.  
  100. #include <loghelper>
  101. #include <wstatshelper>
  102.  
  103.  
  104. public Plugin:myinfo = {
  105.         name = NAME,
  106.         author = "psychonic and FeuerSturm",
  107.         description = "Advanced logging for Dino D-Day. Generates auxilary logging for use with log parsers such as HLstatsX and Psychostats",
  108.         version = VERSION,
  109.         url = "http://www.hlxce.com"
  110. };
  111.  
  112. public APLRes:AskPluginLoad2( Handle:myself, bool:late, String:error[], err_max )
  113. {
  114.         decl String:szGameDir[64];
  115.         GetGameFolderName( szGameDir, sizeof(szGameDir) );
  116.         if ( !!strcmp( szGameDir, "dinodday" ) )
  117.         {
  118.                 strcopy( error, err_max, "This plugin is only supported on Dino D-Day" );
  119.                 return APLRes_Failure;
  120.         }
  121.        
  122.         g_bLate = late;
  123.        
  124.         return APLRes_Success;
  125. }
  126.  
  127. public OnPluginStart()
  128. {
  129.         CreatePopulateWeaponTrie();
  130.         CreateConVar( "superlogs_dinodday_version", VERSION, NAME, FCVAR_NOTIFY|FCVAR_DONTRECORD );
  131.        
  132.         hook_wstats();
  133.         HookEvent( "player_death", Event_PlayerDeathPre, EventHookMode_Pre );
  134.         HookEvent( "player_death", Event_PlayerDeath );
  135.         HookEvent( "player_spawn", Event_PlayerSpawn );
  136.         HookEvent( "round_end", Event_RoundEnd, EventHookMode_PostNoCopy );
  137.                
  138.         AddGameLogHook( OnGameLog );
  139.         AddTempEntHook( "Shotgun Shot", OnFireBullets );
  140. }
  141.  
  142. public OnAllPluginsLoaded()
  143. {
  144.         for ( new i = 1; i <= MaxClients; i++ )
  145.         {
  146.                 if ( IsClientInGame( i ) )
  147.                 {
  148.                         OnClientPutInServer( i )
  149.                 }
  150.         }
  151. }
  152.  
  153. public OnMapStart()
  154. {
  155.         static bool:bLoggedMap = false;
  156.         if( g_bLate && !bLoggedMap )
  157.         {
  158.                 LogMapLoad();
  159.         }
  160.        
  161.         bLoggedMap = true;
  162.        
  163.         GetTeams();
  164. }
  165.  
  166. public OnClientPutInServer( client )
  167. {
  168.         SDKHook( client, SDKHook_TraceAttackPost, OnTraceAttack );
  169.         SDKHook( client, SDKHook_OnTakeDamagePost, OnTakeDamage );
  170.         reset_player_stats( client );
  171. }
  172.  
  173. public Action:OnFireBullets( const String:szName[], const clients[], clientCount, Float:flDelay )
  174. {
  175.         new client = TE_ReadNum( "m_iPlayer" ) + 1;
  176.         new weapon_index = TE_ReadNum( "m_iWeaponID" );
  177.        
  178.         if( weapon_index >= 0 )
  179.         {
  180.                 if( GetEntProp(client, Prop_Send, "m_iPlayerClass") == PLAYERCLASS_TREX && weapon_index == WEAPON_MG42 )
  181.                 {
  182.                         weapon_index = WEAPON_TREX;
  183.                 }
  184.                 g_weapon_stats[client][weapon_index][LOG_HIT_SHOTS]++;
  185.         }
  186.        
  187.         return Plugin_Continue;
  188. }
  189.  
  190. public OnTraceAttack( victim, attacker, inflictor, Float:damage, damagetype, ammotype, hitbox, hitgroup )
  191. {
  192.         if ( hitgroup > 0 && attacker > 0 && attacker <= MaxClients && victim > 0 && victim <= MaxClients )
  193.         {
  194.                 g_iNextHitgroup[victim] = hitgroup;
  195.         }
  196. }
  197.  
  198. public OnTakeDamage( victim, attacker, inflictor, Float:damage, damagetype )
  199. {      
  200.         if ( attacker > 0 && attacker <= MaxClients && victim > 0 && victim <= MaxClients )
  201.         {
  202.                 decl String: weapon[MAX_WEAPON_LEN + PREFIX_LEN];
  203.                 GetClientWeapon( attacker, weapon, sizeof(weapon) );
  204.                
  205.                 new weapon_index = get_weapon_index(weapon[PREFIX_LEN]);
  206.                 new hitgroup = g_iNextHitgroup[victim];
  207.                 if ( hitgroup < 8 )
  208.                 {
  209.                         hitgroup += LOG_HIT_OFFSET;
  210.                 }
  211.                
  212.                 new bool:headshot = ( !IsPlayerAlive( victim ) && g_iNextHitgroup[victim] == HITGROUP_HEAD );
  213.                 if ( weapon_index > -1 )
  214.                 {
  215.                         g_weapon_stats[attacker][weapon_index][LOG_HIT_HITS]++;
  216.                         g_weapon_stats[attacker][weapon_index][LOG_HIT_DAMAGE] += RoundToNearest( damage );
  217.                         g_weapon_stats[attacker][weapon_index][hitgroup]++;
  218.                         if ( headshot )
  219.                         {
  220.                                 g_weapon_stats[attacker][weapon_index][LOG_HIT_HEADSHOTS]++;
  221.                                 LogPlayerEvent( attacker, "triggered", "headshot" );
  222.                         }
  223.                 }
  224.  
  225.                 g_iNextHitgroup[victim] = 0;
  226.         }
  227. }
  228.  
  229. public Action:OnGameLog( const String:szMessage[] )
  230. {
  231.         if( g_bIgnoreLog )
  232.                 return Plugin_Handled;
  233.        
  234.         return Plugin_Continue;
  235. }
  236.  
  237. public Action:Event_PlayerDeathPre( Handle:event, const String:name[], bool:dontBroadcast )
  238. {
  239.         PauseLogging();
  240.        
  241.         return Plugin_Continue;
  242. }
  243.  
  244. public Event_PlayerDeath( Handle:event, const String:name[], bool:dontBroadcast )
  245. {
  246.         ResumeLogging();
  247.        
  248.         new victim = GetClientOfUserId( GetEventInt( event, "userid" ) );
  249.        
  250.         if ( victim > 0 )
  251.         {
  252.                 new attacker = GetClientOfUserId( GetEventInt( event, "attacker" ) );
  253.  
  254.                 decl String:weapon[MAX_WEAPON_LEN];
  255.                 GetEventString( event, "weapon", weapon, sizeof(weapon) );
  256.                 if( attacker > 0 && attacker != victim )
  257.                 {
  258.                         new weapon_index = get_weapon_index( weapon );
  259.                         if ( weapon_index > -1 )
  260.                         {
  261.                                 g_weapon_stats[attacker][weapon_index][LOG_HIT_KILLS]++;               
  262.                                 g_weapon_stats[victim][weapon_index][LOG_HIT_DEATHS]++;
  263.                                 if ( GetClientTeam( attacker ) == GetClientTeam( victim ) )
  264.                                 {
  265.                                         g_weapon_stats[attacker][weapon_index][LOG_HIT_TEAMKILLS]++;
  266.                                 }      
  267.                         }
  268.                        
  269.                         LogKill( attacker, victim, weapon, true );
  270.                 }
  271.                 else
  272.                 {
  273.                         new customkill = GetEventInt(event, "customkill");
  274.                         if( customkill == CUSTOMKILL_GOAT )
  275.                         {
  276.                                 LogPlayerEvent(attacker, "triggered", "kill_goat");
  277.                                 return;
  278.                         }
  279.                        
  280.                         LogPlayerEvent(victim, "committed suicide with", weapon);
  281.                 }
  282.                
  283.                 dump_player_stats( victim );
  284.         }
  285. }
  286.  
  287. public Event_PlayerSpawn( Handle:event, const String:name[], bool:dontBroadcast )
  288. {
  289.         new client = GetClientOfUserId(G etEventInt( event, "userid" ) );
  290.         if ( client > 0 )
  291.         {
  292.                 reset_player_stats( client );
  293.         }
  294. }
  295.  
  296. public Event_RoundEnd( Handle:event, const String:name[], bool:dontBroadcast )
  297. {
  298.         WstatsDumpAll();
  299. }
  300.  
  301. public OnClientDisconnect( client )
  302. {
  303.         OnPlayerDisconnect( client );
  304. }