Skip to content
View in the app

A better way to browse. Learn more.

Learn more

bot-revive/addons/amxmodx/scripting/olds_botrevive.sma

olds_botrevive.sma
138 lines · 4 KB · Pawn (AMX Mod X)
Raw
/*
 * Bot Revive (olds.ro workshop card LIB-0779) - Deathmatch with bots
 *
 * While at least one bot is on the server, a human who dies is revived after
 * olds_botrevive_delay seconds (rg_round_respawn, the standard spawn loadout), with a HUD
 * countdown, so a lone human playing against bots gets a continuous game. With
 * olds_botrevive_bots_only 0 bots are revived too. olds_botrevive_max limits the revives
 * per player per round (0 = no limit). Without bots the plugin does nothing.
 *
 * Cvars: olds_botrevive_delay 5, olds_botrevive_bots_only 1, olds_botrevive_max 0.
 *
 * Copyright (C) 2026 daemon (olds.ro)
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
#include <amxmodx>
#include <reapi>

#define PLUGIN  "Bot Revive"
#define VERSION "1.0.0"
#define AUTHOR  "olds.ro"

#define TASK_TICK 77900     // + player id

new g_delay, g_botsOnly, g_max;
new g_revives[MAX_PLAYERS + 1];     // this round
new g_left[MAX_PLAYERS + 1];        // countdown seconds, 0 = none

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

    bind_pcvar_num(create_cvar("olds_botrevive_delay", "5", FCVAR_NONE,
        "Seconds before a dead player is revived", true, 1.0, true, 60.0), g_delay);
    bind_pcvar_num(create_cvar("olds_botrevive_bots_only", "1", FCVAR_NONE,
        "1 = only humans are revived (when bots are present), 0 = bots too", true, 0.0, true, 1.0), g_botsOnly);
    bind_pcvar_num(create_cvar("olds_botrevive_max", "0", FCVAR_NONE,
        "Revives per player per round (0 = no limit)", true, 0.0, true, 100.0), g_max);
    AutoExecConfig(true, "olds_botrevive");

    RegisterHookChain(RG_CBasePlayer_Killed, "on_killed", true);
    RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round", true);
    RegisterHookChain(RG_CBasePlayer_Spawn, "on_spawn", true);
}

bool:bots_present()
{
    for (new id = 1; id <= MaxClients; id++)
        if (is_user_connected(id) && is_user_bot(id))
            return true;
    return false;
}

public on_killed(victim, killer, gib)
{
    if (!(1 <= victim <= MaxClients) || !is_user_connected(victim))
        return HC_CONTINUE;
    if (is_user_bot(victim) && g_botsOnly)
        return HC_CONTINUE;
    if (!bots_present())
        return HC_CONTINUE;
    if (g_max && g_revives[victim] >= g_max)
    {
        if (!is_user_bot(victim))
            client_print_color(victim, print_team_default, "^4[Revive]^1 %L", victim, "BR_LIMIT", g_max);
        return HC_CONTINUE;
    }
    g_left[victim] = g_delay;
    remove_task(TASK_TICK + victim);
    set_task(1.0, "task_tick", TASK_TICK + victim, _, _, "a", g_delay);
    show_countdown(victim);
    return HC_CONTINUE;
}

public task_tick(task)
{
    new id = task - TASK_TICK;
    if (!g_left[id] || !is_user_connected(id) || is_user_alive(id))
    {
        stop(id);
        return;
    }
    if (--g_left[id] > 0)
    {
        show_countdown(id);
        return;
    }
    stop(id);

    new TeamName:team = get_member(id, m_iTeam);
    if (team != TEAM_TERRORIST && team != TEAM_CT)
        return;
    // Bots may have left during the countdown; a round that is ending restarts anyway.
    if (!bots_present() || get_member_game(m_bRoundTerminating))
        return;
    g_revives[id]++;
    rg_round_respawn(id);
    new name[MAX_NAME_LENGTH];
    get_user_name(id, name, charsmax(name));
    log_amx("%s revived (%d this round)", name, g_revives[id]);
}

stop(id)
{
    remove_task(TASK_TICK + id);
    g_left[id] = 0;
}

show_countdown(id)
{
    if (is_user_bot(id))
        return;
    set_hudmessage(80, 220, 120, -1.0, 0.35, 0, 0.0, 1.1, 0.0, 0.0, -1);
    show_hudmessage(id, "%L", id, "BR_HUD", g_left[id]);
}

public on_spawn(id)
{
    // Spawned by the round or by another plugin: no revive pending.
    if (is_user_alive(id))
        stop(id);
    return HC_CONTINUE;
}

public on_restart_round()
{
    for (new id = 1; id <= MaxClients; id++)
    {
        g_revives[id] = 0;
        stop(id);
    }
}

public client_disconnected(id)
{
    stop(id);
    g_revives[id] = 0;
}

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.