PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <reapi>
#pragma semicolon 1
const TASK_ADDBOT = 202724;
new const szBotName[][]={"Zombie","Ghost","Dog"};
new iNpcType[3];
public plugin_init()
{
register_plugin("NPC DeathMsg", "0.0.1", "metal_upa");
remove_task(TASK_ADDBOT);
set_task(2.0, "TaskAddBot", TASK_ADDBOT);
}
public TaskAddBot()
{
new id, szReason[128];
for(new i = 0; i < 3; i++)
{
id = engfunc(EngFunc_CreateFakeClient, szBotName[i]);
if(!(1<=id<=MaxClients)) continue;
dllfunc(DLLFunc_ClientConnect, id, szBotName[i], "127.0.0.1", szReason);
dllfunc(DLLFunc_ClientPutInServer, id);
set_pev(id, pev_flags, pev(id, pev_flags) | FL_FAKECLIENT);
rg_set_user_team(id, TEAM_UNASSIGNED, MODEL_UNASSIGNED);
iNpcType[i] = id; //save bot id here.
}
}
SendDeathMsg(atk, vic)
{
new szWeaponName[32]; //get attacker's weapon.
new wpn = get_member(atk, m_pActiveItem);
if(is_nullent(wpn))
{
copy(szWeaponName, 31, "magic"); //failed to retrieve weapon name, so give a random name.
}
else
{
get_entvar(wpn, var_classname, szWeaponName, 31);
if(!szWeaponName[0]) copy(szWeaponName, 31, "magic"); //failed to retrieve weapon name, so give a random name.
}
replace_stringex(szWeaponName, 31, "weapon_", ""); //remove 'weapon_' string from szWeaponName.
message_begin(MSG_ALL, 83); //DeathMsg=83
write_byte(atk); // killer
write_byte(vic); // victim
write_byte(0); // headshot flag? 1=yes 0=no.
write_string(szWeaponName); // killer's weapon
message_end();
}
//when entity been killed, you need to add SendDeathMsg(attacker, victim) into your plugin.
//Example:
public OnNpcKilled(npc, atk)
{
if(!is_user_connected(atk)) return;
new szClassName[32];
get_entvar(npc, var_classname, szClassName, 31);
for(new i = 0; i < 3; i++)
{
if(equal(szClassName, szBotName[i]))
{
SendDeathMsg(atk, iNpcType[i]);
break;
}
}
}