//#define DEBUG_ENABLE
#if defined DEBUG_ENABLE
#include <VizualizeVector.inl>
#endif
#define FIX_ANGLES // Sets the Angles of the bomb as a player
#define FIX_BUGS // Fix missed a bomb under the map
#include <amxmodx>
#include <fakemeta>
#include <fakemeta_util>
#if defined FIX_BUGS
#include <hamsandwich>
new const CLASSNAME[] = "weapon_c4";
const Float: SITTING = 46.0;
// #define is_on_ground(%1) (fm_distance_to_floor(%1) < SITTING)
#endif
public plugin_init()
{
register_plugin("Bomb fixes", "0.0.1", "wopox1337");
#if defined FIX_ANGLES
register_logevent("bomb_planted", 3, "2=Planted_The_Bomb");
#endif
#if defined FIX_BUGS
RegisterHam(Ham_Weapon_PrimaryAttack, CLASSNAME, "C4_PrimaryAttack_Pre", .Post = false);
#endif
}
#if defined FIX_ANGLES
// Thanks to Voed
public bomb_planted()
{
static Float: vfAngles[3], pPlayer;
pPlayer = get_loguser_index();
pev(pPlayer, pev_v_angle, vfAngles);
new pBomb = engfunc(EngFunc_FindEntityByString, 0, "model", "models/w_c4.mdl");
if(!pev_valid(pBomb))
return PLUGIN_CONTINUE;
vfAngles[0] = 0.0;
vfAngles[1] += 90.0;
set_pev(pBomb, pev_angles, vfAngles);
return PLUGIN_CONTINUE;
}
stock get_loguser_index()
{
new loguser[80], name[32];
read_logargv(0, loguser, charsmax(loguser));
parse_loguser(loguser, name, charsmax(name));
return get_user_index(name);
}
#endif
#if defined FIX_BUGS
public C4_PrimaryAttack_Pre(pEnt)
{
static pPlayer; pPlayer = pev(pEnt, pev_owner);
if(!is_on_ground(pPlayer))
{
#if defined client_printex
client_printex(pPlayer, print_center, "#C4_Plant_Must_Be_On_Ground");
#else
engclient_print(pPlayer, engprint_center, "You must be standing on^n^nthe ground to plant the C4!");
#endif
return HAM_SUPERCEDE;
}
return HAM_IGNORED;
}
#endif
stock is_on_ground(pPlayer)
{
if(fm_distance_to_floor1(pPlayer) < SITTING)
return true;
else
return false;
}
stock Float:fm_distance_to_floor1(index, ignoremonsters = 1) {
new Float:start[3], Float:dest[3], Float:end[3];
pev(index, pev_origin, start);
dest[0] = start[0];
dest[1] = start[1];
dest[2] = -8191.0;
engfunc(EngFunc_TraceLine, start, dest, ignoremonsters, index, 0);
get_tr2(0, TR_vecEndPos, end);
pev(index, pev_absmax, start);
// new Float:ret = floatabs(start[2] - end[2]);
new Float:ret = start[2] - end[2];
#if defined DEBUG_ENABLE
static iStart[3], iEnd[3];
FVecIVec(start, iStart); FVecIVec(end, iEnd);
UTIL_VisualizeVector(
.vStart = iStart,
.vEnd = iEnd,
.time = 0.5,
.width = 3
);
#endif
return ret > 0 ? ret : 0.0;
}
public client_PreThink(pPlayer)
{
client_print(pPlayer, print_center, "To Floor: %.1f", fm_distance_to_floor1(pPlayer));
}