Skip to content
View in the app

A better way to browse. Learn more.

Learn more

assassination-day/addons/amxmodx/scripting/olds_assassin.sma

olds_assassin.sma
387 lines · 11.9 KB · Pawn (AMX Mod X)
Raw
/*
 * Assassination Day (olds.ro)
 * 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: <https://www.gnu.org/licenses/>.
 *
 * Jailbreak special game: one living player (a prisoner or a guard, picked at random) is the
 * VIP. The guards protect the VIP; the prisoners must kill the VIP within olds_assn_time
 * seconds. The VIP gets olds_assn_vip_hp health and a gold glow (set_user_rendering). Only
 * prisoners can hurt the VIP (a prisoner VIP can be hurt by the other prisoners, and guards
 * cannot hurt the VIP). The VIP's death (RG_CBasePlayer_Killed) wins the round for the
 * prisoners and pays the killer olds_assn_reward; the time running out wins it for the
 * guards; RG_RoundEnd closes the game whatever ends the round.
 *
 * Started by an admin (amx_assassin, ADMIN_LEVEL_A) or by the warden (say /assassin). Team
 * roles come from the "[JB] Core" (library "jailbreak"; jb_get_simon_id() names the warden):
 * prisoners are the terrorists, guards the counter-terrorists.
 *
 * Cvars: olds_assn_time 180, olds_assn_vip_hp 250, olds_assn_reward 1500,
 *        olds_assn_pick 0 (0 anyone, 1 a prisoner, 2 a guard), olds_assn_newvip 1
 * Admin: amx_assassin [stop|status] (ADMIN_LEVEL_A)
 */

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>
#include <reapi>

#pragma semicolon 0

#define PLUGIN  "Assassination Day"
#define VERSION "1.0.0"
#define AUTHOR  "daemon (olds.ro)"

#define TASK_TIMER 8740
#define MIN_PLAYERS 3

/* "[JB] Core" API, declared here so the plugin compiles without its include. */
#pragma reqlib "jailbreak"
native jb_get_simon_id()

new const ALARM_SOUND[] = "ambience/alarm1.wav"

new g_time
new g_vipHp
new g_reward
new g_pick
new g_newVip

new bool:g_on
new g_vip
new g_left
new g_games
new g_hudSync

public plugin_precache()
{
    precache_sound(ALARM_SOUND)
}

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_dictionary("olds_assassin.txt")

    bind_pcvar_num(create_cvar("olds_assn_time", "180", FCVAR_NONE,
        "Seconds the guards must keep the VIP alive", true, 10.0, true, 900.0), g_time)
    bind_pcvar_num(create_cvar("olds_assn_vip_hp", "250", FCVAR_NONE,
        "Health of the VIP", true, 1.0, true, 1000.0), g_vipHp)
    bind_pcvar_num(create_cvar("olds_assn_reward", "1500", FCVAR_NONE,
        "Money for the prisoner who kills the VIP", true, 0.0, true, 16000.0), g_reward)
    bind_pcvar_num(create_cvar("olds_assn_pick", "0", FCVAR_NONE,
        "Who can be the VIP: 0 anyone, 1 a prisoner, 2 a guard", true, 0.0, true, 2.0), g_pick)
    bind_pcvar_num(create_cvar("olds_assn_newvip", "1", FCVAR_NONE,
        "If the VIP leaves: 1 = pick a new VIP, 0 = end the game as a draw", true, 0.0, true, 1.0), g_newVip)
    AutoExecConfig(true, "olds_assassin")

    register_concmd("amx_assassin", "cmd_assassin", ADMIN_LEVEL_A, "[stop|status] - starts Assassination Day")
    register_clcmd("say /assassin", "cmd_warden")
    register_clcmd("say_team /assassin", "cmd_warden")

    RegisterHookChain(RG_CBasePlayer_Killed, "on_killed_post", true)
    RegisterHookChain(RG_CSGameRules_FPlayerCanTakeDamage, "on_can_damage", false)
    RegisterHookChain(RG_RoundEnd, "on_round_end_post", true)
    RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_pre", false)

    g_hudSync = CreateHudSyncObj()
}

/* ------------------------------------------------------------ roles */

bool:is_prisoner(id)
{
    return is_user_alive(id) && cs_get_user_team(id) == CS_TEAM_T
}

bool:is_guard(id)
{
    return is_user_alive(id) && cs_get_user_team(id) == CS_TEAM_CT
}

bool:can_be_vip(id)
{
    if (!is_user_alive(id))
        return false
    if (g_pick == 1)
        return is_prisoner(id)
    if (g_pick == 2)
        return is_guard(id)
    return is_prisoner(id) || is_guard(id)
}

