/*
* Fall Damage Blocker (olds.ro workshop card LIB-0266)
*
* Players with an access flag, optionally of one team only, lose no health
* when they fall. On the maps named in a list nobody takes fall damage at
* all. Only fall damage is blocked: the landing sound and animation, and
* every other kind of damage (trigger_hurt, shots, grenades), stay as normal.
*
* Who is protected:
* - on a listed map: every player, whatever the flag and the team;
* - elsewhere: a player of the olds_nofall_team team (0 = both) who has
* one of the olds_nofall_flag access flags ("" = no flag needed).
*
* Commands: none.
*
* Cvars (in configs/plugins/olds_nofall.cfg, which ships with the plugin; if
* the file is missing, the plugin writes it with these defaults the first
* time it starts):
* olds_nofall_flag "b" Access flags that give the protection, any one is
* enough. "" = every player of the team.
* olds_nofall_team 0 0 = both teams, 1 = Terrorists only,
* 2 = Counter-Terrorists only.
* olds_nofall_maps "" More maps where everyone is protected, besides
* the ones in configs/olds_nofall_maps.ini.
* Separate names with spaces or commas; a name that
* ends with * matches every map starting with it
* ("kz_*").
* olds_nofall_msg 0 1 = tell the player in chat each time a fall
* did no damage.
*
* Map file: configs/olds_nofall_maps.ini, one map name (or "prefix*") per
* line; lines starting with ; # or // are comments. It is read when the map
* starts.
*
* How it works, as the card asks: RG_CBasePlayer_TakeDamage (pre) checks
* the DMG_FALL bit and, for a protected player, stops the call with
* HC_SUPERCEDE so the game applies no damage at all. The chat text is in
* data/lang/olds_nofall.txt.
*
* Requires AMX Mod X 1.10 with ReAPI (ReGameDLL_CS). Written and tested on
* AMX Mod X 1.10.0.5490, ReAPI 5.29.0.358 and ReGameDLL_CS 5.30.0.814.
*
* Copyright (C) 2026 alexit (olds.ro workshop)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* 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/>.
*/
#include <amxmodx>
#include <amxmisc>
#include <reapi>
#pragma semicolon 1
new const PLUGIN_NAME[] = "Fall Damage Blocker";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";
// Map list in the configs folder, read at map start.
new const MAPS_FILE[] = "olds_nofall_maps.ini";
// Values of olds_nofall_team.
enum
{
NOFALL_BOTH_TEAMS,
NOFALL_TERRORISTS,
NOFALL_CTS
};
new g_flags[32]; // olds_nofall_flag
new g_team; // olds_nofall_team
new g_extraMaps[256]; // olds_nofall_maps
new g_message; // olds_nofall_msg
new g_mapName[MAX_MAPNAME_LENGTH];
// True when the current map is listed in the map file.
new bool:g_mapInFile;
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
// The damage hook comes from ReGameDLL_CS.
if (!is_regamedll())
set_fail_state("ReGameDLL_CS is not running. This plugin needs ReGameDLL_CS and ReAPI.");
register_dictionary("olds_nofall.txt");
bind_pcvar_string(create_cvar("olds_nofall_flag", "b", FCVAR_NONE,
"Access flags that give fall damage protection, any one is enough (empty = every player of the team)"),
g_flags, charsmax(g_flags));
bind_pcvar_num(create_cvar("olds_nofall_team", "0", FCVAR_NONE,
"0 = both teams, 1 = Terrorists only, 2 = Counter-Terrorists only",
true, 0.0, true, 2.0), g_team);
bind_pcvar_string(create_cvar("olds_nofall_maps", "", FCVAR_NONE,
"More maps where nobody takes fall damage, besides configs/olds_nofall_maps.ini (spaces or commas; name* = prefix)"),
g_extraMaps, charsmax(g_extraMaps));
bind_pcvar_num(create_cvar("olds_nofall_msg", "0", FCVAR_NONE,
"1 = tell the player in chat when a fall did no damage",
true, 0.0, true, 1.0), g_message);
AutoExecConfig(true, "olds_nofall");
get_mapname(g_mapName, charsmax(g_mapName));
g_mapInFile = map_in_file();
RegisterHookChain(RG_CBasePlayer_TakeDamage, "on_take_damage_pre", false);
}
/**
* Runs before the game applies any damage to a player. Only fall damage is
* looked at; everything else passes through untouched.
*/
public on_take_damage_pre(id, inflictor, attacker, Float:damage, damageBits)
{
if (!(damageBits & DMG_FALL) || !is_protected(id))
return HC_CONTINUE;
if (g_message && damage >= 1.0)
client_print_color(id, print_team_default, "%L", id, "NOFALL_BLOCKED", floatround(damage));
// The game's TakeDamage is not called, so no health, armor, pain sound
// or view punch is applied. The landing sound comes from the player's
// movement code and still plays.
SetHookChainReturn(ATYPE_INTEGER, false);
return HC_SUPERCEDE;
}
bool:is_protected(id)
{
// On a listed map everyone is protected, whatever the flag and team.
if (g_mapInFile || map_in_list(g_extraMaps))
return true;
switch (g_team)
{
case NOFALL_TERRORISTS:
{
if (TeamName:get_member(id, m_iTeam) != TEAM_TERRORIST)
return false;
}
case NOFALL_CTS:
{
if (TeamName:get_member(id, m_iTeam) != TEAM_CT)
return false;
}
}
// Read at every fall, so a new olds_nofall_flag and admin flags given
// during the map both count at once.
new needed = read_flags(g_flags);
return !needed || (get_user_flags(id) & needed) != 0;
}
/**
* Tells whether the current map is in a list of names separated by spaces
* or commas.
*/
bool:map_in_list(const list[])
{
if (!list[0])
return false;
new text[sizeof(g_extraMaps)];
copy(text, charsmax(text), list);
replace_string(text, charsmax(text), ",", " ");
new name[MAX_MAPNAME_LENGTH], pos;
while ((pos = argparse(text, pos, name, charsmax(name))) != -1)
{
if (map_matches(name))
return true;
}
return false;
}
/**
* Reads configs/olds_nofall_maps.ini once per map. A missing file simply
* lists no map.
*/
bool:map_in_file()
{
new path[PLATFORM_MAX_PATH];
get_configsdir(path, charsmax(path));
add(path, charsmax(path), "/");
add(path, charsmax(path), MAPS_FILE);
new file = fopen(path, "rt");
if (!file)
return false;
new line[128];
new bool:found;
while (!found && fgets(file, line, charsmax(line)))
{
trim(line);
if (!line[0] || line[0] == ';' || line[0] == '#' || (line[0] == '/' && line[1] == '/'))
continue;
found = map_matches(line);
}
fclose(file);
return found;
}
/**
* Compares one list entry with the current map, ignoring letter case.
* "name*" matches every map whose name starts with "name".
*/
bool:map_matches(const entry[])
{
new length = strlen(entry);
if (!length)
return false;
if (entry[length - 1] == '*')
return length == 1 || equali(g_mapName, entry, length - 1);
return bool:equali(g_mapName, entry);
}