Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new ConVar: redm_equip_manager #123

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cstrike/addons/amxmodx/configs/redm/gamemode_deathmatch.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,14 @@
"redm_aim_barrier_always_show": "2",

// Open equip menu by pressing `G` (drop command).
"redm_open_equip_menu_by_g": "1",
"redm_equip_menu_open_by_g": "1",

// Block the ability to drop the weapon.
"redm_block_drop_weapon": "1",

// Enable equip manager.
"redm_equip_manager": "1",

// Restore weapon slot on respawn.
"redm_keep_weapon_slot": "0",

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ static WeaponState: g_weaponState[MAX_PLAYERS + 1]
*/
static bool: g_inEquipMenu[MAX_PLAYERS + 1]

static bool: redm_equip_manager
static redm_keep_weapon_slot
static bool: redm_open_equip_menu
static bool: redm_equip_menu_open_by_g


EquipManager_Init() {
Expand All @@ -59,6 +61,16 @@ EquipManager_Init() {
// RegisterHookChain(RG_CBasePlayer_GiveNamedItem, "CBasePlayer_GiveNamedItem", .post = false)
RegisterHookChain(RG_CBasePlayer_AddPlayerItem, "CBasePlayer_AddPlayerItem", .post = false)

bind_pcvar_num(
create_cvar(
"redm_equip_manager", "1",
.has_min = true, .min_val = 0.0,
.has_max = true, .max_val = 1.0,
.flags = _FCVAR_BOOLEAN,
.description = "Enable equip manager."
),
redm_equip_manager
)
bind_pcvar_num(
create_cvar(
"redm_keep_weapon_slot", "0",
Expand All @@ -79,8 +91,22 @@ EquipManager_Init() {
),
redm_open_equip_menu
)
bind_pcvar_num(
create_cvar(
"redm_equip_menu_open_by_g", "1",
.has_min = true, .min_val = 0.0,
.has_max = true, .max_val = 1.0,
.flags = _FCVAR_BOOLEAN,
.description = "Open equip menu by pressing `G` (drop command)."
),
redm_equip_menu_open_by_g
)

register_concmd("redm_dump_equip", "ConCmd_redm_dump_equip", ADMIN_MAP, "Dump loaded equipset from config to table in console.")
register_concmd(
"redm_dump_equip", "ConCmd_redm_dump_equip",
ADMIN_MAP,
"Dump loaded equipset from config to table in console."
)

new const equipMenuCmds[][] = {
"say /guns", "say !guns", "guns"
Expand All @@ -91,6 +117,7 @@ EquipManager_Init() {
}

register_clcmd("cl_autobuy", "ClCmd_cl_autobuy", .FlagManager = false)
register_clcmd("drop", "ClCmd_Drop", .FlagManager = false)
}

/**
Expand All @@ -102,6 +129,9 @@ EquipManager_PutInServer(const player) {
EquipManager_Reset(player)
g_lastWeaponSlot[player] = PRIMARY_WEAPON_SLOT

if (!redm_equip_manager)
return

if (is_user_bot(player) || is_user_hltv(player))
return

Expand Down Expand Up @@ -192,12 +222,25 @@ static LoadConfigBotEquip(const JSON: objEquip, const EquipType_e: section) {
public ClCmd_cl_autobuy(const player) {
if (!IsActive())
return PLUGIN_CONTINUE

if (!redm_equip_manager)
return PLUGIN_CONTINUE

Player_SwitchRandomWeapons(player, .newState = !g_playerRandomWeapons[player])

return PLUGIN_HANDLED
}

public ClCmd_Drop(const player) {
if (!IsActive())
return PLUGIN_CONTINUE

if (!redm_equip_menu_open_by_g)
return PLUGIN_CONTINUE

return ClCmd_Guns(player)
}

/**
* Handles the "/guns" client command.
*
Expand All @@ -207,6 +250,9 @@ public ClCmd_Guns(const player) {
if (!IsActive())
return PLUGIN_CONTINUE

if (!redm_equip_manager)
return PLUGIN_CONTINUE

Player_CallEquipMenu(player)

return PLUGIN_HANDLED
Expand Down Expand Up @@ -290,7 +336,7 @@ static Menu_ChooseEquip(const player, const EquipType_e: section) {
new menuTitle[128]
formatex(menuTitle, charsmax(menuTitle), "%l", section == et_Primary ? "PrimaryEquip" : "SecondaryEquip")

if (get_cvar_num("redm_open_equip_menu_by_g"))
if (redm_equip_menu_open_by_g)
strcat(menuTitle, fmt("^n%l", "ToClosePressG"), charsmax(menuTitle))

new menu = menu_create(menuTitle, "MenuHandler_ChooseEquip")
Expand Down Expand Up @@ -343,6 +389,9 @@ public MenuCallback_Primary(const player, const menu, const item) {
public MenuHandler_ChooseEquip(const player, const menu, const item) {
if (!IsActive())
return PLUGIN_HANDLED

if (!redm_equip_manager)
return PLUGIN_HANDLED

new info[2]
menu_item_getinfo(
Expand Down Expand Up @@ -391,11 +440,14 @@ public CBasePlayer_OnSpawnEquip(const player, bool: addDefault, bool: equipGame)
if (!IsActive())
return

SetHookChainArg(3, ATYPE_BOOL, (equipGame = false))

RoundModes_OnSpawnEquip(player)
ModeVote_OnSpawnEquip(player)

if (!redm_equip_manager)
return

SetHookChainArg(3, ATYPE_BOOL, (equipGame = false))

set_member(player, m_bNotKilled, false)
rg_set_user_armor(player, 0, ARMOR_NONE)

Expand Down Expand Up @@ -427,6 +479,9 @@ public CBasePlayer_OnSpawnEquip_Post(const player, bool: addDefault, bool: equip
if (!IsActive())
return

if (!redm_equip_manager)
return

new hasConfiguredEquip = false
for (new EquipType_e: section; section < EquipType_e; section++) {
if (g_playerWeapons[player][section] == EQUIP_NOT_CHOOSEN)
Expand All @@ -453,6 +508,9 @@ public CBasePlayer_AddPlayerItem(const player, const item) {
if (!IsActive())
return

if (!redm_equip_manager)
return

// Restore weaponState
set_member(item, m_Weapon_iWeaponState, g_weaponState[player])
}
Expand Down
25 changes: 0 additions & 25 deletions cstrike/addons/amxmodx/scripting/ReDeathmatch/ReDM_features.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ static g_oldGroupinfo[MAX_PLAYERS + 1]
static bool: g_protectionState[MAX_PLAYERS + 1]
static Float: g_nextPlayerChooseTeam[MAX_PLAYERS + 1]

static bool: redm_open_equip_menu_by_g
static bool: redm_block_drop_weapon
static Float: redm_sounds_distance
static Float: redm_healer
Expand Down Expand Up @@ -54,16 +53,6 @@ Features_Init() {
AimBarriers_Init()
Tickets_Init()

bind_pcvar_num(
create_cvar(
"redm_open_equip_menu_by_g", "1",
.has_min = true, .min_val = 0.0,
.has_max = true, .max_val = 1.0,
.flags = _FCVAR_BOOLEAN,
.description = "Open equip menu by pressing `G` (drop command)."
),
redm_open_equip_menu_by_g
)
bind_pcvar_num(
create_cvar(
"redm_block_drop_weapon", "1",
Expand Down Expand Up @@ -201,20 +190,6 @@ Features_Init() {
),
redm_changeteam_freq
)

register_clcmd("drop", "ClCmd_Drop", .FlagManager = false)
}

public ClCmd_Drop(const player) {
if (!IsActive())
return PLUGIN_CONTINUE

if (!redm_open_equip_menu_by_g)
return PLUGIN_CONTINUE

amxclient_cmd(player, "guns")

return PLUGIN_HANDLED
}

public MsgHook_HudTextArgs() {
Expand Down