PHP Code:
#include <amxmodx>
#include <fakemeta>
#define CVAR_CHECK_FREQ 1.0
#define BLOOD_COLOR_YELLOW 195
#define BLOOD_COLOR_RED 247
stock const s_chColors[] =
{
000, 007, 015, 031, 047, 063, 079, 095, 103,
106, 110, 111, 123, 127, 128, 130, 144, 146,
160, 165, 176, 179, 192, 193, 196, 202, 208,
212, 216, 225, 231, 234, 237, 238, 239, 240,
241, 242, 243, 244, 245, 246, 248, 249, 250,
251, 252, 253, 255
};
stock random_color()
{
// This method chooses only the more robust colors
return s_chColors[random_num(1, sizeof(s_chColors))-1];
}
new bool:g_bFirstWrite;
new bool:g_bInBloodMsg;
new bool:g_bBloodColorizer;
public plugin_init()
{
register_plugin("Blood Colorizer", "1.1", "ts2do");
register_forward(FM_MessageBegin, "on_message_begin");
register_forward(FM_WriteByte, "on_write_byte");
register_cvar("amx_bloodcolorizer", "1");
set_task(CVAR_CHECK_FREQ, "check_cvar", 0, "", 0, "b");
check_cvar();
}
public check_cvar()
{
g_bBloodColorizer = bool:get_cvar_num("amx_bloodcolorizer");
}
public on_message_begin(msg_dest, msg_type, const Float:fOrigin[3], ed)
{
// We need to know where we are in the message
g_bFirstWrite = g_bBloodColorizer;
}
public on_write_byte(byte)
{
// Here we need to handle two types of blood messages
// Blood color indices are BLOOD_COLOR_RED or BLOOD_COLOR_YELLOW
// #1 Byte 1 is a blood color and needs to be overridden
// #2.1 Byte 1 is either TE_BLOOD, TE_BLOODSPRITE, or TE_BLOODSTREAM
// #2.2 Byte 2 is a blood color and needs to be overridden
if(g_bFirstWrite)
{
// Handling #1
if(byte==BLOOD_COLOR_RED || byte==BLOOD_COLOR_YELLOW)
{
write_byte(random_color());
g_bFirstWrite = false;
return FMRES_SUPERCEDE;
}
// Handling #2.1
g_bInBloodMsg = (byte==TE_BLOOD||byte==TE_BLOODSPRITE||byte==TE_BLOODSTREAM);
g_bFirstWrite = false;
}
else if(g_bInBloodMsg)
{
// Handling #2.1
write_byte(random_color());
g_bInBloodMsg = false;
return FMRES_SUPERCEDE;
}
return FMRES_IGNORED;
}