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

Modes enhance #35

Merged
merged 4 commits into from
Sep 6, 2023
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
15 changes: 15 additions & 0 deletions cstrike/addons/amxmodx/data/lang/redm/redm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ ToClosePressG = \wTo close the menu - press `\yG\w`
CurrentMode = Current mode:
NextMode = Next Mode -
YouCanChooseEquip = You can select equipment by pressing `^3G^1` (or \3/guns^1).
ModeChanges = The game mode changes.
Modes = Game modes
DisableForceMode = Disable forced mode
NextGameMode = next game mode
Choose = Choose
Selecting = Selecting
Extend = extend


[ru]
Currently = сейчас
Expand All @@ -25,3 +33,10 @@ ToClosePressG = \wЧтобы закрыть меню - нажмите `\yG\w`
CurrentMode = Текущий режим:
NextMode = Следующий режим -
YouCanChooseEquip = Вы можете выбрать экипировку нажав `^3G^1` (или ^3/guns^1).
ModeChanges = Смена режима игры.
Modes = Режимы игры
DisableForceMode = Отключить фиксированный режим
NextGameMode = следующий игровой режим
Choose = Выберите
Selecting = Выбор
Extend = продлить
4 changes: 4 additions & 0 deletions cstrike/addons/amxmodx/scripting/ReDeathmatch.sma
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public client_putinserver(player) {
EquipManager_PutInServer(player)
}

public client_disconnected(player, bool: drop, message[], maxLen) {
ModeVote_Disconnected(player)
}

