/*
* Freeday Manager (olds.ro workshop card LIB-0875)
* Copyright (C) 2026 daemon (olds.ro)
*
* 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/>.
*
* Jailbreak: the warden (say /freeday, a menu of living prisoners) or an admin
* (amx_freeday <name>, ADMIN_LEVEL_A) gives a prisoner a freeday. The prisoner glows in
* olds_fday_color and guards cannot hurt them until the day (round) ends. A freeday prisoner
* who attacks a guard loses the freeday. At most olds_fday_max freedays a day.
* The warden comes from the "[JB] Core" (library "jailbreak", jb_get_simon_id()); prisoners
* are the terrorists, guards the counter-terrorists.
*/
#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <reapi>
#define PLUGIN "Freeday Manager"
#define VERSION "1.0.0"
#define AUTHOR "daemon (olds.ro)"
#pragma reqlib "jailbreak"
native jb_get_simon_id()
new g_max
new g_colorText[16]
new bool:g_free[MAX_PLAYERS + 1]
new g_given
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_freeday.txt")
bind_pcvar_num(create_cvar("olds_fday_max", "3", FCVAR_NONE, "Freedays that can be given each day", true, 0.0, true, 32.0), g_max)
bind_pcvar_string(create_cvar("olds_fday_color", "0 255 0", FCVAR_NONE, "Glow colour of a freeday prisoner: r g b"), g_colorText, charsmax(g_colorText))
AutoExecConfig(true, "olds_freeday")
register_clcmd("say /freeday", "cmd_menu")
register_clcmd("say_team /freeday", "cmd_menu")
register_concmd("amx_freeday", "cmd_admin", ADMIN_LEVEL_A, "<name> - gives that prisoner a freeday")
register_concmd("amx_freeday_status", "cmd_status", ADMIN_LEVEL_A, "- lists today's freedays")
RegisterHookChain(RG_CBasePlayer_TakeDamage, "on_take_damage_pre", false)
RegisterHookChain(RG_CBasePlayer_Killed, "on_killed_post", true)
RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_pre", false)
}
public client_disconnected(id)
{
g_free[id] = false
}
/* ------------------------------------------------------------------ the day */
public on_restart_pre()
{
for (new id = 1; id <= MaxClients; id++)
{
if (g_free[id] && is_user_connected(id))
set_user_rendering(id)
g_free[id] = false
}
g_given = 0
}
public on_killed_post(victim, killer, gib)
{
if (g_free[victim])
{
g_free[victim] = false
set_user_rendering(victim)
}
}
bool:is_prisoner(id)
{
return is_user_alive(id) && TeamName:get_member(id, m_iTeam) == TEAM_TERRORIST
}
bool:is_guard(id)
{
return is_user_connected(id) && TeamName:get_member(id, m_iTeam) == TEAM_CT
}
public on_take_damage_pre(victim, inflictor, attacker, Float:damage, bits)
{
if (attacker < 1 || attacker > MaxClients || attacker == victim)
return HC_CONTINUE
/* A freeday prisoner who attacks a guard gives the freeday up; the hit goes through. */
if (g_free[attacker] && is_guard(victim))
{
end_freeday(attacker, "FDAY_LOST")
return HC_CONTINUE
}
/* Guards cannot hurt a freeday prisoner. */
if (g_free[victim] && is_guard(attacker))
{
SetHookChainReturn(ATYPE_INTEGER, 0)
return HC_SUPERCEDE
}
return HC_CONTINUE
}
/* ------------------------------------------------------------------ giving */
glow(id)
{
new r[4], g[4], b[4]
parse(g_colorText, r, charsmax(r), g, charsmax(g), b, charsmax(b))
set_user_rendering(id, kRenderFxGlowShell, clamp(str_to_num(r), 0, 255), clamp(str_to_num(g), 0, 255),
clamp(str_to_num(b), 0, 255), kRenderNormal, 16)
}
/* 1 = given; otherwise the reason is told to `by` (0 = the server console). */
give_freeday(by, target)
{
if (!is_prisoner(target))
{
tell(by, "FDAY_NOT_PRISONER")
return 0
}
if (g_free[target])
{
tell(by, "FDAY_ALREADY")
return 0
}
if (g_given >= g_max)
{
tell_num(by, "FDAY_LIMIT", g_max)
return 0
}
g_free[target] = true
g_given++
glow(target)
client_cmd(0, "spk buttons/bell1")
new name[MAX_NAME_LENGTH], giver[MAX_NAME_LENGTH]
get_user_name(target, name, charsmax(name))
if (by)
get_user_name(by, giver, charsmax(giver))
else
copy(giver, charsmax(giver), "The server")
client_print(0, print_chat, "%L", LANG_PLAYER, "FDAY_GIVEN", giver, name, g_given, g_max)
log_amx("%s gave %s a freeday (%d of %d)", giver, name, g_given, g_max)
return 1
}
end_freeday(id, const why[])
{
g_free[id] = false
set_user_rendering(id)
new name[MAX_NAME_LENGTH]
get_user_name(id, name, charsmax(name))
client_print(0, print_chat, "%L", LANG_PLAYER, why, name)
log_amx("%s lost the freeday", name)
}
tell(id, const key[])
{
if (id)
client_print(id, print_chat, "%L", id, key)
else
server_print("%L", LANG_SERVER, key)
}
tell_num(id, const key[], num)
{
if (id)
client_print(id, print_chat, "%L", id, key, num)
else
server_print("%L", LANG_SERVER, key, num)
}
/* ------------------------------------------------------------------ the warden's menu */
public cmd_menu(id)
{
if (jb_get_simon_id() != id || !is_guard(id))
{
tell(id, "FDAY_NOT_WARDEN")
return PLUGIN_HANDLED
}
if (g_given >= g_max)
{
tell_num(id, "FDAY_LIMIT", g_max)
return PLUGIN_HANDLED
}
new title[64]
formatex(title, charsmax(title), "%L", id, "FDAY_MENU", g_max - g_given)
new menu = menu_create(title, "on_menu")
new name[MAX_NAME_LENGTH], info[8], items
for (new p = 1; p <= MaxClients; p++)
{
if (!is_prisoner(p) || g_free[p])
continue
get_user_name(p, name, charsmax(name))
num_to_str(get_user_userid(p), info, charsmax(info))
menu_additem(menu, name, info)
items++
}
if (!items)
{
menu_destroy(menu)
tell(id, "FDAY_NOBODY")
return PLUGIN_HANDLED
}
menu_display(id, menu)
return PLUGIN_HANDLED
}
public on_menu(id, menu, item)
{
if (item < 0)
{
menu_destroy(menu)
return PLUGIN_HANDLED
}
new info[8], access, callback
menu_item_getinfo(menu, item, access, info, charsmax(info), _, _, callback)
menu_destroy(menu)
/* Still the warden when choosing? */
if (jb_get_simon_id() != id || !is_guard(id))
{
tell(id, "FDAY_NOT_WARDEN")
return PLUGIN_HANDLED
}
new target = find_player_ex(FindPlayer_MatchUserId, str_to_num(info))
if (!target)
{
tell(id, "FDAY_NOT_PRISONER")
return PLUGIN_HANDLED
}
give_freeday(id, target)
return PLUGIN_HANDLED
}
/* ------------------------------------------------------------------ admin */
public cmd_admin(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
new arg[32]
read_argv(1, arg, charsmax(arg))
new target = cmd_target(id, arg, CMDTARGET_ALLOW_SELF)
if (!target)
return PLUGIN_HANDLED
give_freeday(id, target)
return PLUGIN_HANDLED
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
console_print(id, "[Freeday] %d of %d given today, warden #%d", g_given, g_max, jb_get_simon_id())
new name[MAX_NAME_LENGTH]
for (new p = 1; p <= MaxClients; p++)
{
if (!is_user_connected(p))
continue
get_user_name(p, name, charsmax(name))
console_print(id, "[Freeday] #%d %s team %d alive %d health %d freeday %d glow %d", p, name,
get_member(p, m_iTeam), is_user_alive(p), get_user_health(p), g_free[p], get_entvar(p, var_renderfx) == kRenderFxGlowShell)
}
return PLUGIN_HANDLED
}