Skip to content

Commit

Permalink
Feature: ConVars flags extend (#88)
Browse files Browse the repository at this point in the history
* redm.inc: add `ConVar_ExtendedFlags`

* Add extended flags to convars

* Feature: new command `redm_dump_settings` - show mode current settings (#89)

* redm.inc: add GetCvarTypeStr()

* new command: `redm_dump_settings` - show mode current settings
  • Loading branch information
SergeyShorokhov authored Feb 11, 2024
1 parent 09e487f commit f33195e
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 1 deletion.
1 change: 1 addition & 0 deletions cstrike/addons/amxmodx/scripting/ReDeathmatch.sma
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public plugin_init() {
"redm_active", "1",
.has_min = true, .min_val = 0.0,
.has_max = true, .max_val = 1.0,
.flags = _FCVAR_BOOLEAN,
.description = "Controls the state of Re:DM. \
Don't use into ReDM configs!"
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ AimBarriers_Init() {
"redm_aim_barrier", "1",
.has_min = true, .min_val = 0.0,
.has_max = true, .max_val = 1.0,
.flags = _FCVAR_BOOLEAN,
.description = "Enable a barrier in the middle of the map (`anti-rush' system). \
It does not work on `de_`, `cs_` `css_` maps."
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ModeVote_Init() {
"redm_mode_vote_enable", "1",
.has_min = true, .min_val = 0.0,
.has_max = true, .max_val = 1.0,
.flags = _FCVAR_BOOLEAN,
.description = "Enable voting for the next game mode."
),
redm_mode_vote_enable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ static Trie: g_cvarValues = Invalid_Trie

CvarsHandler_Init() {
register_concmd("redm_dump_cvars", "ConCmd_redm_dump_cvars", ADMIN_MAP, "Dump changed CVar to table.")
register_concmd("redm_dump_settings", "ConCmd_redm_dump_settings", ADMIN_MAP, "Dump mode settings")
}

/**
Expand All @@ -21,6 +22,23 @@ public ConCmd_redm_dump_cvars(const player, const level, const commandId) {
return PLUGIN_HANDLED
}

/**
* Displays mode settings to the specified player.
*
* @param player The player to whom the CVAR values should be displayed.
* @param level The access level of the player executing the command.
* @param commandId The ID of the command.
* @return Returns PLUGIN_HANDLED.
*/
public ConCmd_redm_dump_settings(const player, const level, const commandId) {
if (!cmd_access(player, level, commandId, 1))
return PLUGIN_HANDLED

DumpAllSettings(player)

return PLUGIN_HANDLED
}

/**
* Loads CVAR settings from a Re:DM configuration.
*
Expand Down Expand Up @@ -194,3 +212,81 @@ stock DumpAllSavedCvars(const player = 0) {

TrieIterDestroy(iter)
}

DumpAllSettings(const player = 0, const prefix[] = "redm_") {
new const template[] = "| %-2i | %-32.32s | %-7s | %-16s | %10s |"
console_print(player, "| %-2s | %-32.32s | %-7s | %-16s | %10s |",
"#", "ConVar name", "type", "value", "bounds"
)
console_print(player,
"| -- | -------------------------------- | ------- | ---------------- | ---------- |"
)

for (new cvarIndex, idx; cvarIndex < 100; cvarIndex++) {
new name[32]
new flags
new pluginId
new cvarHandle
new description[192]

new bool: found = get_plugins_cvar(
cvarIndex,
name, charsmax(name),
flags,
pluginId,
cvarHandle,
description, charsmax(description)
) != 0

if (!found)
continue

if (flags & FCVAR_PROTECTED)
continue

#if 0
// TODO: Does it need to be?
static currentPluginId = -1
if (currentPluginId == -1)
currentPluginId = get_plugin(-1)

if (pluginId != currentPluginId)
continue
#endif

if (strncmp(name, prefix, strlen(prefix), .ignorecase = true) != 0)
continue

new valueStr[32]
if (flags & _FCVAR_FLOAT)
formatex(valueStr, charsmax(valueStr), "%.2f", get_pcvar_float(cvarHandle))
else
get_pcvar_string(cvarHandle, valueStr, charsmax(valueStr))

enum Bounds_s {
bool: hasBound,
Float: value
}
new bounds[CvarBounds][Bounds_s]

for (new CvarBounds: boundType; boundType < CvarBounds; boundType++) {
bounds[boundType][hasBound] = get_pcvar_bounds(cvarHandle, boundType, bounds[boundType][value])
}

new boundsBuffer[32]
if (bounds[CvarBound_Lower][hasBound] || bounds[CvarBound_Upper][hasBound]) {
formatex(boundsBuffer, charsmax(boundsBuffer), "%s .. %s",
bounds[CvarBound_Lower][hasBound] ? fmt("%.1f", bounds[CvarBound_Lower][value]) : " - ",
bounds[CvarBound_Upper][hasBound] ? fmt("%.1f", bounds[CvarBound_Upper][value]) : " - "
)
}

console_print(player, template,
++idx,
name,
GetCvarTypeStr(flags),
valueStr,
boundsBuffer
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ EquipManager_Init() {
"redm_keep_weapon_slot", "1",
.has_min = true, .min_val = 0.0,
.has_max = true, .max_val = 1.0,
.flags = _FCVAR_BOOLEAN,
.description = "Restore weapon slot on respawn."
),
redm_keep_weapon_slot
Expand All @@ -71,6 +72,7 @@ EquipManager_Init() {
"redm_open_equip_menu", "0",
.has_min = true, .min_val = 0.0,
.has_max = true, .max_val = 1.0,
.flags = _FCVAR_BOOLEAN,
.description = "Open weapon equip menu on spawn."
),
redm_open_equip_menu
Expand Down
13 changes: 13 additions & 0 deletions cstrike/addons/amxmodx/scripting/ReDeathmatch/ReDM_features.inc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Features_Init() {
"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
Expand All @@ -60,6 +61,7 @@ Features_Init() {
"redm_block_drop_weapon", "1",
.has_min = true, .min_val = 0.0,
.has_max = true, .max_val = 1.0,
.flags = _FCVAR_BOOLEAN,
.description = "Block the ability to drop the weapon."
),
redm_block_drop_weapon
Expand All @@ -68,6 +70,7 @@ Features_Init() {
create_cvar(
"redm_healer", "10.0",
.has_min = true, .min_val = 0.0,
.flags = _FCVAR_FLOAT,
.description = "How much to restore HP when killing an enemy."
),
redm_healer
Expand All @@ -76,6 +79,7 @@ Features_Init() {
create_cvar(
"redm_healer_hs", "20.0",
.has_min = true, .min_val = 0.0,
.flags = _FCVAR_FLOAT,
.description = "How much to restore HP when killing with HS an enemy."
),
redm_healer_hs
Expand All @@ -84,6 +88,7 @@ Features_Init() {
create_cvar(
"redm_sounds_distance", "1500.0",
.has_min = true, .min_val = 0.0,
.flags = _FCVAR_FLOAT,
.description = "Mute the sounds of other players at a distance."
),
redm_sounds_distance
Expand All @@ -93,13 +98,15 @@ Features_Init() {
"redm_fade", "1",
.has_min = true, .min_val = 0.0,
.has_max = true, .max_val = 1.0,
.flags = _FCVAR_BOOLEAN,
.description = "Highlight the display when you kill someone."
),
redm_fade
)
bind_pcvar_string(
create_cvar(
"redm_fade_colors", "0 200 0 50",
.flags = _FCVAR_STRING,
.description = "Kill highlights color [RGBA]"
),
redm_fade_colors, charsmax(redm_fade_colors)
Expand All @@ -109,6 +116,7 @@ Features_Init() {
"redm_refill_ammo", "1",
.has_min = true, .min_val = 0.0,
.has_max = true, .max_val = 1.0,
.flags = _FCVAR_BOOLEAN,
.description = "Refill ammo on kills."
),
redm_refill_ammo
Expand All @@ -118,6 +126,7 @@ Features_Init() {
"redm_hitsound", "1",
.has_min = true, .min_val = 0.0,
.has_max = true, .max_val = 1.0,
.flags = _FCVAR_BOOLEAN,
.description = "Play a sound when an enemy is hit."
),
redm_hitsound
Expand All @@ -127,6 +136,7 @@ Features_Init() {
"mp_damage_headshot_only", "0",
.has_min = true, .min_val = 0.0,
.has_max = true, .max_val = 1.0,
.flags = _FCVAR_BOOLEAN,
.description = "Enable hits only in HS."
),
mp_damage_headshot_only
Expand All @@ -136,20 +146,23 @@ Features_Init() {
"redm_hide_other_deathnotice", "1",
.has_min = true, .min_val = 0.0,
.has_max = true, .max_val = 1.0,
.flags = _FCVAR_BOOLEAN,
.description = "Hide other players' killfeed."
),
redm_hide_other_deathnotice
)
bind_pcvar_string(
create_cvar(
"redm_protection_color_t", "200 0 0 15",
.flags = _FCVAR_STRING,
.description = "On spawn T protection colors [RGBA]"
),
redm_protection_color_t, charsmax(redm_protection_color_t)
)
bind_pcvar_string(
create_cvar(
"redm_protection_color_ct", "0 0 200 15",
.flags = _FCVAR_STRING,
.description = "On spawn CT protection colors [RGBA]"
),
redm_protection_color_ct, charsmax(redm_protection_color_ct)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ RoundModes_Init() {
bind_pcvar_string(
create_cvar(
"redm_modes_switch", "sequentially",
.flags = (_FCVAR_STRING | _FCVAR_BOOLEAN),
.description = "Game mode change mode. \
`0`, `disable` - disable modes, \
`random` - random change, \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ static redm_spawn_preset[32]

SpawnManager_Init() {
bind_pcvar_string(
create_cvar("redm_spawn_preset", "preset"),
create_cvar(
"redm_spawn_preset",
"preset",
.flags = _FCVAR_STRING
),
redm_spawn_preset,
charsmax(redm_spawn_preset)
)
Expand Down
23 changes: 23 additions & 0 deletions cstrike/addons/amxmodx/scripting/include/redm.inc
Original file line number Diff line number Diff line change
Expand Up @@ -590,3 +590,26 @@ stock _xs_vec_to_string(const Float: vec[], output[], const len, const precision
stock const XS_X = 0;
stock const XS_Y = 1;
stock const XS_Z = 2;

// Extend ConVar flags.
enum _: ConVar_ExtendedFlags (<<= 1) {
_FCVAR_BOOLEAN = (FCVAR_NOEXTRAWHITEPACE << 1), /**< Can contain boolean value */
_FCVAR_STRING, /**< Can contain string value */
_FCVAR_FLOAT, /**< Can contain float value */
}

stock GetCvarTypeStr(const /* ConVar_ExtendedFlags: */ flags) {
new buffer[32]
copy(buffer, charsmax(buffer), "number")

if (flags & _FCVAR_BOOLEAN)
copy(buffer, charsmax(buffer), "boolean")

if (flags & _FCVAR_STRING)
copy(buffer, charsmax(buffer), "string")

if (flags & _FCVAR_FLOAT)
copy(buffer, charsmax(buffer), "float")

return buffer
}
2 changes: 2 additions & 0 deletions cstrike/addons/amxmodx/scripting/redm_spawns.sma
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public plugin_cfg() {
"redm_randomspawn_los", "1",
.has_min = true, .min_val = 0.0,
.has_max = true, .max_val = 1.0,
.flags = _FCVAR_BOOLEAN,
.description = "Check the spawn point for visibility by enemies (line of sight)."
),
redm_randomspawn_los
Expand All @@ -108,6 +109,7 @@ public plugin_cfg() {
create_cvar(
"redm_randomspawn_dist", "1500.0",
.has_min = true, .min_val = 0.0,
.flags = _FCVAR_FLOAT,
.description = "Minimum distance to the enemy to enable spawn checks."
),
redm_randomspawn_dist
Expand Down

0 comments on commit f33195e

Please sign in to comment.