public CSGameRules_PlayerKilled_Post(const victim, const killer, const inflictor) {
if (!IsActive())
return
Expand Down
261 changes: 261 additions & 0 deletions cstrike/addons/amxmodx/scripting/ReDeathmatch/Modes/Menus.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
static MENU_FLAG = ADMIN_MAP

ModesMenus_Init() {
registerClCmd(
"redm_modes_menu",
"ClCmd_redm_modes_menu",
.flags = MENU_FLAG,
.info = "ReDM: Change game mode"
)

register_clcmd("say /modes", "ClCmd_redm_modes_menu", .flags = MENU_FLAG)
}

public ClCmd_redm_modes_menu(const player, const level, const cid) {
if (!cmd_access(player, level, cid, 1))
return PLUGIN_HANDLED

if (!IsActive())
return PLUGIN_HANDLED

Menu_Modes(player)

return PLUGIN_HANDLED
}

static bool: Menu_Modes(const player) {
if (!json_object_has_value(Config_GetCurrent(), "modes"))
return false

new JSON: arrModes = json_object_get_value(Config_GetCurrent(), "modes")

new count = json_array_get_count(arrModes)
if (!count) {
json_free(arrModes)

return false
}

new callback
if (!callback)
callback = menu_makecallback("MenuCallback_Modes")

SetGlobalTransTarget(player)
new menu = menu_create(fmt("%l", "Modes"), "MenuHandler_Modes")

if (!IsModeForced()) {
menu_additem(
menu,
fmt(
"%l^n",
"DisableForceMode"
),
.callback = callback
)
} else {
new modeName[64]
GetModeInfo(RoundModes_GetCurrentMode(), modeName, charsmax(modeName))

menu_additem(
menu,
fmt(
HasLangKey(modeName) ? "%l^n %l: \d%l\w^n" : "%l^n %l: \d%s\w^n" ,
"DisableForceMode",
"Currently",
modeName
),
.callback = callback
)
}

for (new idx; idx < count; idx++) {
new JSON: objMode = json_array_get_value(arrModes, idx)

new modeName[32]
json_object_get_string(objMode, "name", modeName, charsmax(modeName))

menu_additem(menu, fmt(HasLangKey(modeName) ? "%l" : "%s", modeName))

json_free(objMode)
}

json_free(arrModes)

menu_setprop(menu, MPROP_BACKNAME, fmt("%l", "BACK"))
menu_setprop(menu, MPROP_NEXTNAME, fmt("%l", "MORE"))
menu_setprop(menu, MPROP_EXITNAME, fmt("%l", "EXIT"))
menu_setprop(menu, MPROP_NUMBER_COLOR, "\y")

menu_display(player, menu)

return true
}

public MenuCallback_Modes(const player, const menu, const item) {
// Disable only `force mode` item
if (item != 0)
return ITEM_IGNORE

return IsModeForced() ? ITEM_IGNORE : ITEM_DISABLED
}

public MenuHandler_Modes(const player, const menu, const item) {
menu_destroy(menu)

if (!IsActive())
return PLUGIN_HANDLED

if(item < 0) {
UTIL_PlaySoundEffect(player, "fvox/blip.wav", .pitch = 30)

return PLUGIN_HANDLED
}

new modeIdx = (item - 1)

RoundModes_SetCurrentMode(modeIdx)

rg_round_end(
CHalfLifeMultiplay__GetRoundRestartDelay(),
WINSTATUS_DRAW,
ROUND_END_DRAW,
fmt("%L", LANG_SERVER, "ModeChanges"),
.trigger = true
)

UTIL_PlaySoundEffect(player, "fvox/blip.wav", .pitch = 80)

return PLUGIN_HANDLED
}

Menu_GetVoteItemsCount() {
if (!json_object_has_value(Config_GetCurrent(), "modes"))
return false

new JSON: arrModes = json_object_get_value(Config_GetCurrent(), "modes")
new count = json_array_get_count(arrModes)
json_free(arrModes)

return count
}

bool: Menu_VoteMode(const player = 0) {
if (!json_object_has_value(Config_GetCurrent(), "modes"))
return false

new JSON: arrModes = json_object_get_value(Config_GetCurrent(), "modes")

new count = json_array_get_count(arrModes)
if (!count) {
json_free(arrModes)
return false
}

new menu = menu_create("Choose", "MenuHandler_ChooseNextMode")

static callback
if (!callback)
callback = menu_makecallback("MenuCallback_ChooseNextMode")

for (new idx; idx < count; idx++) {
new JSON: objMode = json_array_get_value(arrModes, idx)

new modeName[32]
json_object_get_string(objMode, "name", modeName, charsmax(modeName))

menu_additem(menu, modeName, .callback = callback)

json_free(objMode)
}

menu_setprop(menu, MPROP_BACKNAME, fmt("%l", "BACK"))
menu_setprop(menu, MPROP_NEXTNAME, fmt("%l", "MORE"))
menu_setprop(menu, MPROP_NUMBER_COLOR, "\y")
menu_setprop(menu, MPROP_EXITNAME, fmt("%l", "EXIT"))
menu_setprop(menu, MPROP_EXIT, MEXIT_NEVER)

new players[MAX_PLAYERS], playersCount
get_players(players, playersCount, "ch")

for (new idx; idx < playersCount; idx++) {
new p = player ? player : players[idx]

SetGlobalTransTarget(p)

menu_setprop(menu, MPROP_TITLE, fmt("%l %l", "Choose", "NextGameMode"))
menu_display(p, menu, .time = 1)

if (player)
break
}

return true
}

public MenuCallback_ChooseNextMode(const player, const menu, const item) {
new modeName[32]
menu_item_getinfo(
menu, item,
.name = modeName,
.namelen = charsmax(modeName)
)

SetGlobalTransTarget(player)

new buffer[256]

new bool: playerInVote = Vote_IsPlayerParticipatingInVote(player)

strcat(buffer, fmt(!playerInVote ? "\d" : ""), charsmax(buffer))
strcat(buffer, fmt(HasLangKey(modeName) ? "%l" : "%s", modeName), charsmax(buffer))

new bool: isCurrentModeItem = (item == RoundModes_GetCurrentMode())
strcat(buffer, fmt(isCurrentModeItem ? " \d(%l)" : "", "Extend"), charsmax(buffer))

new votesCount = Vote_GetItemVotesCount(item)
new playerVote = Vote_PlayerGetVote(player)
new playersCount = Vote_GetPlayersCount()
new Float: votedPercent = (votesCount * 100.0) / playersCount

if (item == playerVote)
strcat(buffer, "\r", charsmax(buffer))

strcat(buffer, fmt("\R%.0f%%", votedPercent), charsmax(buffer))

menu_item_setname(menu, item, buffer)

new bool: playerHasVote = Vote_IsPlayerVoted(player)
if(playerHasVote) {
return item != playerVote ? ITEM_DISABLED : ITEM_IGNORE
}

return ITEM_IGNORE
}

public MenuHandler_ChooseNextMode(const player, const menu, const item) {
menu_destroy(menu)

if (!IsActive())
return PLUGIN_HANDLED

if (!ModeVote_IsVoteStarted())
return PLUGIN_HANDLED

new bool: playerInVote = Vote_IsPlayerParticipatingInVote(player)
if (Vote_IsPlayerVoted(player) || !playerInVote)
return PLUGIN_HANDLED

if (item < 0) {
UTIL_PlaySoundEffect(player, "fvox/blip.wav", .pitch = 30)

return PLUGIN_HANDLED
}

UTIL_PlaySoundEffect(player, "fvox/blip.wav", .pitch = 80)

Vote_PlayerVote(player, item)

Menu_VoteMode(player)

return PLUGIN_HANDLED
}
Loading
Loading