/*
* Landing Streak (olds.ro) - surf practice: counts consecutive landings across
* an ordered route of named zones.
*
* 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. You should have received a copy of the GNU General Public
* License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <reapi>
#define PLUGIN "Landing Streak"
#define VERSION "1.0.0"
#define AUTHOR "daemon (olds.ro)"
#define MAX_ZONES 32
#define ZONE_NAME 32
new const COUNT_SOUND[] = "buttons/blip1" // stock sound/buttons/blip1.wav, played with spk
new g_zoneName[MAX_ZONES][ZONE_NAME]
new Float:g_zoneMin[MAX_ZONES][3]
new Float:g_zoneMax[MAX_ZONES][3]
new g_zoneCount
new g_streak[MAX_PLAYERS + 1]
new g_best[MAX_PLAYERS + 1]
new g_next[MAX_PLAYERS + 1] // index of the zone that counts next
new g_last[MAX_PLAYERS + 1] // zone of the last landing, -1 = none
new bool:g_ground[MAX_PLAYERS + 1]
new HookChain:g_thinkHook
new g_cvarReset
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_landstreak.txt")
g_cvarReset = create_cvar("olds_landstreak_reset", "1",
.description = "1 = landing in the wrong zone resets the streak, 0 = it is ignored",
.has_min = true, .min_val = 0.0, .has_max = true, .max_val = 1.0)
AutoExecConfig(true, "olds_landstreak")
register_clcmd("say /streak", "cmd_streak")
register_clcmd("say_team /streak", "cmd_streak")
register_concmd("olds_landstreak_status", "cmd_status", ADMIN_CFG, "- zones and streaks")
register_concmd("olds_landstreak_reload", "cmd_reload", ADMIN_CFG, "- reload this map's zones")
RegisterHookChain(RG_CBasePlayer_Spawn, "on_spawn_post", true)
g_thinkHook = RegisterHookChain(RG_CBasePlayer_PostThink, "on_post_think", true)
DisableHookChain(g_thinkHook)
RegisterHam(Ham_Touch, "trigger_teleport", "on_teleport_touch", 1)
}
public plugin_natives()
{
register_library("olds_landstreak")
register_native("olds_landstreak_reset", "native_reset")
register_native("olds_landstreak_get", "native_get")
}
public plugin_cfg()
{
load_zones()
}
/* ---------- zones ---------- */
load_zones()
{
g_zoneCount = 0
for (new id = 1; id <= MaxClients; id++)
reset_streak(id)
new path[192], map[64]
get_configsdir(path, charsmax(path))
get_mapname(map, charsmax(map))
format(path, charsmax(path), "%s/olds_landstreak/%s.ini", path, map)
new file = fopen(path, "rt")
if (!file)
{
DisableHookChain(g_thinkHook)
server_print("[Landing Streak] No route for %s (%s): the plugin is idle on this map.", map, path)
return
}
new line[256], name[ZONE_NAME], number[6][16], lineNo
while (!feof(file) && fgets(file, line, charsmax(line)))
{
lineNo++
trim(line)
if (!line[0] || line[0] == ';' || line[0] == '#' || (line[0] == '/' && line[1] == '/'))
continue
new parts = parse(line, name, charsmax(name), number[0], charsmax(number[]), number[1], charsmax(number[]),
number[2], charsmax(number[]), number[3], charsmax(number[]), number[4], charsmax(number[]),
number[5], charsmax(number[]))
if (parts != 7 || !name[0])
{
log_amx("[Landing Streak] %s line %d skipped: expected ^"name^" x1 y1 z1 x2 y2 z2", path, lineNo)
continue
}
new bool:valid = true
for (new i = 0; i < 6; i++)
{
if (!is_number(number[i]))
{
valid = false
break
}
}
if (!valid)
{
log_amx("[Landing Streak] %s line %d skipped: a coordinate is not a number", path, lineNo)
continue
}
if (g_zoneCount >= MAX_ZONES)
{
log_amx("[Landing Streak] %s: more than %d zones, the rest are skipped", path, MAX_ZONES)
break
}
for (new axis = 0; axis < 3; axis++)
{
new Float:a = str_to_float(number[axis]), Float:b = str_to_float(number[axis + 3])
g_zoneMin[g_zoneCount][axis] = floatmin(a, b)
g_zoneMax[g_zoneCount][axis] = floatmax(a, b)
}
copy(g_zoneName[g_zoneCount], charsmax(g_zoneName[]), name)
g_zoneCount++
}
fclose(file)
if (g_zoneCount)
EnableHookChain(g_thinkHook)
else
DisableHookChain(g_thinkHook)
server_print("[Landing Streak] %d zone(s) loaded for %s.", g_zoneCount, map)
}
bool:is_number(const text[])
{
new i, digits, dots
if (text[0] == '-' || text[0] == '+')
i++
for (; text[i]; i++)
{
if (text[i] == '.')
{
if (++dots > 1)
return false
}
else if ('0' <= text[i] <= '9')
digits++
else
return false
}
return digits > 0
}
zone_at(const Float:origin[3])
{
for (new zone = 0; zone < g_zoneCount; zone++)
{
if (g_zoneMin[zone][0] <= origin[0] <= g_zoneMax[zone][0]
&& g_zoneMin[zone][1] <= origin[1] <= g_zoneMax[zone][1]
&& g_zoneMin[zone][2] <= origin[2] <= g_zoneMax[zone][2])
return zone
}
return -1
}
/* ---------- streaks ---------- */
reset_streak(id)
{
g_streak[id] = 0
g_next[id] = 0
g_last[id] = -1
}
public client_putinserver(id)
{
reset_streak(id)
g_best[id] = 0
g_ground[id] = true
}
public client_disconnected(id)
{
reset_streak(id)
g_best[id] = 0
}
public on_spawn_post(id)
{
if (1 <= id <= MaxClients && is_user_alive(id))
{
reset_streak(id)
g_ground[id] = (get_entvar(id, var_flags) & FL_ONGROUND) != 0
}
return HC_CONTINUE
}
public on_teleport_touch(teleport, id)
{
if (1 <= id <= MaxClients && is_user_connected(id))
break_streak(id)
return HAM_IGNORED
}
public on_post_think(id)
{
if (!is_user_alive(id))
return HC_CONTINUE
new bool:ground = (get_entvar(id, var_flags) & FL_ONGROUND) != 0
if (ground && !g_ground[id])
on_landing(id)
g_ground[id] = ground
return HC_CONTINUE
}
on_landing(id)
{
new Float:origin[3]
get_entvar(id, var_origin, origin)
new zone = zone_at(origin)
if (zone < 0 || zone == g_last[id])
return
g_last[id] = zone
if (zone == g_next[id])
{
count_landing(id, zone)
return
}
if (!get_pcvar_num(g_cvarReset))
return
break_streak(id)
g_last[id] = zone
if (zone == 0)
count_landing(id, zone) // the wrong zone is the start: a new streak begins
}
count_landing(id, zone)
{
g_streak[id]++
g_next[id] = (zone + 1) % g_zoneCount
if (g_streak[id] > g_best[id])
g_best[id] = g_streak[id]
if (is_user_bot(id))
return
set_dhudmessage(80, 200, 255, -1.0, 0.22, 0, 0.0, 1.5, 0.05, 0.3)
show_dhudmessage(id, "%L", id, "LS_COUNT", g_streak[id], g_zoneName[g_next[id]])
client_cmd(id, "spk %s", COUNT_SOUND)
}
break_streak(id)
{
new had = g_streak[id]
reset_streak(id)
if (had > 0 && is_user_connected(id) && !is_user_bot(id))
{
set_dhudmessage(255, 90, 60, -1.0, 0.22, 0, 0.0, 1.5, 0.05, 0.3)
show_dhudmessage(id, "%L", id, "LS_RESET", had)
}
}
/* ---------- commands ---------- */
public cmd_streak(id)
{
if (!g_zoneCount)
client_print_color(id, print_team_default, "^4[Landing Streak]^1 %L", id, "LS_NO_ROUTE")
else
client_print_color(id, print_team_default, "^4[Landing Streak]^1 %L", id, "LS_BEST", g_best[id], g_streak[id], g_zoneName[g_next[id]])
return PLUGIN_HANDLED
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
new map[64]
get_mapname(map, charsmax(map))
console_print(id, "[Landing Streak] %s: %d zone(s), olds_landstreak_reset %d", map, g_zoneCount, get_pcvar_num(g_cvarReset))
for (new zone = 0; zone < g_zoneCount; zone++)
console_print(id, " %d. %s", zone + 1, g_zoneName[zone])
new name[32]
for (new player = 1; player <= MaxClients; player++)
{
if (!is_user_connected(player))
continue
get_user_name(player, name, charsmax(name))
console_print(id, " %s: streak %d, best %d, next zone %d", name, g_streak[player], g_best[player], g_zoneCount ? g_next[player] + 1 : 0)
}
return PLUGIN_HANDLED
}
public cmd_reload(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
load_zones()
console_print(id, "[Landing Streak] %d zone(s) loaded.", g_zoneCount)
return PLUGIN_HANDLED
}
/* ---------- natives ---------- */
// olds_landstreak_reset(id): break the player's streak (a checkpoint teleport, for example).
public native_reset(plugin, params)
{
new id = get_param(1)
if (!(1 <= id <= MaxClients) || !is_user_connected(id))
{
log_error(AMX_ERR_NATIVE, "[Landing Streak] Invalid player %d", id)
return 0
}
break_streak(id)
return 1
}
// olds_landstreak_get(id, &best = 0): the current streak; best is the best this map.
public native_get(plugin, params)
{
new id = get_param(1)
if (!(1 <= id <= MaxClients) || !is_user_connected(id))
{
log_error(AMX_ERR_NATIVE, "[Landing Streak] Invalid player %d", id)
return 0
}
set_param_byref(2, g_best[id])
return g_streak[id]
}