#define Radian2Degree(%1) (%1 * 180.0 / M_PI)
#define Distance2D(%1,%2) floatsqroot((%1*%1) + (%2*%2))
public OnCamThink(iCameraEnt)
{
new id = get_entvar(iCameraEnt, var_owner);
if(!is_user_alive(id) || !is_entity(iCameraEnt))
return;
new iTrace = create_tr2();
new Float:flPlayerOrigin[XYZ], Float:flPlayerEndVision[XYZ],Float:flPlayerPunchAngle[XYZ], Float:flCamOrigin[XYZ], Float:flVecPlayerAngles[XYZ], Float:flVecCamAngles[XYZ], Float:flVecCamAngles_Side[XYZ], Float:flVecCamAngles_Up[XYZ];
get_entvar(id, var_origin, flPlayerOrigin);
get_entvar(id, var_view_ofs, flVecPlayerAngles);
flPlayerOrigin[Z] += flVecPlayerAngles[Z];
get_entvar(id, var_v_angle, flVecPlayerAngles);
// if (g_bCamInverseCam[id])
// {
// set_visibility(0, id, es_angles, g_flAngles[id]);
// flVecPlayerAngles[1] *= -1.0;
// }
// else
// {
// unset_visibility(0, id, es_angles);
// }
angle_vector(flVecPlayerAngles, ANGLEVECTOR_FORWARD, flVecCamAngles);
angle_vector(flVecPlayerAngles, ANGLEVECTOR_RIGHT, flVecCamAngles_Side);
angle_vector(flVecPlayerAngles, ANGLEVECTOR_UP, flVecCamAngles_Up);
// xs_vec_sub_scaled(flPlayerOrigin, flVecCamAngles, g_flCamDistance[id], flCamOrigin);
// xs_vec_sub_scaled(flPlayerOrigin, flVecCamAngles_Side, -25.0, flCamOrigin);
for (new i; i<3; i++)
flCamOrigin[i] = flPlayerOrigin[i] - flVecCamAngles[i] * g_flCamDistance[i] + flVecCamAngles_Side[i] * 10.0 + flVecCamAngles_Up[i] * 5.0;
engfunc(EngFunc_TraceLine, flPlayerOrigin, flCamOrigin, IGNORE_MONSTERS, id, iTrace);
new Float:flFraction, Float:flEnd[3];
get_tr2(iTrace, TR_flFraction, flFraction);
// xs_vec_sub_scaled(flPlayerOrigin, flVecCamAngles, flFraction * g_flCamDistance[id], flCamOrigin);
for (new i; i<3; i++)
flCamOrigin[i] = flPlayerOrigin[i] - flVecCamAngles[i] * g_flCamDistance[id] * flFraction + flVecCamAngles_Side[i] * g_flCamDistance_Side[id] + flVecCamAngles_Up[i] * g_flCamDistance_Up[id];
// get_entvar(id, var_punchangle, flPlayerPunchAngle);
xs_vec_add(flVecPlayerAngles, flPlayerPunchAngle, flVecPlayerAngles);
angle_vector(flVecPlayerAngles, ANGLEVECTOR_FORWARD, flVecCamAngles);
angle_vector(flVecPlayerAngles, ANGLEVECTOR_RIGHT, flVecCamAngles_Side);
angle_vector(flVecPlayerAngles, ANGLEVECTOR_UP, flVecCamAngles_Up);
for (new i; i<3; i++)
flPlayerEndVision[i] = flPlayerOrigin[i] + flVecCamAngles[i] * 8192.0 + flVecCamAngles_Side[i] + flVecCamAngles_Up[i];
engfunc(EngFunc_TraceLine, flPlayerOrigin, flPlayerEndVision, DONT_IGNORE_MONSTERS, id, iTrace);
if(get_distance_f(flPlayerOrigin, flPlayerEndVision) > 400.0)
{
get_tr2(iTrace, TR_vecEndPos, flPlayerEndVision);
}
// static Float:flSend;
// if (flSend < get_gametime())
// {
// flSend = get_gametime() + 0.2;
// zp_debug_draw_line(flPlayerOrigin, flEnd, 0.15, 5);
// }
set_entvar(iCameraEnt, var_origin, flCamOrigin);
aim_at_origin(iCameraEnt, flPlayerEndVision, flVecPlayerAngles);
set_entvar(iCameraEnt, var_angles, flVecPlayerAngles);
set_entvar(iCameraEnt, var_nextthink, get_gametime() + 0.01);
}
stock aim_at_origin(id,const Float:origin[3],Float:angles[3]) { //stock base by Lord of Destruction
static Float:DeltaOrigin[3], Float:orig[3]
pev(id,pev_origin, orig)
DeltaOrigin[0] = orig[0] - origin[0]
DeltaOrigin[1] = orig[1] - origin[1]
DeltaOrigin[2] = orig[2] - origin[2]/* + 16.0*/ //bot keeps aiming too high
angles[0] = Radian2Degree(floatatan(DeltaOrigin[2] / Distance2D(DeltaOrigin[0], DeltaOrigin[1]),0))
angles[1] = Radian2Degree(floatatan(DeltaOrigin[1] / DeltaOrigin[0],0))
if(DeltaOrigin[0] >= 0.0) angles[1] += 180.0
}