#pragma semicolon 1
#include <amxmodx>
#include <fakemeta>
#include <engine>
#include <xs>
new g_Backpack_SmokeSprite;
#define BOMB_PACK_ICON "sprites/backpack_smoke/backpack_ring.spr"
#define RING_CLASSNAME "Bomb_Ring"
#define RING_BOMB_ENTITY pev_iuser1
new Float:fColor[][3] =
{
{255.0, 0.0, 0.0},
{0.0, 0.0, 255.0},
{0.0, 255.0, 0.0},
{255.0, 255.0, 6.0},
{255.0, 0.0, 255.0}
};
public plugin_init()
{
register_touch("worldspawn", "weaponbox", "weaponboxTouch");
register_think(RING_CLASSNAME, "ringThink");
}
public plugin_precache()
{
g_Backpack_SmokeSprite = precache_model("sprites/backpack_smoke/backpack_smoke.spr");
precache_model(BOMB_PACK_ICON);
}
public weaponboxTouch(iWorldSpawn, iBombEntity)
{
if(!pev_valid(iBombEntity))
return PLUGIN_HANDLED;
static szBombModel[32];
pev(iBombEntity, pev_model, szBombModel, charsmax(szBombModel));
if(containi(szBombModel, "w_backpack") == -1)
return PLUGIN_HANDLED;
if(pev(iBombEntity, pev_flags) & ~FL_ONGROUND)
return PLUGIN_HANDLED;
static Float:vecOrigin[3];
pev(iBombEntity, pev_origin, vecOrigin);
// lie flat code ^^
static Float:fTraceTo[3], Float:fFraction;
xs_vec_sub(vecOrigin, Float:{0.0, 0.0, 10.0}, fTraceTo);
engfunc(EngFunc_TraceLine, vecOrigin, fTraceTo, IGNORE_MONSTERS, iBombEntity, 0);
get_tr2(0, TR_flFraction, fFraction);
if(fFraction == 1.0)
return PLUGIN_HANDLED;
static bombEntity;bombEntity = pev(iBombEntity, RING_BOMB_ENTITY);
if(bombEntity)
{
if(bombEntity > get_maxplayers())
{
remove_task(iBombEntity);
set_task(0.5, "makeBombFloat", iBombEntity);
}
return PLUGIN_HANDLED;
}
switch(random_num(0, 1))
{
case 0:
{
remove_task(iBombEntity);
set_pev(iBombEntity, RING_BOMB_ENTITY, pev(iBombEntity, pev_owner));
smokeEffect(iBombEntity);
}
case 1:
{
new iEnt = create_entity("env_sprite");
if(pev_valid(iEnt))
{
set_pev(iBombEntity, RING_BOMB_ENTITY, iEnt);
remove_task(iBombEntity);
set_task(0.5, "makeBombFloat", iBombEntity);
}
}
}
return PLUGIN_HANDLED;
}
public makeBombFloat(iBombEntity)
{
if(!pev_valid(iBombEntity))
return;
static Float:vecOrigin[3], iRingEntity;iRingEntity = pev(iBombEntity, RING_BOMB_ENTITY);
pev(iBombEntity, pev_origin, vecOrigin);
vecOrigin[2] += 30.0;
engfunc(EngFunc_SetOrigin, iBombEntity, vecOrigin);
// use this to change the ring origin, so you can make the bomb be right in the middle
vecOrigin[2] += 0.0;
engfunc(EngFunc_SetOrigin, iRingEntity, vecOrigin);
set_pev(iRingEntity, pev_classname, RING_CLASSNAME);
engfunc(EngFunc_SetOrigin, iRingEntity, vecOrigin);
engfunc(EngFunc_SetModel, iRingEntity, BOMB_PACK_ICON);
set_pev(iRingEntity, pev_solid, SOLID_NOT);
set_pev(iRingEntity, pev_movetype, MOVETYPE_FLY);
set_pev(iRingEntity, pev_nextthink, get_gametime());
set_pev(iRingEntity, RING_BOMB_ENTITY, iBombEntity);
set_pev(iRingEntity, pev_rendercolor, fColor[random_num(0, charsmax(fColor))]);
}
public smokeEffect(iBombEntity)
{
if(!pev_valid(iBombEntity))
return;
static Float:vecOrigin[3];
pev(iBombEntity, pev_origin, vecOrigin);
engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, vecOrigin, 0);
write_byte(TE_FIREFIELD);
engfunc(EngFunc_WriteCoord, vecOrigin[0]);
engfunc(EngFunc_WriteCoord, vecOrigin[1]);
engfunc(EngFunc_WriteCoord, vecOrigin[2] += 15.0);
write_short(2);
write_short(g_Backpack_SmokeSprite);
write_byte(1);
write_byte(TEFIRE_FLAG_ALLFLOAT | TEFIRE_FLAG_ALPHA);
write_byte(10);
message_end();
set_task(0.3, "smokeEffect", iBombEntity);
}
public ringThink(ent)
{
if(!pev_valid(ent))
return;
if(!pev_valid(pev(ent, RING_BOMB_ENTITY)))
{
remove_entity(ent);
return;
}
set_pev(ent, pev_nextthink, get_gametime() + 0.5);
}