Quote:
Originally Posted by Mika Misori
Does anyone know a plugin that report the damage done to tank into the chat, but does not count the damage from molotov?
I found only this plugin: https://forums.alliedmods.net/showthread.php?t=329865
but it is for statistics, which is displayed on transition to the next map.
I want to know who really shot/hit tank and how much real damage was done by player's guns/melee, but not the damage from someone threw a molo, after which all just run away from tank.
|
Untested
PHP Code:
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
#define PLUGIN_VERSION "1.0"
int g_iPlayerTankDamage [MAXPLAYERS+1][MAXPLAYERS+1];
public void OnPluginStart()
{
HookEvent("player_hurt", Event_PlayerHurt, EventHookMode_Post);
HookEvent("tank_killed", Event_TankKilled, EventHookMode_Post);
HookEvent("player_death", Event_TankKilled, EventHookMode_Post);
}
void Event_PlayerHurt(Event event, const char[] name, bool dontBroadcast)
{
int victim = GetClientOfUserId(event.GetInt("userid"));
if (!victim || !IsPlayerTank(victim) || IsTankInDeathAnimation(victim)) return;
int attacker = GetClientOfUserId(event.GetInt("attacker"));
if (!attacker || !IsClientInGame(attacker) || GetClientTeam(attacker) != 2) return;
int iDamage = event.GetInt("dmg_health");
int iType = event.GetInt("type");
//This line to uncount fire damage, if it doesnt work, you need to check the fire damage type and block it, I cant access the game atm
if(IsFireDamage(iType)) iDamage = 0;
g_iPlayerTankDamage[attacker][victim] += iDamage;
}
void Event_TankKilled(Event event, const char[] name, bool dontBroadcast)
{
int victim = GetClientOfUserId(event.GetInt("userid"));
if (!victim || !IsPlayerTank(victim)) return;
PrintTankDamageStatus(victim);
}
//This part was modified from > https://forums.alliedmods.net/showthread.php?p=2559282
void PrintTankDamageStatus(int victim)
{
int iSurvivor, iPlayer[MAXPLAYERS+1][2];
for (int i = 1; i <= MaxClients; i++)
{
if (g_iPlayerTankDamage[i][victim] <= 0 || !IsClientInGame(i) || GetClientTeam(i) != 2) continue;
iPlayer[iSurvivor][0] = i;
iPlayer[iSurvivor][1] = g_iPlayerTankDamage[i][victim];
iSurvivor++;
}
if (iSurvivor == 0) return;
SortCustom2D(iPlayer, iSurvivor, SortDescending);
char sMessage[256];
for (int i; i < iSurvivor; i++)
{
int attacker = iPlayer[i][0];
char sTemp[64];
Format(sTemp, sizeof(sTemp), "\x01%s \x05%N \x01(\x04%d \x01dmg)", (i > 0 ? ", " : ""), attacker, g_iPlayerTankDamage[attacker][victim]);
StrCat(sMessage, sizeof(sMessage), sTemp);
g_iPlayerTankDamage[attacker][victim] = 0;
}
PrintToChatAll("\x04[Notify] \x03%N \x01killed: %s\x01.", victim, sMessage);
}
int SortDescending(int[] elem1, int[] elem2, const int[][] array, Handle hndl)
{
return elem2[0] - elem1[0];
}
bool IsPlayerTank(int client)
{
return (IsClientInGame(client) && GetClientTeam(client) == 3 && GetEntProp(client, Prop_Send, "m_zombieClass") == 8);
}
bool IsTankInDeathAnimation(int client)
{
return (GetEntProp(client, Prop_Send, "m_isIncapacitated", 1) > 0 || GetEntProp(client, Prop_Send, "m_nSequence") >= 65 || !IsPlayerAlive(client));
}
bool IsFireDamage(int damagetype)
{
return (damagetype == DMG_BURN || damagetype == DMG_PREVENT_PHYSICS_FORCE + DMG_BURN || damagetype == DMG_DIRECT + DMG_BURN);
}
__________________