/*
 * zp_parachute.sma - Invisible parachute for all players.
 * Hold E (use key) while falling to slow descent.
 * No model, no visual distraction. Works for humans AND zombies.
 *
 * Uses gradual velocity deceleration (the standard amx_parachute approach)
 * instead of hard-clamping, which caused jerky/stuttery movement.
 */
#include <amxmodx>
#include <fakemeta>

#define PLUGIN  "[ZP] Invisible Parachute"
#define VERSION "1.1"
#define AUTHOR  "nogame.ro"

#define PARACHUTE_FALL   -150.0   /* target gentle fall speed (negative = down) */
#define DECEL             40.0    /* deceleration per frame (how fast chute deploys) */

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_forward(FM_PlayerPreThink, "fw_PlayerPreThink")
}

public fw_PlayerPreThink(id)
{
    if (!is_user_alive(id))
        return FMRES_IGNORED

    /* Must be holding E (IN_USE) */
    if (!(pev(id, pev_button) & IN_USE))
        return FMRES_IGNORED

    /* Must be in the air */
    if (pev(id, pev_flags) & FL_ONGROUND)
        return FMRES_IGNORED

    static Float:velocity[3]
    pev(id, pev_velocity, velocity)

    /* Only slow if falling (negative Z velocity) */
    if (velocity[2] < 0.0)
    {
        /*
         * Gradual deceleration: add DECEL units per frame toward PARACHUTE_FALL.
         * If still falling faster than target: nudge up by DECEL.
         * If at or slower than target: clamp to target.
         * This produces a smooth slowdown instead of a hard snap.
         */
        if (velocity[2] + DECEL < PARACHUTE_FALL)
            velocity[2] = velocity[2] + DECEL
        else
            velocity[2] = PARACHUTE_FALL

        set_pev(id, pev_velocity, velocity)
    }

    return FMRES_IGNORED
}
