/*
* Edge Landing Damage Block (olds.ro)
* Copyright (C) 2026 daemon (olds.ro), written by daemon's plugin agent
*
* This program is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details: <https://www.gnu.org/licenses/>.
*
* Surf: no fall damage for small clips on ramp edges. Fall damage (Ham_TakeDamage with
* DMG_FALL) is blocked (HAM_SUPERCEDE) when all of these hold:
* - olds_ramp_enable is 1;
* - the player's vertical speed is above -700 (pev_velocity) and the landing speed
* (m_flFallVelocity) is at most olds_ramp_maxspeed;
* - a ramp surface (plane normal z between 0.05 and 0.7) is within olds_ramp_dist units of
* the player's hull, found with EngFunc_TraceHull downwards, sideways and diagonally.
* Any other fall damage applies as usual.
*
* Cvars: olds_ramp_enable 1, olds_ramp_maxspeed 1000, olds_ramp_dist 32
*/
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <reapi>
#pragma semicolon 0
#define PLUGIN "Edge Landing Damage Block"
#define VERSION "1.0.0"
#define AUTHOR "daemon (olds.ro)"
#define RAMP_MIN_Z 0.05
#define RAMP_MAX_Z 0.7
#define MIN_VEL_Z -700.0
new g_enable
new Float:g_maxSpeed
new Float:g_dist
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
bind_pcvar_num(create_cvar("olds_ramp_enable", "1", FCVAR_NONE,
"Block fall damage on ramp edges", true, 0.0, true, 1.0), g_enable)
bind_pcvar_float(create_cvar("olds_ramp_maxspeed", "1000", FCVAR_NONE,
"Fastest landing (units/s) that is still forgiven", true, 0.0, true, 5000.0), g_maxSpeed)
bind_pcvar_float(create_cvar("olds_ramp_dist", "32", FCVAR_NONE,
"How close (units) a ramp surface must be", true, 1.0, true, 128.0), g_dist)
AutoExecConfig(true, "olds_rampland")
RegisterHam(Ham_TakeDamage, "player", "fw_take_damage", false)
}
/* True when a hull trace from the player in one of 17 directions meets a ramp plane. */
bool:near_ramp(id)
{
new Float:origin[3], Float:end[3], Float:normal[3], Float:fraction
pev(id, pev_origin, origin)
new hull = (pev(id, pev_flags) & FL_DUCKING) ? HULL_HEAD : HULL_HUMAN
new Float:dist = floatclamp(g_dist, 1.0, 128.0)
new trace = create_tr2()
new bool:found
for (new d = 0; d < 17 && !found; d++)
{
new Float:dx, Float:dy, Float:dz
if (d == 16)
dz = -1.0
else
{
new Float:yaw = float(d % 8) * 45.0
dx = floatcos(yaw, degrees)
dy = floatsin(yaw, degrees)
if (d >= 8)
{
/* Diagonally down. */
dx *= 0.7071
dy *= 0.7071
dz = -0.7071
}
}
end[0] = origin[0] + dx * dist
end[1] = origin[1] + dy * dist
end[2] = origin[2] + dz * dist
engfunc(EngFunc_TraceHull, origin, end, IGNORE_MONSTERS, hull, id, trace)
if (get_tr2(trace, TR_StartSolid) || get_tr2(trace, TR_AllSolid))
continue
get_tr2(trace, TR_flFraction, fraction)
if (fraction >= 1.0)
continue
get_tr2(trace, TR_vecPlaneNormal, normal)
if (normal[2] > RAMP_MIN_Z && normal[2] < RAMP_MAX_Z)
found = true
}
free_tr2(trace)
return found
}
public fw_take_damage(victim, inflictor, attacker, Float:damage, bits)
{
if (!g_enable || !(bits & DMG_FALL) || !is_user_alive(victim))
return HAM_IGNORED
new Float:vel[3]
pev(victim, pev_velocity, vel)
new Float:fall = Float:get_member(victim, m_flFallVelocity)
if (vel[2] <= MIN_VEL_Z || fall > g_maxSpeed)
return HAM_IGNORED
if (!near_ramp(victim))
return HAM_IGNORED
new name[MAX_NAME_LENGTH]
get_user_name(victim, name, charsmax(name))
log_amx("%s: %.0f fall damage blocked on a ramp edge (landing at %.0f u/s)", name, damage, fall)
return HAM_SUPERCEDE
}