#include <amxmodx>
#include <reapi>
// #define USE_TEAM_COLOR // Uncomment to use team colors, comment to use grenade-specific colors.
#if defined USE_TEAM_COLOR
new g_iColorsTT[] = { 191, 130, 0 }; // RGB Colors for terrorists.
new g_iColorsCT[] = { 0, 130, 191 }; // RGB Colors for counter-terrorists.
#else
new const g_szGrenadeColors[][] = {
{ 191, 130, 0 }, // HE Grenade color.
{ 0, 130, 191 }, // Flashbang color.
{ 0, 255, 0 } // Smoke Grenade color.
};
#endif
enum {
LIFETIME = 3, // Lifetime in seconds.
WIDTH = 2, // Line width.
BRIGHTNESS = 225 // Line brightness.
};
new g_SpriteTrail;
public plugin_precache() {
g_SpriteTrail = precache_model("sprites/smoke.spr");
}
public plugin_init() {
register_plugin("[ReAPI] Grenade Trail", "0.0.2", "mIDnight");
RegisterHookChain(RG_CBasePlayer_ThrowGrenade, "@CBasePlayer_ThrowGrenade_Post", true);
}
@CBasePlayer_ThrowGrenade_Post(UserId, WeaponId) {
new pGrenade = GetHookChainReturn(ATYPE_INTEGER);
if (is_nullent(pGrenade)) {
return HC_CONTINUE;
}
@SetSprite(UserId, pGrenade, WeaponId, LIFETIME, WIDTH, BRIGHTNESS);
return HC_CONTINUE;
}
@SetSprite(UserId, GrenadeId, WeaponId, LifeTime, Width, Brig) {
new teamColor[3];
#if defined USE_TEAM_COLOR
teamColor = get_member(UserId, m_iTeam) == TEAM_TERRORIST ? g_iColorsTT : g_iColorsCT;
#else
new Weapon_iId = get_member(WeaponId, m_iId);
switch (Weapon_iId) {
case WEAPON_HEGRENADE: teamColor = g_szGrenadeColors[0];
case WEAPON_FLASHBANG: teamColor = g_szGrenadeColors[1];
case WEAPON_SMOKEGRENADE: teamColor = g_szGrenadeColors[2];
}
#endif
for (new i = 1; i <= get_maxplayers(); i++) {
if (!is_user_connected(i) || get_member(i, m_iTeam) != get_member(UserId, m_iTeam)) {
continue;
}
message_begin(MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, _, i);
write_byte(TE_BEAMFOLLOW);
write_short(GrenadeId);
write_short(g_SpriteTrail);
write_byte(LifeTime * 10);
write_byte(Width);
write_byte(teamColor[0]);
write_byte(teamColor[1]);
write_byte(teamColor[2]);
write_byte(Brig);
message_end();
}
}