PHP Code:
#define TASK_EXPLODE 1111
#define EXPLOSION_MAX_DAMAGE 100
#define EXPLOSION_RANGE 300
#define EXPLOSION_BLAST_RADIUS 250
new toucher_owner;
new Float:g_origin[3];
// It's called when the entity is touched
public mine_explosion(toucher, touched)
{
toucher_owner = entity_get_edict(toucher, EV_ENT_owner);
// Only crashing if this check is passed!
if(cs_get_user_team(touched) != cs_get_user_team(toucher_owner))
{
entity_get_vector(toucher, EV_VEC_origin, g_origin);
set_task(0.5, "explode", toucher + TASK_EXPLODE);
emit_sound(toucher, CHAN_AUTO, "ambience/particle_suck1.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
}
}
public explode(toucher)
{
toucher -= TASK_EXPLODE;
new Float:position[3];
position[0] = g_origin[0] + random_float(-100.0, 100.0);
position[1] = g_origin[1] + random_float(-100.0, 100.0);
position[2] = g_origin[2] + random_float(-50.0, 50.0);
te_explosion(Float:g_origin, Float:position, zerogxplode, (random_num(0,20) + 20), 12, TE_EXPLFLAG_NONE);
te_smoke(Float:g_origin, Float:position, steam1, 60, 10);
new players[32], num, i;
get_players(players, num, "a");
new target, Float:target_origin[3], Float:distance, damage;
new multiplier = (EXPLOSION_MAX_DAMAGE * EXPLOSION_MAX_DAMAGE) / EXPLOSION_RANGE;
for(i=0; i<num; i++)
{
target = players[i];
entity_get_vector(target, EV_VEC_origin, target_origin);
distance = get_distance_f(g_origin, target_origin);
if(distance < EXPLOSION_RANGE && cs_get_user_team(toucher_owner) != cs_get_user_team(target))
{
damage = (EXPLOSION_RANGE - floatround(distance)) * multiplier;
damage = sqroot(damage);
ExecuteHamB(Ham_TakeDamage, target, toucher, toucher, damage, DMG_ALWAYSGIB);
remove_entity(toucher);
}
}
}
stock te_explosion(Float:origin[3], Float:position[3], sprite, scale, framerate, flags)
{
engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin);
write_byte(TE_EXPLOSION);
engfunc(EngFunc_WriteCoord, position[0]); // position.x
engfunc(EngFunc_WriteCoord ,position[1]); // position.y
engfunc(EngFunc_WriteCoord, position[2]); // position.z
write_short(sprite); // sprite index
write_byte(scale); // scale in 0.1's
write_byte(framerate); // framerate
write_byte(flags); // flags
message_end();
}
stock te_smoke(Float:origin[3], Float:position[3], sprite, scale, framerate)
{
engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin);
write_byte(TE_SMOKE);
engfunc(EngFunc_WriteCoord, position[0]); // position.x
engfunc(EngFunc_WriteCoord ,position[1]); // position.y
engfunc(EngFunc_WriteCoord, position[2]); // position.z
write_short(sprite); // sprite index
write_byte(scale); // scale in 0.1's
write_byte(framerate); // framerate
message_end();
}