#include <amxmodx>
#include <fakemeta>
#include <reapi>
#include <xs>
new SpriteCode = 1337;
new const SPRITE_MODEL[] = "sprites/bomb.spr";
new const SPRITE_COLOR[3] = { 255, 255, 0 };
const Float: SPRITE_WALL_OFFSET = 10.0;
const Float: SPRITE_SCALE = 0.3;
const Float: SPRITE_SCALE_UNIT = 0.0005;
const Float: UNITS_TO_METER = 40.0;
public plugin_init()
{
new iBombPlace = NULLENT;
while ((iBombPlace = rg_find_ent_by_class(iBombPlace, "func_bomb_target")))
{
CreateSprite(iBombPlace);
}
register_forward(FM_AddToFullPack, "AddToFullPack", true);
}
public plugin_precache()
{
precache_model(SPRITE_MODEL);
}
public AddToFullPack(iState, iE, iEntity, iHost, iHostFlags, iPlayer, pSet)
{
if(get_entvar(iEntity, var_chain) != SpriteCode)
return;
static iTrace;
static Float: flFraction;
static Float: flDistance;
static Float: flScale;
static Float: flFov;
static Float: flFrame;
static Float: vecStart[3];
static Float: vecEnd[3];
static Float: vecViewOfs[3];
static Float: vecViewAngle[3];
static Float: vecEndPos[3];
iTrace = create_tr2();
get_entvar(iHost, var_origin, vecStart);
get_entvar(iEntity, var_origin, vecEnd);
get_entvar(iHost, var_view_ofs, vecViewOfs);
get_entvar(iHost, var_v_angle, vecViewAngle);
get_entvar(iHost, var_fov, flFov);
engfunc(EngFunc_TraceLine, vecStart, vecEnd, IGNORE_MONSTERS, iEntity, iTrace);
xs_vec_sub(vecStart, vecEnd, vecStart);
flFrame = xs_vec_len(vecStart) / UNITS_TO_METER;
get_entvar(iHost, var_origin, vecStart);
get_entvar(iEntity, var_origin, vecEnd);
vecStart[2] += vecViewOfs[2];
engfunc(EngFunc_TraceLine, vecStart, vecEnd, IGNORE_MONSTERS, iHost, iTrace);
get_tr2(0, TR_flFraction, flFraction);
get_tr2(iTrace, TR_vecEndPos, vecEndPos);
get_tr2(iTrace, TR_vecPlaneNormal, vecEnd);
xs_vec_mul_scalar(vecEnd, SPRITE_WALL_OFFSET, vecEnd);
xs_vec_add(vecEnd, vecEndPos, vecEnd);
flDistance = get_distance_f(vecStart, vecEnd);
free_tr2(iTrace);
flScale = SPRITE_SCALE + (SPRITE_SCALE_UNIT * flDistance);
set_es(iState, ES_Origin, vecEnd);
set_es(iState, ES_Frame, flFrame);
set_es(iState, ES_Scale, flScale);
set_es(iState, ES_RenderColor, SPRITE_COLOR);
set_es(iState, ES_MoveType, MOVETYPE_TOSS);
}
CreateSprite(iBombPlace)
{
if (is_nullent(iBombPlace))
return NULLENT;
new Float:fMaxs[3]; get_entvar(iBombPlace, var_absmax, fMaxs);
new Float:fMins[3]; get_entvar(iBombPlace, var_absmin, fMins);
new Float: vecOrigin[3];
vecOrigin[0] = (fMins[0] + fMaxs[0]) * 0.5;
vecOrigin[1] = (fMins[1] + fMaxs[1]) * 0.5;
vecOrigin[2] = (fMins[2] + fMaxs[2]) * 0.5;
new iSprite = rg_create_entity("env_sprite", true);
if(is_nullent(iSprite))
return NULLENT;
engfunc(EngFunc_SetModel, iSprite, SPRITE_MODEL);
engfunc(EngFunc_SetOrigin, iSprite, vecOrigin);
SetEntityRender(iSprite, kRenderFxNoDissipation, Float: { 0.0, 0.0, 0.0 }, kRenderGlow, 255.0);
set_entvar(iSprite, var_chain, SpriteCode);
set_entvar(iSprite, var_effects, get_entvar(iSprite, var_effects) | EF_FORCEVISIBILITY);
return iSprite;
}
SetEntityRender(iEntity, iFx = kRenderFxNone, Float: flColor[3] = { 255.0, 255.0, 255.0 }, iRender = kRenderNormal, Float: flAmount = 16.0)
{
set_entvar(iEntity, var_renderfx, iFx);
set_entvar(iEntity, var_rendercolor, flColor);
set_entvar(iEntity, var_rendermode, iRender);
set_entvar(iEntity, var_renderamt, flAmount);
}