Skip to content
View in the app

A better way to browse. Learn more.

Learn more

surf-jail-remover/addons/amxmodx/scripting/olds_jailrm.sma

olds_jailrm.sma
181 lines · 5.3 KB · Pawn (AMX Mod X)
Raw
/*
 * Surf Jail Remover (olds.ro)
 * 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.
 * You should have received a copy of the GNU General Public License along with this
 * program. If not, see <https://www.gnu.org/licenses/>.
 *
 * On listed surf maps, removes (or opens) the jail cage some time after each round
 * starts, so the jail trap cannot hold players forever.
 */
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <hamsandwich>
#include <reapi>

#define PLUGIN  "Surf Jail Remover"
#define VERSION "1.0.0"
#define AUTHOR  "daemon (olds.ro)"

#define TASK_APPLY  21750
#define MAX_NAMES   16
#define NAME_LEN    32

new g_cvar_delay, g_cvar_mode, g_cvar_msg;
new bool:g_active;
new g_names[MAX_NAMES][NAME_LEN];
new g_name_count;

bool:can_open(const classname[])
{
    return bool:(equal(classname, "func_door") || equal(classname, "func_door_rotating")
        || equal(classname, "momentary_door") || equal(classname, "func_breakable"));
}

bool:map_matches(const map[], const pattern[])
{
    new len = strlen(pattern);
    if (len > 1 && pattern[len - 1] == '*')
        return bool:(equali(map, pattern, len - 1));
    return bool:(equali(map, pattern));
}

/*
 * olds_jailrm.ini: "<map> [targetname ...]" per line. A map ending in * matches every
 * map that starts with the text before it. Without names: jail_door jail_cage.
 */
bool:read_ini(const map[])
{
    new path[128];
    get_localinfo("amxx_configsdir", path, charsmax(path));
    add(path, charsmax(path), "/olds_jailrm.ini");

    new fp = fopen(path, "rt");
    if (!fp)
    {
        log_amx("Cannot open %s.", path);
        return false;
    }

    new line[256], word[NAME_LEN], rest[256];
    new bool:found = false;
    g_name_count = 0;

    while (!found && fgets(fp, line, charsmax(line)))
    {
        trim(line);
        if (!line[0] || line[0] == ';' || line[0] == '#' || (line[0] == '/' && line[1] == '/'))
            continue;

        strtok2(line, word, charsmax(word), rest, charsmax(rest), ' ', TRIM_FULL);
        if (!map_matches(map, word))
            continue;

        found = true;
        while (rest[0] && g_name_count < MAX_NAMES)
        {
            copy(line, charsmax(line), rest);
            strtok2(line, word, charsmax(word), rest, charsmax(rest), ' ', TRIM_FULL);
            if (word[0])
                copy(g_names[g_name_count++], NAME_LEN - 1, word);
        }
    }
    fclose(fp);

    if (found && !g_name_count)
    {
        copy(g_names[0], NAME_LEN - 1, "jail_door");
        copy(g_names[1], NAME_LEN - 1, "jail_cage");
        g_name_count = 2;
    }
    return found;
}

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

    g_cvar_delay = create_cvar("olds_jail_delay", "30.0", FCVAR_NONE,
        "Seconds after the round starts before the jail is removed or opened", true, 0.0, true, 600.0);
    g_cvar_mode = create_cvar("olds_jail_mode", "1", FCVAR_NONE,
        "1 = remove the jail entities, 2 = open doors (entities that cannot open are removed)", true, 1.0, true, 2.0);
    g_cvar_msg = create_cvar("olds_jail_msg", "1", FCVAR_NONE,
        "1 = tell the players when the jail is gone", true, 0.0, true, 1.0);
    AutoExecConfig(true, "olds_jailrm");

    RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round", true);
}

public plugin_cfg()
{
    new map[32];
    get_mapname(map, charsmax(map));
    g_active = read_ini(map);

    if (!g_active)
    {
        log_amx("Map %s is not listed in olds_jailrm.ini: nothing to do.", map);
        return;
    }
    // The first round may already have started before this plugin was ready.
    schedule_apply();
}

public on_restart_round()
{
    if (g_active)
        schedule_apply();
}

schedule_apply()
{
    remove_task(TASK_APPLY);
    set_task(floatmax(get_pcvar_float(g_cvar_delay), 0.1), "task_apply", TASK_APPLY);
}

public task_apply()
{
    if (!g_active)
        return;

    new mode = get_pcvar_num(g_cvar_mode);
    new removed = 0, opened = 0;
    new ent, next_ent, classname[32];

    for (new i = 0; i < g_name_count; i++)
    {
        ent = find_ent_by_tname(-1, g_names[i]);
        while (ent > 0)
        {
            // Look up the next one first: this one may be removed.
            next_ent = find_ent_by_tname(ent, g_names[i]);

            if (pev_valid(ent) == 2)
            {
                pev(ent, pev_classname, classname, charsmax(classname));
                if (mode == 2 && can_open(classname))
                {
                    ExecuteHamB(Ham_Use, ent, 0, 0, 1, 1.0);
                    opened++;
                }
                else
                {
                    engfunc(EngFunc_RemoveEntity, ent);
                    removed++;
                }
            }
            ent = next_ent;
        }
    }

    if (removed + opened > 0 && get_pcvar_num(g_cvar_msg))
        client_print_color(0, print_team_default, "%l", "JAILRM_OPEN");
}

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.