count_alive(&prisoners, &guards)
{
    prisoners = 0
    guards = 0
    for (new i = 1; i <= MaxClients; i++)
    {
        if (is_prisoner(i))
            prisoners++
        else if (is_guard(i))
            guards++
    }
    return prisoners + guards
}

/* A VIP who still leaves at least one prisoner to hunt and one guard to protect. */
pick_vip(except)
{
    new prisoners, guards
    count_alive(prisoners, guards)
    new pool[MAX_PLAYERS], count
    for (new i = 1; i <= MaxClients; i++)
    {
        if (i == except || !can_be_vip(i))
            continue
        if (is_prisoner(i) && (prisoners < 2 || guards < 1))
            continue
        if (is_guard(i) && prisoners < 1)
            continue
        pool[count++] = i
    }
    return count ? pool[random(count)] : 0
}

/* ------------------------------------------------------------ starting and ending */

start_game(starter)
{
    if (g_on)
    {
        reply(starter, "ASSN_ALREADY")
        return
    }
    new prisoners, guards
    if (count_alive(prisoners, guards) < MIN_PLAYERS || !prisoners || !guards)
    {
        reply(starter, "ASSN_FEW")
        log_amx("Assassination Day refused: %d prisoners and %d guards alive (need %d players, both teams)", prisoners, guards, MIN_PLAYERS)
        return
    }
    new vip = pick_vip(0)
    if (!vip)
    {
        reply(starter, "ASSN_NO_VIP")
        return
    }
    g_on = true
    g_games++
    g_left = clamp(g_time, 10, 900)
    make_vip(vip)
    for (new i = 1; i <= MaxClients; i++)
    {
        if (is_user_connected(i) && !is_user_bot(i))
            client_cmd(i, "spk ^"%s^"", ALARM_SOUND)
    }
    remove_task(TASK_TIMER)
    set_task(1.0, "task_timer", TASK_TIMER, _, _, "b")
    new name[MAX_NAME_LENGTH], who[MAX_NAME_LENGTH]
    get_user_name(vip, name, charsmax(name))
    if (starter)
        get_user_name(starter, who, charsmax(who))
    else
        copy(who, charsmax(who), "server")
    new side[12]
    if (is_prisoner(vip))
        copy(side, charsmax(side), "prisoner")
    else
        copy(side, charsmax(side), "guard")
    log_amx("Assassination Day started by %s: VIP %s (%s), %d HP, %d seconds", who, name, side, g_vipHp, g_left)
}

make_vip(id)
{
    g_vip = id
    set_user_health(id, clamp(g_vipHp, 1, 1000))
    set_user_rendering(id, kRenderFxGlowShell, 255, 200, 0, kRenderNormal, 25)
    new name[MAX_NAME_LENGTH]
    get_user_name(id, name, charsmax(name))
    for (new i = 1; i <= MaxClients; i++)
    {
        if (!is_user_connected(i))
            continue
        if (i == id)
            client_print_color(i, print_team_default, "%L", i, "ASSN_YOU", g_vipHp)
        else if (cs_get_user_team(i) == CS_TEAM_CT)
            client_print_color(i, print_team_blue, "%L", i, "ASSN_PROTECT", name)
        else
            client_print_color(i, print_team_red, "%L", i, "ASSN_KILL", name)
    }
}

clear_vip()
{
    if (g_vip && is_user_connected(g_vip))
        set_user_rendering(g_vip, kRenderFxNone, 0, 0, 0, kRenderNormal, 0)
    g_vip = 0
}

stop_game()
{
    g_on = false
    remove_task(TASK_TIMER)
    clear_vip()
}

public task_timer()
{
    if (!g_on)
        return
    if (--g_left <= 0)
    {
        log_amx("Assassination Day: time is up, the VIP lives: the guards win")
        tell_all("ASSN_SAFE")
        stop_game()
        rg_round_end(5.0, WINSTATUS_CTS, ROUND_CTS_WIN, "The VIP survived Assassination Day!")
        return
    }
    if (!g_vip)
        return
    new name[MAX_NAME_LENGTH]
    get_user_name(g_vip, name, charsmax(name))
    set_hudmessage(255, 200, 0, -1.0, 0.12, 0, 0.0, 1.1, 0.0, 0.0, -1)
    for (new i = 1; i <= MaxClients; i++)
    {
        if (is_user_connected(i) && !is_user_bot(i))
            ShowSyncHudMsg(i, g_hudSync, "%L", i, "ASSN_HUD", name, g_left / 60, g_left % 60)
    }
}

