/*
* Landing Lab (olds.ro workshop card AMX-044)
*
* Kreedz practice: a player who turned it on with /landlab and lands inside a
* training zone gets one short recap of that landing:
* Landing: 250 u/s on touch-down, dropped 64 units (fall speed 410)
* Nothing is collected outside the zones, during a ranked run, or across a
* teleport or checkpoint restore.
*
* say /landlab turn the recap on or off for yourself (off by default)
*
* How a landing is seen: every frame (FM_PlayerPostThink) the plugin reads
* pev_flags. Leaving the ground starts a jump and records the height
* (pev_origin z); while airborne it keeps the last horizontal speed and fall
* speed; the first frame with FL_ONGROUND again is the landing.
* A jump is thrown away (no recap) when:
* - the player leaves the zone at any time between take-off and landing;
* - the player moves further in one frame than their speed allows (a
* teleport or a checkpoint restore), or the player respawns;
* - the player is in a ranked run (see below).
*
* Ranked runs: KZ cores keep this state differently, so the plugin offers two
* natives (library "olds_landlab") a core or a small bridge can call:
* olds_landlab_set_ranked(id, bool:ranked) ranked: nothing is shown or stored
* olds_landlab_teleported(id) drop the current jump now
* Without a bridge every run counts as practice.
*
* Zones: addons/amxmodx/configs/olds_landlab/<map>.ini, one box per line:
* "Zone name" x1 y1 z1 x2 y2 z2
* A map without zones shows no recap (/landlab says so).
*
* Cvar: olds_landlab_hud 1 (1 = DHUD line, 0 = chat).
* Command: olds_landlab_status (ADMIN_CFG).
*
* Copyright (C) 2026 daemon (olds.ro)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <reapi>
#define PLUGIN "Landing Lab"
#define VERSION "1.0.0"
#define AUTHOR "olds.ro"
const MAX_ZONES = 32
const ZONE_NAME = 32
const Float:TELEPORT_SLACK = 48.0
new g_name[MAX_ZONES][ZONE_NAME]
new Float:g_min[MAX_ZONES][3]
new Float:g_max[MAX_ZONES][3]
new g_count
new g_file[128]
new bool:g_on[MAX_PLAYERS + 1]
new bool:g_ranked[MAX_PLAYERS + 1]
new bool:g_wasOnGround[MAX_PLAYERS + 1]
new bool:g_airborne[MAX_PLAYERS + 1] // a jump inside a zone is being collected
new Float:g_takeoffZ[MAX_PLAYERS + 1]
new Float:g_speed[MAX_PLAYERS + 1] // last horizontal speed in the air
new Float:g_fall[MAX_PLAYERS + 1] // last fall speed in the air
new Float:g_last[MAX_PLAYERS + 1][3] // origin in the previous frame
new g_recaps[MAX_PLAYERS + 1]
new Float:g_nextUse[MAX_PLAYERS + 1]
new g_forward
new g_hud
public plugin_natives()
{
register_library("olds_landlab")
register_native("olds_landlab_set_ranked", "native_set_ranked")
register_native("olds_landlab_teleported", "native_teleported")
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_landlab.txt")
bind_pcvar_num(create_cvar("olds_landlab_hud", "1", FCVAR_NONE,
"1 = landing recap as a DHUD line, 0 = in chat.", true, 0.0, true, 1.0), g_hud)
AutoExecConfig(true, "olds_landlab")
register_clcmd("say /landlab", "cmd_landlab")
register_clcmd("say_team /landlab", "cmd_landlab")
register_concmd("olds_landlab_status", "cmd_status", ADMIN_CFG, "- zones and who has the recap on")
RegisterHookChain(RG_CBasePlayer_Spawn, "on_spawn_post", true)
load_zones()
if (g_count)
g_forward = register_forward(FM_PlayerPostThink, "on_post_think", true)
}
public plugin_end()
{
if (g_forward)
unregister_forward(FM_PlayerPostThink, g_forward, true)
}
/* ---------- zones ---------- */
load_zones()
{
new map[64]
get_mapname(map, charsmax(map))
get_configsdir(g_file, charsmax(g_file))
format(g_file, charsmax(g_file), "%s/olds_landlab/%s.ini", g_file, map)
new file = fopen(g_file, "rt")
if (!file)
return
new line[256], name[ZONE_NAME], value[6][16], number
while (fgets(file, line, charsmax(line)))
{
number++
trim(line)
if (!line[0] || line[0] == ';' || (line[0] == '/' && line[1] == '/'))
continue
if (g_count == MAX_ZONES)
{
log_amx("%s: more than %d zones, the rest are ignored", g_file, MAX_ZONES)
break
}
if (parse(line, name, charsmax(name), value[0], charsmax(value[]), value[1], charsmax(value[]),
value[2], charsmax(value[]), value[3], charsmax(value[]), value[4], charsmax(value[]),
value[5], charsmax(value[])) != 7 || !name[0] || !all_numbers(value))
{
log_amx("%s line %d: expected ^"name^" x1 y1 z1 x2 y2 z2, skipped", g_file, number)
continue
}
for (new axis = 0; axis < 3; axis++)
{
new Float:a = str_to_float(value[axis]), Float:b = str_to_float(value[axis + 3])
g_min[g_count][axis] = floatmin(a, b)
g_max[g_count][axis] = floatmax(a, b)
}
copy(g_name[g_count], charsmax(g_name[]), name)
g_count++
}
fclose(file)
}
bool:all_numbers(const value[6][16])
{
for (new v = 0; v < 6; v++)
{
new i = (value[v][0] == '-' || value[v][0] == '+') ? 1 : 0, digits
for (; value[v][i]; i++)
{
if (isdigit(value[v][i]))
digits++
else if (value[v][i] != '.')
return false
}
if (!digits)
return false
}
return true
}
bool:in_zone(const Float:origin[3])
{
for (new z = 0; z < g_count; z++)
if (g_min[z][0] <= origin[0] <= g_max[z][0] && g_min[z][1] <= origin[1] <= g_max[z][1]
&& g_min[z][2] <= origin[2] <= g_max[z][2])
return true
return false
}
/* ---------- every frame ---------- */
public on_post_think(id)
{
if (!(1 <= id <= MaxClients) || !g_on[id] || !is_user_alive(id))
return FMRES_IGNORED
new Float:origin[3], Float:velocity[3]
pev(id, pev_origin, origin)
pev(id, pev_velocity, velocity)
new bool:onGround = bool:(pev(id, pev_flags) & FL_ONGROUND)
// Moved further than the speed allows: a teleport or a restore.
new Float:frame = Float:global_get(glb_frametime)
new Float:allowed = vector_length(velocity) * floatmax(frame, 0.001) * 2.0 + TELEPORT_SLACK
if (g_airborne[id] && get_distance_f(origin, g_last[id]) > allowed)
g_airborne[id] = false
g_last[id] = origin
if (g_ranked[id] || !in_zone(origin))
{
g_airborne[id] = false // stop collecting outside the zones and in ranked runs
g_wasOnGround[id] = onGround
return FMRES_IGNORED
}
if (!onGround)
{
if (g_wasOnGround[id])
{
g_airborne[id] = true
g_takeoffZ[id] = origin[2]
}
if (g_airborne[id])
{
g_speed[id] = floatsqroot(velocity[0] * velocity[0] + velocity[1] * velocity[1])
g_fall[id] = -velocity[2]
}
}
else if (!g_wasOnGround[id] && g_airborne[id])
{
g_airborne[id] = false
recap(id, g_takeoffZ[id] - origin[2])
}
g_wasOnGround[id] = onGround
return FMRES_IGNORED
}
recap(id, Float:drop)
{
g_recaps[id]++
new speed = floatround(g_speed[id]), dropped = floatround(drop), fall = floatround(floatmax(g_fall[id], 0.0))
new line[128]
if (dropped >= 0)
formatex(line, charsmax(line), "%L", id, "LANDLAB_RECAP_DROP", speed, dropped, fall)
else
formatex(line, charsmax(line), "%L", id, "LANDLAB_RECAP_UP", speed, -dropped, fall)
if (g_hud)
{
set_dhudmessage(120, 230, 160, -1.0, 0.66, 0, 0.0, 2.5, 0.1, 0.4)
show_dhudmessage(id, "%s", line)
}
else
client_print_color(id, print_team_default, "^4[Landing Lab]^1 %s", line)
}
drop_jump(id)
{
g_airborne[id] = false
g_wasOnGround[id] = true
}
public on_spawn_post(id)
{
if (1 <= id <= MaxClients)
drop_jump(id)
return HC_CONTINUE
}
/* ---------- natives for a KZ core or bridge ---------- */
public native_set_ranked(plugin, params)
{
new id = get_param(1)
if (!(1 <= id <= MaxClients))
{
log_error(AMX_ERR_NATIVE, "olds_landlab_set_ranked: invalid player %d", id)
return 0
}
g_ranked[id] = get_param(2) != 0
if (g_ranked[id])
drop_jump(id)
return 1
}
public native_teleported(plugin, params)
{
new id = get_param(1)
if (!(1 <= id <= MaxClients))
{
log_error(AMX_ERR_NATIVE, "olds_landlab_teleported: invalid player %d", id)
return 0
}
drop_jump(id)
return 1
}
/* ---------- commands ---------- */
public cmd_landlab(id)
{
if (!is_user_connected(id))
return PLUGIN_HANDLED
new Float:now = get_gametime()
if (now < g_nextUse[id])
return PLUGIN_HANDLED
g_nextUse[id] = now + 1.0
if (!g_count)
{
client_print_color(id, print_team_default, "^4[Landing Lab]^1 %L", id, "LANDLAB_NO_ZONES")
return PLUGIN_HANDLED
}
g_on[id] = !g_on[id]
drop_jump(id)
client_print_color(id, print_team_default, "^4[Landing Lab]^1 %L", id, g_on[id] ? "LANDLAB_ON" : "LANDLAB_OFF")
return PLUGIN_HANDLED
}
public client_putinserver(id)
{
g_on[id] = false
g_ranked[id] = false
g_recaps[id] = 0
drop_jump(id)
}
public client_disconnected(id)
{
g_on[id] = false
g_ranked[id] = false
g_recaps[id] = 0
g_nextUse[id] = 0.0
drop_jump(id)
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
console_print(id, "[Landing Lab] %d zone(s) from %s; recap in %s", g_count, g_file, g_hud ? "DHUD" : "chat")
for (new z = 0; z < g_count; z++)
console_print(id, "[Landing Lab] %d. %s", z + 1, g_name[z])
new players[MAX_PLAYERS], count, name[MAX_NAME_LENGTH]
get_players(players, count, "h")
for (new i = 0; i < count; i++)
{
new p = players[i]
if (!g_on[p] && !g_ranked[p])
continue
get_user_name(p, name, charsmax(name))
console_print(id, "[Landing Lab] %s: %s%s, %d recap(s)", name, g_on[p] ? "on" : "off",
g_ranked[p] ? ", ranked" : "", g_recaps[p])
}
return PLUGIN_HANDLED
}