/*
* Staff Shift (olds.ro workshop card AMX-030)
*
* Moderation: admins opt in as "on duty" for this map with /duty; any player
* types /staff and gets one on-duty admin's name, the next one each time
* (round-robin), so requests spread across the staff.
*
* say /duty admins with the olds_staff_flag access: go on or off duty
* say /staff one on-duty admin's name, or "no staff on duty"
*
* Access: olds_staff_flag "c" (ADMIN_KICK by default), read when used. The
* flags are checked again every time a name is given, so an admin who lost
* the flag (for example after amx_reloadadmins) is taken off duty and never
* named. Duty lives only in memory, per player slot: it is cleared when the
* admin leaves and at every map change, and never written to disk.
*
* Command: olds_staff_status (ADMIN_KICK) lists who is on duty.
*
* Copyright (C) 2026 daemon (olds.ro)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Staff Shift"
#define VERSION "1.0.0"
#define AUTHOR "olds.ro"
new bool:g_onDuty[MAX_PLAYERS + 1]
new g_cursor[MAX_PLAYERS + 1] // each requester's place in the rotation
new Float:g_nextUse[MAX_PLAYERS + 1]
new g_flagText[27]
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_staff.txt")
bind_pcvar_string(create_cvar("olds_staff_flag", "c", FCVAR_NONE,
"Access flag(s) an admin needs for /duty (any of them); empty means c (ADMIN_KICK)."), g_flagText,
charsmax(g_flagText))
AutoExecConfig(true, "olds_staff")
register_clcmd("say /duty", "cmd_duty")
register_clcmd("say_team /duty", "cmd_duty")
register_clcmd("say /staff", "cmd_staff")
register_clcmd("say_team /staff", "cmd_staff")
register_concmd("olds_staff_status", "cmd_status", ADMIN_KICK, "- who is on duty")
}
/* ---------- access ---------- */
required_flags()
{
new flags = read_flags(g_flagText)
return flags ? flags : ADMIN_KICK
}
bool:has_access(id)
{
return is_user_connected(id) && !is_user_bot(id) && (get_user_flags(id) & required_flags()) != 0
}
/* On duty and still allowed to be; an admin who lost the flag is taken off. */
bool:available(id)
{
if (!g_onDuty[id])
return false
if (has_access(id))
return true
g_onDuty[id] = false
return false
}
/* ---------- /duty ---------- */
public cmd_duty(id)
{
if (!is_user_connected(id) || !cooled(id))
return PLUGIN_HANDLED
if (!has_access(id))
{
g_onDuty[id] = false
client_print_color(id, print_team_default, "^4[Staff]^1 %L", id, "STAFF_NO_ACCESS")
return PLUGIN_HANDLED
}
g_onDuty[id] = !g_onDuty[id]
client_print_color(id, print_team_default, "^4[Staff]^1 %L", id, g_onDuty[id] ? "STAFF_DUTY_ON" : "STAFF_DUTY_OFF",
on_duty_count())
new name[MAX_NAME_LENGTH]
get_user_name(id, name, charsmax(name))
log_amx("%s is %s duty", name, g_onDuty[id] ? "on" : "off")
return PLUGIN_HANDLED
}
/* ---------- /staff ---------- */
public cmd_staff(id)
{
if (!is_user_connected(id) || !cooled(id))
return PLUGIN_HANDLED
// Next on-duty admin after the one this player was given last time.
new start = g_cursor[id]
for (new step = 1; step <= MaxClients; step++)
{
new admin = (start + step - 1) % MaxClients + 1
if (!available(admin))
continue
g_cursor[id] = admin
new name[MAX_NAME_LENGTH]
get_user_name(admin, name, charsmax(name))
client_print_color(id, print_team_default, "^4[Staff]^1 %L", id, "STAFF_CONTACT", name, on_duty_count())
return PLUGIN_HANDLED
}
client_print_color(id, print_team_default, "^4[Staff]^1 %L", id, "STAFF_NONE")
return PLUGIN_HANDLED
}
on_duty_count()
{
new count
for (new p = 1; p <= MaxClients; p++)
if (available(p))
count++
return count
}
/* ---------- helpers ---------- */
bool:cooled(id)
{
new Float:now = get_gametime()
if (now < g_nextUse[id])
return false
g_nextUse[id] = now + 1.0
return true
}
public client_disconnected(id)
{
g_onDuty[id] = false
g_cursor[id] = 0
g_nextUse[id] = 0.0
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
new name[MAX_NAME_LENGTH], count
console_print(id, "[Staff] duty flag(s) ^"%s^"", g_flagText)
for (new p = 1; p <= MaxClients; p++)
{
if (!available(p))
continue
get_user_name(p, name, charsmax(name))
console_print(id, "[Staff] %s", name)
count++
}
console_print(id, "[Staff] %d on duty", count)
return PLUGIN_HANDLED
}