public on_killed_post(victim, killer, gib)
{
    if (!g_on || victim != g_vip)
        return HC_CONTINUE
    new name[MAX_NAME_LENGTH], kname[MAX_NAME_LENGTH]
    get_user_name(victim, name, charsmax(name))
    if (killer >= 1 && killer <= MaxClients && killer != victim && is_user_connected(killer) && cs_get_user_team(killer) == CS_TEAM_T)
    {
        get_user_name(killer, kname, charsmax(kname))
        rg_add_account(killer, clamp(g_reward, 0, 16000), AS_ADD)
        client_print_color(killer, print_team_red, "%L", killer, "ASSN_PAID", g_reward)
        log_amx("Assassination Day: %s killed the VIP %s and earned $%d: the prisoners win", kname, name, g_reward)
    }
    else
        log_amx("Assassination Day: the VIP %s died: the prisoners win", name)
    tell_all("ASSN_DEAD")
    stop_game()
    rg_round_end(5.0, WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "The VIP was assassinated!")
    return HC_CONTINUE
}

public on_can_damage(victim, attacker)
{
    if (!g_on || victim != g_vip || attacker < 1 || attacker > MaxClients || attacker == victim || !is_user_connected(attacker))
        return HC_CONTINUE
    /* Only prisoners may hurt the VIP: guards never, prisoners even a prisoner VIP. */
    SetHookChainReturn(ATYPE_INTEGER, cs_get_user_team(attacker) == CS_TEAM_T ? 1 : 0)
    return HC_SUPERCEDE
}

public on_round_end_post(WinStatus:status, ScenarioEventEndRound:event, Float:delay)
{
    if (!g_on)
        return HC_CONTINUE
    /* The round ended some other way (a team wiped out, the round timer): close the game. */
    log_amx("Assassination Day closed by the round end (win status %d)", _:status)
    stop_game()
    return HC_CONTINUE
}

public on_restart_pre()
{
    if (g_on)
        stop_game()
    return HC_CONTINUE
}

public client_disconnected(id)
{
    if (!g_on || id != g_vip)
        return
    g_vip = 0
    new vip = g_newVip ? pick_vip(id) : 0
    if (vip)
    {
        new name[MAX_NAME_LENGTH]
        get_user_name(vip, name, charsmax(name))
        log_amx("Assassination Day: the VIP left; the new VIP is %s", name)
        make_vip(vip)
        return
    }
    log_amx("Assassination Day: the VIP left: the game ends in a draw")
    tell_all("ASSN_LEFT")
    stop_game()
    rg_round_end(5.0, WINSTATUS_DRAW, ROUND_END_DRAW, "Assassination Day is called off")
}

/* ------------------------------------------------------------ commands */

reply(id, const key[])
{
    if (id && is_user_connected(id))
        client_print_color(id, print_team_default, "%L", id, key)
    else
        server_print("[Assassination Day] %L", LANG_SERVER, key)
}

tell_all(const key[])
{
    for (new i = 1; i <= MaxClients; i++)
    {
        if (is_user_connected(i))
            client_print_color(i, print_team_default, "%L", i, key)
    }
}

public cmd_assassin(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    new arg[16]
    read_argv(1, arg, charsmax(arg))
    if (equali(arg, "status"))
    {
        new name[MAX_NAME_LENGTH], prisoners, guards
        count_alive(prisoners, guards)
        if (g_vip)
            get_user_name(g_vip, name, charsmax(name))
        else
            copy(name, charsmax(name), "-")
        console_print(id, "Assassination Day: on %d, VIP %s (health %d), %d s left, games %d, alive %d prisoners / %d guards",
            g_on ? 1 : 0, name, g_vip ? get_user_health(g_vip) : 0, g_on ? g_left : 0, g_games, prisoners, guards)
        return PLUGIN_HANDLED
    }
    if (equali(arg, "stop"))
    {
        if (g_on)
        {
            stop_game()
            tell_all("ASSN_STOPPED")
            log_amx("Assassination Day stopped by an admin")
        }
        return PLUGIN_HANDLED
    }
    start_game(id)
    return PLUGIN_HANDLED
}

public cmd_warden(id)
{
    if (!is_user_connected(id))
        return PLUGIN_HANDLED
    if (jb_get_simon_id() != id)
    {
        client_print_color(id, print_team_default, "%L", id, "ASSN_NOT_WARDEN")
        return PLUGIN_HANDLED
    }
    start_game(id)
    return PLUGIN_HANDLED
}

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.