Skip to content
View in the app

A better way to browse. Learn more.

Learn more

free-armor-on-spawn/addons/amxmodx/scripting/olds_spawnarmor.sma

olds_spawnarmor.sma
170 lines · 6.2 KB · Pawn (AMX Mod X)
Raw
/*
 * Spawn Armor (olds.ro workshop card LIB-0301)
 *
 * Every player who spawns gets free armor: one amount for the Terrorists,
 * another for the Counter-Terrorists, a larger amount for players with the
 * "t" access flag, with or without a helmet.
 *
 * Armor is only ever raised. A player who still has more armor (kept from
 * the last round, bought, or given by another plugin such as a deathmatch
 * respawn) keeps it, and a helmet the player already wears is never taken
 * away.
 *
 * Commands: none.
 *
 * Cvars (saved with their descriptions in configs/plugins/olds_spawnarmor.cfg
 * the first time the plugin starts):
 *   olds_sarmor_t         50    Armor for Terrorists at each spawn (0 - 999,
 *                               0 = none).
 *   olds_sarmor_ct        100   Armor for Counter-Terrorists at each spawn
 *                               (0 - 999, 0 = none).
 *   olds_sarmor_helmet    1     1 = give vest and helmet, 0 = vest only.
 *   olds_sarmor_vip       150   Armor for players with access flag "t"
 *                               (0 - 999). They get this amount or their
 *                               team's amount, whichever is larger.
 *                               0 = they get the team amount like everyone.
 *   olds_sarmor_skipround 1     Rounds at the start of each game in which no
 *                               armor is given (0 - 100). 1 = none in the
 *                               first (pistol) round, 0 = armor from the
 *                               first round. A game starts with the map, at
 *                               "Game Commencing" and at every sv_restart.
 *
 * How it works, as the card asks: RG_CBasePlayer_Spawn (post) gives the
 * armor with rg_set_user_armor, which also updates the helmet icon on the
 * HUD. The round count is ReGameDLL's own m_iTotalRoundsPlayed.
 *
 * Requires AMX Mod X 1.10 with ReAPI (ReGameDLL_CS). Written and tested on
 * AMX Mod X 1.10.0.5490, ReAPI 5.29.0.358 and ReGameDLL_CS 5.30.0.814.
 *
 * Copyright (C) 2026 alexit (olds.ro workshop)
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * 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/>.
 */

#include <amxmodx>
#include <reapi>

#pragma semicolon 1

new const PLUGIN_NAME[] = "Spawn Armor";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";

// Access flag "t" marks the players who get olds_sarmor_vip.
const VIP_FLAG = ADMIN_LEVEL_H;

// Largest amount a cvar accepts. The HUD shows three digits.
const MAX_ARMOR = 999;

// Largest value of olds_sarmor_skipround.
const MAX_SKIP_ROUNDS = 100;

new g_armorT;        // olds_sarmor_t
new g_armorCT;       // olds_sarmor_ct
new g_helmet;        // olds_sarmor_helmet
new g_armorVip;      // olds_sarmor_vip
new g_skipRounds;    // olds_sarmor_skipround

public plugin_init()
{
	register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);

	// The spawn hook and the round count come from ReGameDLL_CS.
	if (!is_regamedll())
		set_fail_state("ReGameDLL_CS is not running. This plugin needs ReGameDLL_CS and ReAPI.");

	bind_pcvar_num(create_cvar("olds_sarmor_t", "50", FCVAR_NONE,
		"Armor given to Terrorists at each spawn (0 = none)",
		true, 0.0, true, float(MAX_ARMOR)), g_armorT);

	bind_pcvar_num(create_cvar("olds_sarmor_ct", "100", FCVAR_NONE,
		"Armor given to Counter-Terrorists at each spawn (0 = none)",
		true, 0.0, true, float(MAX_ARMOR)), g_armorCT);

	bind_pcvar_num(create_cvar("olds_sarmor_helmet", "1", FCVAR_NONE,
		"1 = give vest and helmet, 0 = vest only",
		true, 0.0, true, 1.0), g_helmet);

	bind_pcvar_num(create_cvar("olds_sarmor_vip", "150", FCVAR_NONE,
		"Armor for players with access flag t; they get this or their team amount, whichever is larger (0 = team amount)",
		true, 0.0, true, float(MAX_ARMOR)), g_armorVip);

	bind_pcvar_num(create_cvar("olds_sarmor_skipround", "1", FCVAR_NONE,
		"Rounds at the start of each game with no free armor (1 = skip the pistol round, 0 = give armor from the first round)",
		true, 0.0, true, float(MAX_SKIP_ROUNDS)), g_skipRounds);

	AutoExecConfig(true, "olds_spawnarmor");

	RegisterHookChain(RG_CBasePlayer_Spawn, "on_player_spawn_post", true);
}

/**
 * Runs after the game has finished spawning the player, so the armor the
 * player kept from the last round, and any armor the game itself gave, is
 * already in place and can be compared.
 */
public on_player_spawn_post(id)
{
	// The hook also runs for a player who is still choosing a team. Only a
	// living Terrorist or Counter-Terrorist gets armor.
	if (!is_user_alive(id))
		return HC_CONTINUE;

	new amount;

	switch (TeamName:get_member(id, m_iTeam))
	{
		case TEAM_TERRORIST: amount = g_armorT;
		case TEAM_CT: amount = g_armorCT;
		default: return HC_CONTINUE;
	}

	// A VIP never gets less than the rest of the team.
	if (g_armorVip > 0 && (get_user_flags(id) & VIP_FLAG))
		amount = max(amount, g_armorVip);

	if (amount > 0 && !is_skipped_round())
		raise_armor(id, amount);

	return HC_CONTINUE;
}

/**
 * Tells whether the current round is one of the first olds_sarmor_skipround
 * rounds of the game. ReGameDLL counts the rounds already played: 0 during
 * the first round, and back to 0 after a map change, "Game Commencing" or
 * sv_restart.
 */
bool:is_skipped_round()
{
	return get_member_game(m_iTotalRoundsPlayed) < g_skipRounds;
}

/**
 * Gives the player at least amount armor. Nothing is ever lowered: a larger
 * amount stays, and a helmet the player already wears stays even with
 * olds_sarmor_helmet 0.
 */
raise_armor(id, amount)
{
	new ArmorType:current;
	new armor = rg_get_user_armor(id, current);

	new ArmorType:wanted = (g_helmet || current == ARMOR_VESTHELM) ? ARMOR_VESTHELM : ARMOR_KEVLAR;

	if (armor >= amount && current == wanted)
		return;

	// rg_set_user_armor also sends ArmorType, so the HUD shows the helmet
	// icon only when a helmet is worn.
	rg_set_user_armor(id, max(armor, amount), wanted);
}

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.