Bueno, se me ocurrió la idea de hacer un plugin sencillo con el mismo sistema del CS:GO que al morir te muestra el daño recibido y provocado. También te lo vuelve a mostrar cuando comienza la siguiente ronda (si no me equivoco) pero yo lo modifiqué para que lo muestre cuando termina la ronda, además si ya moriste no te lo vuelve a mostrar.
Utilicé arrays dinámicas, la verdad que no se utilizarlas muy bien pero estuve leyendo un poco y creo, CREO, que no rompí nada.
Tomo críticas y sugerencias.
Funciones:
EDIT: Fixeado el client_death, lo setea muerto si se suicida o no.
EDIT2: Fixeado que solo reinicie la variable 'g_dead' cuando spawnea el player. 'g_dead' ahora es bool.
EDIT3: Agregué el plugin_end, donde destruye las array.
Utilicé arrays dinámicas, la verdad que no se utilizarlas muy bien pero estuve leyendo un poco y creo, CREO, que no rompí nada.
Tomo críticas y sugerencias.
Funciones:
Código PHP:
/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#define PLUGIN "Damage Dealt"
#define VERSION "1.0"
#define AUTHOR "Ezq"
new Array:g_aAttackers, Array:g_aVictims, Array:g_aDamages, Array:g_aHits;
new bool:g_dead[33];
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
register_event("Damage", "onDamage", "b", "2!0", "3=0", "4!0");
register_event("HLTV", "newRound", "a", "1=0", "2=0");
register_logevent("roundEnd", 2, "1=Round_End");
RegisterHam(Ham_Spawn, "player", "Ham_PlayerSpawn_Post", 1);
// Creo las array
g_aAttackers = ArrayCreate(1);
g_aVictims = ArrayCreate(1);
g_aDamages = ArrayCreate(1);
g_aHits = ArrayCreate(1);
}
public plugin_end()
{
ArrayDestroy(g_aAttackers);
ArrayDestroy(g_aVictims);
ArrayDestroy(g_aDamages);
ArrayDestroy(g_aHits);
}
public plugin_cfg()
{
// Hago que funcione con el amx apagado (para mix, pcw, etc)
if(is_plugin_loaded("Pause Plugins") > -1)
{
server_cmd("amx_pausecfg add ^"%s^"", PLUGIN);
}
}
public newRound()
{
// Limpio las array al comenzar la nueva ronda.
ArrayClear(g_aAttackers);
ArrayClear(g_aVictims);
ArrayClear(g_aDamages);
ArrayClear(g_aHits);
}
public roundEnd()
{
new players[32], num;
get_players(players, num, "a");
/* Cuando termina la ronda le muestro el daño recibido y provocado
de todos los players que están conectados y no murieron */
for(new i = 0; i < num; i++)
{
if(is_user_connected(i) && !g_dead[i])
{
showDamageTaken(i);
showDamageGiven(i);
}
}
}
public Ham_PlayerSpawn_Post(id)
{
if(is_user_alive(id))
{
// Cuando spawnean les seteo la variable 'g_dead' en falso.
g_dead[id] = false;
}
}
public client_death(killer, victim, wpnindex, hitplace, TK)
{
if(killer != victim) // Si no se suicida
{
// Al morir le muestro el daño que recibió y causó (a la victima).
showDamageTaken(victim);
showDamageGiven(victim);
}
g_dead[victim] = true;
}
public onDamage(victim)
{
static attacker; attacker = get_user_attacker(victim);
static damage; damage = read_data(2);
if(is_user_connected(attacker))
{
static bool:exists;
/* Busco si el atacante y la victima coinciden, de ser así,
acumulo el daño y agrego 1 al contador de hits,
y seteo la variable exists en verdadero (o sea, que hay coincidencia) */
for(new i = 0; i < ArraySize(g_aAttackers); i++)
{
if(ArrayGetCell(g_aAttackers, i) == attacker && ArrayGetCell(g_aVictims, i) == victim)
{
ArraySetCell(g_aDamages, i, ArrayGetCell(g_aDamages, i) + _:damage);
ArraySetCell(g_aHits, i, ArrayGetCell(g_aHits, i) + 1);
exists = true;
break;
}
}
if(!exists) // Si no existe simplemente los agrego a los array.
{
ArrayPushCell(g_aAttackers, attacker);
ArrayPushCell(g_aVictims, victim);
ArrayPushCell(g_aDamages, _:damage);
ArrayPushCell(g_aHits, 1);
}
}
}
public showDamageTaken(id)
{
// Defino nuevas array para guardar la info y que sea mas simple mostrarla.
new Array: a_attackers; a_attackers = ArrayCreate(1);
new Array: a_damages; a_damages = ArrayCreate(1);
new Array: a_hits; a_hits = ArrayCreate(1);
/* Busco si dentro de mi array de victimas aparece el id (quien murió)
y guardo los datos de los atacantes (id, daño, hits) en mis array secundarias.*/
for(new i = 0; i < ArraySize(g_aVictims); i++)
{
if(ArrayGetCell(g_aVictims, i) == id)
{
ArrayPushCell(a_attackers, ArrayGetCell(g_aAttackers, i));
ArrayPushCell(a_damages, ArrayGetCell(g_aDamages, i));
ArrayPushCell(a_hits, ArrayGetCell(g_aHits, i));
}
}
// Obtengo el name del player (en este caso la victima)
new playerName[32]; get_user_name(id, playerName, sizeof(playerName));
console_print(id, "");
console_print(id, "%s - Daño recibido", playerName);
console_print(id, "------------------------------");
// Recorro todos los atacantes y los muestro en la consola de la victima
for(new i = 0; i < ArraySize(a_attackers); i++)
{
new attackerName[32], damage, hits;
get_user_name(ArrayGetCell(a_attackers, i), attackerName, sizeof(attackerName));
damage = ArrayGetCell(a_damages, i);
hits = ArrayGetCell(a_hits, i);
console_print(id, "Daño recibido de ^"%s^" - %d en %d hit(s)", attackerName, damage, hits);
}
}
public showDamageGiven(id)
{
// Defino nuevas array para guardar la info y que sea mas simple mostrarla.
new Array: a_victims; a_victims = ArrayCreate(1);
new Array: a_damages; a_damages = ArrayCreate(1);
new Array: a_hits; a_hits = ArrayCreate(1);
/* Busco si dentro de mi array de victimas aparece el id (quien murió)
y guardo los datos de las victimas (id, daño, hits) en mis array secundarias.*/
for(new i = 0; i < ArraySize(g_aAttackers); i++)
{
if(ArrayGetCell(g_aAttackers, i) == id)
{
ArrayPushCell(a_victims, ArrayGetCell(g_aVictims, i));
ArrayPushCell(a_damages, ArrayGetCell(g_aDamages, i));
ArrayPushCell(a_hits, ArrayGetCell(g_aHits, i));
}
}
// Obtengo el name del player (en este caso el atacante)
new playerName[32]; get_user_name(id, playerName, sizeof(playerName));
console_print(id, "");
console_print(id, "%s - Daño provocado", playerName);
console_print(id, "------------------------------");
// Recorro todos las victimas y los muestro en la consola del atacante
for(new i = 0; i < ArraySize(a_victims); i++)
{
new victimName[32], damage, hits;
get_user_name(ArrayGetCell(a_victims, i), victimName, sizeof(victimName));
damage = ArrayGetCell(a_damages, i);
hits = ArrayGetCell(a_hits, i);
console_print(id, "Daño provocado a ^"%s^" - %d en %d hit(s)", victimName, damage, hits);
}
}
EDIT: Fixeado el client_death, lo setea muerto si se suicida o no.
EDIT2: Fixeado que solo reinicie la variable 'g_dead' cuando spawnea el player. 'g_dead' ahora es bool.
EDIT3: Agregué el plugin_end, donde destruye las array.