/*
* Build Palette (olds.ro) - ReBaseBuilder add-on. During the build phase a
* builder marks a block as an entrance, a step or cover: the block takes that
* label's colour, and teammates who aim at it read the word in a DHUD line,
* so the label never depends on colour alone. When the build phase ends every
* marked block gets back the render it had before it was marked.
*
* 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 <fakemeta>
#include <reapi>
#pragma reqlib "rebb_api"
native rebb_is_building_phase()
native rebb_get_barrier_ent_index()
native rebb_get_owned_ent(id)
#define PLUGIN "Build Palette"
#define VERSION "1.0.0"
#define AUTHOR "daemon (olds.ro)"
#define MAX_MARKS 128
#define TASK_AIM 7500
#define AIM_PERIOD 0.3
#define AIM_RANGE 1024.0
enum
{
KIND_ENTRANCE,
KIND_STEP,
KIND_COVER,
KINDS
}
new const KIND_WORD[KINDS][] = { "entrance", "step", "cover" }
new const KIND_CVAR[KINDS][] = { "olds_palette_entrance", "olds_palette_step", "olds_palette_cover" }
new const KIND_DEFAULT[KINDS][] = { "90 220 110", "245 200 60", "100 160 255" }
new const OFF_WHITE[3] = { 235, 230, 215 } // used when a colour cvar is not "r g b"
new g_block[MAX_MARKS] // 0 = free slot
new g_kind[MAX_MARKS]
new g_author[MAX_MARKS]
new g_oldMode[MAX_MARKS] // render before the mark, put back at the end of the phase
new g_oldFx[MAX_MARKS]
new Float:g_oldColor[MAX_MARKS][3]
new Float:g_oldAmount[MAX_MARKS]
new Float:g_tint[MAX_MARKS][3] // what we set, to see whether someone changed it since
new Float:g_tintAmount[MAX_MARKS]
new g_lastSeen[MAX_PLAYERS + 1] // mark slot shown to each player, -1 = none
new Float:g_lastShown[MAX_PLAYERS + 1]
new g_cvarAlpha
new g_cvarColor[KINDS]
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
g_cvarAlpha = create_cvar("olds_palette_alpha", "120", FCVAR_NONE, "Render amount of a marked block (0-255)", true, 0.0, true, 255.0)
for (new k = 0; k < KINDS; k++)
g_cvarColor[k] = create_cvar(KIND_CVAR[k], KIND_DEFAULT[k], FCVAR_NONE, "Colour as ^"red green blue^"; anything else gives off-white")
AutoExecConfig(true, "olds_palette")
register_clcmd("say", "cmd_say")
register_clcmd("say_team", "cmd_say")
register_concmd("olds_palette_status", "cmd_status", ADMIN_CFG, "- marked blocks")
RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_pre", false)
set_task(AIM_PERIOD, "task_aim", TASK_AIM, _, _, "b")
}
/* ---------- blocks ---------- */
bool:is_digits(const text[])
{
if (!text[0])
return false
for (new i = 0; text[i]; i++)
{
if (!('0' <= text[i] <= '9'))
return false
}
return true
}
Float:pev_float(entity, field)
{
new Float:value
pev(entity, field, value)
return value
}
bool:valid_player(id)
{
return 1 <= id <= MaxClients && is_user_connected(id)
}
bool:is_block(entity)
{
if (entity <= MaxClients || !pev_valid(entity) || entity == rebb_get_barrier_ent_index())
return false
new classname[16], target[16]
pev(entity, pev_classname, classname, charsmax(classname))
if (!equal(classname, "func_wall"))
return false
pev(entity, pev_target, target, charsmax(target))
return !equal(target, "ignore")
}
// The builder holding the block now, else the owner ReBaseBuilder stored on it.
block_owner(entity)
{
for (new id = 1; id <= MaxClients; id++)
{
if (is_user_connected(id) && rebb_get_owned_ent(id) == entity)
return id
}
new owner = pev(entity, pev_iuser1)
if (!valid_player(owner))
owner = pev(entity, pev_iuser3)
if (!valid_player(owner))
owner = pev(entity, pev_iuser4)
return valid_player(owner) ? owner : 0
}
mark_of(entity)
{
for (new n = 0; n < MAX_MARKS; n++)
{
if (g_block[n] == entity)
return n
}
return -1
}
aimed_block(id)
{
new Float:start[3], Float:offset[3], Float:angles[3], Float:dir[3], Float:stop[3]
pev(id, pev_origin, start)
pev(id, pev_view_ofs, offset)
pev(id, pev_v_angle, angles)
for (new axis = 0; axis < 3; axis++)
start[axis] += offset[axis]
angle_vector(angles, ANGLEVECTOR_FORWARD, dir)
for (new axis = 0; axis < 3; axis++)
stop[axis] = start[axis] + dir[axis] * AIM_RANGE
new trace = create_tr2()
engfunc(EngFunc_TraceLine, start, stop, DONT_IGNORE_MONSTERS, id, trace)
new hit = get_tr2(trace, TR_pHit)
free_tr2(trace)
return is_block(hit) ? hit : 0
}
kind_color(kind, Float:color[3])
{
new text[24], part[3][6]
get_pcvar_string(g_cvarColor[kind], text, charsmax(text))
if (parse(text, part[0], charsmax(part[]), part[1], charsmax(part[]), part[2], charsmax(part[])) == 3
&& is_digits(part[0]) && is_digits(part[1]) && is_digits(part[2]))
{
for (new i = 0; i < 3; i++)
color[i] = float(clamp(str_to_num(part[i]), 0, 255))
return
}
for (new i = 0; i < 3; i++)
color[i] = float(OFF_WHITE[i])
}
apply_tint(n)
{
new entity = g_block[n]
set_pev(entity, pev_rendermode, kRenderTransColor)
set_pev(entity, pev_renderfx, kRenderFxNone)
set_pev(entity, pev_rendercolor, g_tint[n])
set_pev(entity, pev_renderamt, g_tintAmount[n])
}
bool:still_ours(n)
{
new entity = g_block[n], Float:color[3], Float:amount
if (pev(entity, pev_rendermode) != kRenderTransColor)
return false
pev(entity, pev_rendercolor, color)
pev(entity, pev_renderamt, amount)
return color[0] == g_tint[n][0] && color[1] == g_tint[n][1] && color[2] == g_tint[n][2] && amount == g_tintAmount[n]
}
// Put back the render the block had before it was marked, unless someone changed it since.
restore(n)
{
new entity = g_block[n]
if (pev_valid(entity) && still_ours(n))
{
set_pev(entity, pev_rendermode, g_oldMode[n])
set_pev(entity, pev_renderfx, g_oldFx[n])
set_pev(entity, pev_rendercolor, g_oldColor[n])
set_pev(entity, pev_renderamt, g_oldAmount[n])
}
g_block[n] = 0
}
restore_all()
{
new count
for (new n = 0; n < MAX_MARKS; n++)
{
if (g_block[n])
{
restore(n)
count++
}
}
return count
}
/* ---------- phase changes (ReBaseBuilder forwards) ---------- */
public rebb_preparation_start(prepTime)
{
end_phase()
}
public rebb_zombies_released()
{
end_phase()
}
end_phase()
{
new count = restore_all()
if (count)
server_print("[Palette] Build phase over: %d marked block(s) restored.", count)
}
public rebb_build_start(buildTime)
{
restore_all()
}
// The core and colour plugins change the render while a block is carried: tint it again after the drop.
public rebb_drop_post(id, entity)
{
new n = mark_of(entity)
if (n >= 0 && rebb_is_building_phase())
apply_tint(n)
}
public on_restart_round_pre()
{
// The core resets its blocks on a new round; forget the marks without touching them.
for (new n = 0; n < MAX_MARKS; n++)
g_block[n] = 0
return HC_CONTINUE
}
public client_disconnected(id)
{
g_lastSeen[id] = -1
}
/* ---------- marking ---------- */
public cmd_say(id)
{
new text[64]
read_args(text, charsmax(text))
remove_quotes(text)
trim(text)
if (!equali(text, "/mark", 5) || (text[5] && text[5] != ' '))
return PLUGIN_CONTINUE
new word[16]
copy(word, charsmax(word), text[5])
trim(word)
if (!word[0])
{
client_print(id, print_chat, "[Palette] Aim at your block and type /mark entrance, /mark step, /mark cover or /mark clear.")
return PLUGIN_HANDLED
}
if (!rebb_is_building_phase())
{
client_print(id, print_chat, "[Palette] Blocks can be marked only during the build phase.")
return PLUGIN_HANDLED
}
if (!is_user_alive(id) || TeamName:get_member(id, m_iTeam) != TEAM_CT)
{
client_print(id, print_chat, "[Palette] Only living builders can mark blocks.")
return PLUGIN_HANDLED
}
new kind = -1
for (new k = 0; k < KINDS; k++)
{
if (equali(word, KIND_WORD[k]))
kind = k
}
new bool:clear = bool:equali(word, "clear")
if (kind < 0 && !clear)
{
client_print(id, print_chat, "[Palette] Unknown label ^"%s^": use entrance, step, cover or clear.", word)
return PLUGIN_HANDLED
}
new entity = aimed_block(id)
if (!entity)
{
client_print(id, print_chat, "[Palette] Aim at a block first.")
return PLUGIN_HANDLED
}
new owner = block_owner(entity), n = mark_of(entity)
if (owner && owner != id)
{
client_print(id, print_chat, "[Palette] That block belongs to another builder.")
return PLUGIN_HANDLED
}
if (n >= 0 && g_author[n] != id && valid_player(g_author[n]) && owner != id)
{
client_print(id, print_chat, "[Palette] Another builder marked that block.")
return PLUGIN_HANDLED
}
if (clear)
{
if (n < 0)
client_print(id, print_chat, "[Palette] That block has no mark.")
else
{
restore(n)
client_print(id, print_chat, "[Palette] Mark removed.")
}
return PLUGIN_HANDLED
}
if (n < 0)
{
for (new i = 0; i < MAX_MARKS; i++)
{
if (!g_block[i])
{
n = i
break
}
}
if (n < 0)
{
client_print(id, print_chat, "[Palette] Too many marked blocks (%d).", MAX_MARKS)
return PLUGIN_HANDLED
}
// Remember the render someone else may have set, so the end of the phase gives it back.
g_block[n] = entity
g_oldMode[n] = pev(entity, pev_rendermode)
g_oldFx[n] = pev(entity, pev_renderfx)
pev(entity, pev_rendercolor, g_oldColor[n])
pev(entity, pev_renderamt, g_oldAmount[n])
}
g_kind[n] = kind
g_author[n] = id
kind_color(kind, g_tint[n])
g_tintAmount[n] = get_pcvar_float(g_cvarAlpha)
apply_tint(n)
client_print(id, print_chat, "[Palette] Block marked: %s.", KIND_WORD[kind])
return PLUGIN_HANDLED
}
/* ---------- reading labels ---------- */
public task_aim()
{
new players[MAX_PLAYERS], count, Float:now = get_gametime()
get_players(players, count, "ach")
for (new i = 0; i < count; i++)
{
new id = players[i]
new entity = aimed_block(id), n = entity ? mark_of(entity) : -1
if (n < 0)
{
g_lastSeen[id] = -1
continue
}
// Same team as the builder who marked it (the label is for teammates).
if (valid_player(g_author[n]) && TeamName:get_member(g_author[n], m_iTeam) != TeamName:get_member(id, m_iTeam))
continue
if (n == g_lastSeen[id] && now - g_lastShown[id] < 1.0)
continue
g_lastSeen[id] = n
g_lastShown[id] = now
set_dhudmessage(floatround(g_tint[n][0]), floatround(g_tint[n][1]), floatround(g_tint[n][2]), -1.0, 0.56, 0, 0.0, 1.1, 0.0, 0.1)
show_dhudmessage(id, "%s", KIND_WORD[g_kind[n]])
}
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
new marks, name[32], Float:color[3]
console_print(id, "[Palette] building phase %d, alpha %d", rebb_is_building_phase(), get_pcvar_num(g_cvarAlpha))
for (new n = 0; n < MAX_MARKS; n++)
{
new entity = g_block[n]
if (!entity)
continue
marks++
if (valid_player(g_author[n]))
get_user_name(g_author[n], name, charsmax(name))
else
copy(name, charsmax(name), "(gone)")
pev(entity, pev_rendercolor, color)
console_print(id, " block #%d: %s by %s; render mode %d colour %.0f %.0f %.0f amount %.0f", entity, KIND_WORD[g_kind[n]], name,
pev(entity, pev_rendermode), color[0], color[1], color[2], pev_float(entity, pev_renderamt))
}
console_print(id, " %d marked block(s)", marks)
return PLUGIN_HANDLED
}