PHP Code:
case TRIP_ATTACHED:
{
static loop[6][2] = { {2, 1}, {2, -1}, {0, 1}, {0, -1}, {1, 1}, {1, -1} }
// Search in order: +Z axis -Z axis +X axis -X axis +Y axis -Y axis
for (new i; i < 6; i++)
{
xs_vec_copy(origin, point)
point[loop[i][0]] = origin[loop[i][0]] + (2.0 * float(loop[i][1]))
engfunc(EngFunc_TraceLine, origin, point, IGNORE_MONSTERS, ent, g_ptrace[TH_TRIP])
get_tr2(g_ptrace[TH_TRIP], TR_flFraction, fraction)
if (fraction < 1.0)
{
hit = get_tr2(g_ptrace[TH_TRIP], TR_pHit)
if (!is_attachable_surface(hit))
{
set_grenade_type(ent, NADE_DUD)
return HAM_IGNORED
}
get_tr2(g_ptrace[TH_TRIP], TR_vecPlaneNormal, normal)
set_trip_grenade_attached_to(ent, hit)
// Calculate and store fly velocity.
xs_vec_mul_scalar(normal, fly_speed, temp)
set_trip_grenade_fly_velocity(ent, temp)
// Calculate and store endpoint.
xs_vec_mul_scalar(normal, detect_distance, temp)
xs_vec_add(temp, origin, end)
// Trace to it
engfunc(EngFunc_TraceLine, origin, end, IGNORE_MONSTERS, ent, g_ptrace[TH_TRIP])
get_tr2(g_ptrace[TH_TRIP], TR_flFraction, fraction)
// Final endpoint with no possible wall collision
xs_vec_mul_scalar(normal, (detect_distance * fraction), temp)
xs_vec_add(temp, origin, end)
set_trip_grenade_end_origin(ent, end)
xs_vec_mul_scalar(temp, 0.5, temp)
xs_vec_add(temp, origin, temp)
set_trip_grenade_middle_origin(ent, temp)
set_trip_grenade_arm_time(ent, arm_time)
play_sound(ent, DEPLOY)
entity_set_vector(ent, EV_VEC_velocity, Float:{0.0, 0.0, 0.0}) // Stop if from moving
entity_set_int(ent, EV_INT_sequence, 0) // Otherwise, grenade might make wierd motions.
vector_to_angle(normal, normal)
entity_set_vector(ent, EV_VEC_angles, normal)
set_trip_grenade_mode(ent, TRIP_WAITING)
set_task(0.1, "trip_activation", ent)
return HAM_IGNORED
}
}
// If we reach here, we have serious problems. This means that the grenade hit something like a func_breakable
// that disappeared before the scan was able to take place. Now, the grenade is floating in mid air. So we just
// kaboom it!!!
make_explode(ent)
if (NadeRace:get_grenade_race(ent) == GRENADE_SMOKEGREN)
{
entity_set_int(ent, EV_INT_flags, entity_get_int(ent, EV_INT_flags) | FL_ONGROUND)
}
return HAM_IGNORED
}