/*
* Surface Notebook (olds.ro workshop card AMX-080)
*
* A mapper walking a map aims at a wall, floor or ceiling and types
* amx_pin <remark>. The plugin traces from the player's eyes, reads the
* texture there and keeps the texture name, the exact position and the
* remark. amx_pins lists every pin of the map in the console, so a mapper
* can note "misaligned", "z-fighting" or "wrong texture" while walking and
* read the list back later. Pins live until the map changes.
*
* Console commands (admins with the ADMIN_RCON flag):
* amx_pin <remark> Pins the surface you aim at, with an optional remark.
* The sky and a trace that hits nothing are refused, and
* a spot within olds_pins_dedupe units of an existing pin
* is not added again.
* amx_pins Lists the pins of this map (also from the server
* console).
*
* Cvars (in configs/plugins/olds_pins.cfg, written with the defaults on the
* first start if the file is missing):
* olds_pins_dedupe 16 Two pins closer than this many units are the same
* spot (0 - 1024; 0 = only the exact same point).
*
* At most 12 pins are kept per map. Texts are in data/lang/olds_pins.txt.
*
* How it works, as the card asks: EngFunc_TraceLine from the eyes along the
* view, then engfunc(EngFunc_TraceTexture, ...) on the surface that was hit.
*
* Requires AMX Mod X 1.10 with the fakemeta module (ships with AMX Mod X).
* No ReAPI. Written and tested on AMX Mod X 1.10.0.5490, ReHLDS 3.15.0.896
* 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 <fakemeta>
#pragma semicolon 1
new const PLUGIN_NAME[] = "Surface Notebook";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";
// Pins kept per map.
const MAX_PINS = 12;
const REMARK_LENGTH = 64;
const TEXTURE_LENGTH = 32;
// How far the eye trace reaches, more than any map is wide.
const Float:TRACE_DISTANCE = 8192.0;
// The texture is read on a line that goes this far past the hit point, so
// it crosses the surface.
const Float:PAST_SURFACE = 8.0;
new Float:g_dedupe; // olds_pins_dedupe
new g_pinCount;
new Float:g_pinOrigin[MAX_PINS][3];
new g_pinTexture[MAX_PINS][TEXTURE_LENGTH];
new g_pinRemark[MAX_PINS][REMARK_LENGTH];
new g_pinAuthor[MAX_PINS][MAX_NAME_LENGTH];
new g_mapName[32];
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
register_dictionary("olds_pins.txt");
bind_pcvar_float(create_cvar("olds_pins_dedupe", "16", FCVAR_NONE,
"Two pins closer than this many units are the same spot",
true, 0.0, true, 1024.0), g_dedupe);
AutoExecConfig(true, "olds_pins");
register_concmd("amx_pin", "cmd_pin", ADMIN_RCON, "<remark> - pin the surface you aim at");
register_concmd("amx_pins", "cmd_pins", ADMIN_RCON, "- list the pins of this map");
get_mapname(g_mapName, charsmax(g_mapName));
}
public cmd_pin(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED;
// The server console has no eyes to trace from.
if (!id)
{
console_print(id, "%L", LANG_SERVER, "PINS_NEED_PLAYER");
return PLUGIN_HANDLED;
}
if (g_pinCount >= MAX_PINS)
{
console_print(id, "%L", id, "PINS_FULL", MAX_PINS);
return PLUGIN_HANDLED;
}
new Float:hit[3], texture[TEXTURE_LENGTH];
if (!trace_surface(id, hit, texture, charsmax(texture)))
{
console_print(id, "%L", id, "PINS_NO_SURFACE");
return PLUGIN_HANDLED;
}
for (new pin = 0; pin < g_pinCount; pin++)
{
if (get_distance_f(hit, g_pinOrigin[pin]) <= g_dedupe)
{
console_print(id, "%L", id, "PINS_DUPLICATE", pin + 1, floatround(g_dedupe));
return PLUGIN_HANDLED;
}
}
new remark[REMARK_LENGTH];
read_args(remark, charsmax(remark));
remove_quotes(remark);
trim(remark);
if (!remark[0])
formatex(remark, charsmax(remark), "%L", id, "PINS_NO_REMARK");
new pin = g_pinCount++;
g_pinOrigin[pin] = hit;
copy(g_pinTexture[pin], charsmax(g_pinTexture[]), texture);
copy(g_pinRemark[pin], charsmax(g_pinRemark[]), remark);
get_user_name(id, g_pinAuthor[pin], charsmax(g_pinAuthor[]));
console_print(id, "%L", id, "PINS_ADDED", pin + 1, texture,
floatround(hit[0]), floatround(hit[1]), floatround(hit[2]), remark);
return PLUGIN_HANDLED;
}
public cmd_pins(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED;
if (!g_pinCount)
{
console_print(id, "%L", id, "PINS_LIST_EMPTY", g_mapName);
return PLUGIN_HANDLED;
}
console_print(id, "%L", id, "PINS_LIST_HEAD", g_mapName, g_pinCount, MAX_PINS);
for (new pin = 0; pin < g_pinCount; pin++)
{
// Whole units: AMX Mod X's %.0f can print one less than the value.
console_print(id, "%L", id, "PINS_LIST_LINE", pin + 1, g_pinTexture[pin],
floatround(g_pinOrigin[pin][0]), floatround(g_pinOrigin[pin][1]), floatround(g_pinOrigin[pin][2]),
g_pinRemark[pin], g_pinAuthor[pin]);
}
return PLUGIN_HANDLED;
}
/**
* Traces from the player's eyes along the view. Returns false for the sky
* and for a trace that hits nothing; otherwise fills in the hit point and the
* texture name there.
*/
bool:trace_surface(id, Float:hit[3], texture[], length)
{
new Float:eye[3], Float:viewOffset[3], Float:angles[3], Float:direction[3], Float:end[3];
pev(id, pev_origin, eye);
pev(id, pev_view_ofs, viewOffset);
pev(id, pev_v_angle, angles);
for (new axis = 0; axis < 3; axis++)
eye[axis] += viewOffset[axis];
angle_vector(angles, ANGLEVECTOR_FORWARD, direction);
for (new axis = 0; axis < 3; axis++)
end[axis] = eye[axis] + direction[axis] * TRACE_DISTANCE;
new trace = create_tr2();
engfunc(EngFunc_TraceLine, eye, end, IGNORE_MONSTERS, id, trace);
new Float:fraction;
get_tr2(trace, TR_flFraction, fraction);
get_tr2(trace, TR_vecEndPos, hit);
new hitEntity = get_tr2(trace, TR_pHit);
free_tr2(trace);
// Nothing in the way for the whole distance.
if (fraction >= 1.0)
return false;
new Float:past[3];
for (new axis = 0; axis < 3; axis++)
past[axis] = hit[axis] + direction[axis] * PAST_SURFACE;
// The world is entity 0; a brush entity (door, platform) has its own.
engfunc(EngFunc_TraceTexture, max(hitEntity, 0), eye, past, texture, length);
if (equali(texture, "sky") || engfunc(EngFunc_PointContents, past) == CONTENTS_SKY)
return false;
if (!texture[0])
formatex(texture, length, "%L", id, "PINS_NO_TEXTURE");
return true;
}