Skip to content

Commit

Permalink
04.07.2022
Browse files Browse the repository at this point in the history
  • Loading branch information
ArKaNeMaN committed Jul 3, 2022
1 parent 8739cde commit 7d00e07
Show file tree
Hide file tree
Showing 18 changed files with 155 additions and 72 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@
- _\[Core\]_ Нормальный кфг для модулей (`Modules.json`). Возможно отдельным плагином, перехватывая в форваде активацию модуля
- _\[Limits\]_ Переключатель. Ограничение для игроков, перключаемое игроками через команду.
- _\[Limits & Params\]_ Добавить сток для вызова проверок из параметров.
- Возможно пригодится что-то типа контроллера сообщений с опциональным использованием ланг-фраз и всего такого.
- _\[Items\]_ Добавить предмет типа "Здоровье" и "Броня".
- Только хз зачем тогда будет нужен `SpawnHealth`)
5 changes: 5 additions & 0 deletions amxmodx/configs/plugins/VipModular/Cmds/WeaponMenu.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
"say_team /vipmenu"
],

"vipmenu_silent": [
"vm_silent",
"vipmenu_silent"
],

"vipmenu_autoopen": [
"vm_autoopen",
"say /vm_autoopen",
Expand Down
4 changes: 4 additions & 0 deletions amxmodx/configs/plugins/VipModular/Limits/MinRound-2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{ // Из-за частого использования, в целях некоторой оптимизации ограничение вынесено в отдельный файл
"Limit": "Round",
"Min": 2
}
24 changes: 9 additions & 15 deletions amxmodx/configs/plugins/VipModular/WeaponMenus/Menus/Test1.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
// "MinRound": 1,

/* Проверки перед открытием меню */
"Limits": [
{
"Limit": "Round",
"Min": 1
}
],
// "Limits": [
// { // Эта проверка тут избыточна, т.к. будет срабатывать всегда, потому что не будет быть раунда раньше первого :)
// "Limit": "Round",
// "Min": 1
// }
// ],

/* Список пунктов меню */
"Items": [
Expand All @@ -22,10 +22,7 @@
"Title": "Калаш [рануд 2]",
/* Проверки перед выдачей предметов */
"Limits": [
{
"Limit": "Round",
"Min": 2
}
"File:Limits/MinRound-2"
],

/* Предмет, выдаваемый при выборе этого пункта */
Expand All @@ -36,11 +33,8 @@
"Title": "АВП",
/* Проверки перед выдачей предметов */
"Limits": [
{
"Limit": "Round",
"Min": 2
},
{
"File:Limits/MinRound-2",
{ // Доступно только по субботам
"Limit": "WeekDay",
"Day": "Сб"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@

// "MinRound": 2,
"Limits": [
{
"Limit": "Round",
"Min": 2
}
"File:Limits/MinRound-2"
],

"Items": [
/* Обычный пункт с предметами */
{
"Title": "Активный пункт",
"Item": "File:Items/TestAk"

// "Limits": [ // Эта проверка тут избыточна, т.к. выше меню уже ограничено вторым раундом
// "File:Limits/MinRound-2"
// ]
},

/* Пустая строка */
Expand Down
16 changes: 9 additions & 7 deletions amxmodx/configs/plugins/VipModular/WeaponMenus/Test.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@

/* Проверки перед открытием списка меню */
"Limits": [
{
"Limit": "Round",
"Min": 2
}
"File:Limits/MinRound-2"
],

/* Проверки перед автооткрытием меню в начале раунда */
"AutoopenLimits": [
{ /* Автоматически открывать меню, если у игрока НЕТ основного оружия */
"Limit": "Logic-NOT",
"Limits": { "Limit": "HasPrimaryWeapon" }
// { /* Автоматически открывать меню, если у игрока НЕТ основного оружия */
// "Limit": "Logic-NOT",
// "Limits":
// }

{ // Для ограничения HasPrimaryWeapon добавлен параметр реверса (HasNot)
"Limit": "HasPrimaryWeapon",
"HasNot": true
}
],

Expand Down
8 changes: 4 additions & 4 deletions amxmodx/scripting/VipM-L-Logic.sma
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ public VipM_OnInitModules(){
}

@OnOrCheck(const Trie:Params, const UserId){
return VipM_Limits_ExecuteList(VipM_Params_GetArr(Params, "Limits"), UserId, Limit_Exec_OR);
return VipM_Params_ExecuteLimitsList(Params, "Limits", UserId, Limit_Exec_OR);
}

@OnXorCheck(const Trie:Params, const UserId){
return VipM_Limits_ExecuteList(VipM_Params_GetArr(Params, "Limits"), UserId, Limit_Exec_XOR);
return VipM_Params_ExecuteLimitsList(Params, "Limits", UserId, Limit_Exec_XOR);
}

@OnAndCheck(const Trie:Params, const UserId){
return VipM_Limits_ExecuteList(VipM_Params_GetArr(Params, "Limits"), UserId, Limit_Exec_AND);
return VipM_Params_ExecuteLimitsList(Params, "Limits", UserId, Limit_Exec_AND);
}

@OnNotCheck(const Trie:Params, const UserId){
return !VipM_Limits_ExecuteList(VipM_Params_GetArr(Params, "Limits"), UserId);
return !VipM_Params_ExecuteLimitsList(Params, "Limits", UserId, Limit_Exec_AND);
}
2 changes: 1 addition & 1 deletion amxmodx/scripting/VipM-M-SpawnHealth.sma
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public VipM_OnInitModules(){
}

Dbg_Log("@Event_PlayerSpawned(%d): Limits Count = %d", UserId, ArraySizeSafe(VipM_Params_GetCell(Params, "Limits", Invalid_Array)));
if (!VipM_Limits_ExecuteList(VipM_Params_GetCell(Params, "Limits", Invalid_Array), UserId)) {
if (!VipM_Params_ExecuteLimitsList(Params, "Limits", UserId, Limit_Exec_AND)) {
return;
}
Dbg_Log("@Event_PlayerSpawned(%d): Round №%d -> Passed", UserId, get_member_game(m_iTotalRoundsPlayed) + 1);
Expand Down
2 changes: 1 addition & 1 deletion amxmodx/scripting/VipM-M-SpawnItems.sma
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public VipM_OnInitModules(){
return;
}

if (!VipM_Limits_ExecuteList(VipM_Params_GetCell(Params, "Limits", Invalid_Array), UserId)) {
if (!VipM_Params_ExecuteLimitsList(Params, "Limits", UserId, Limit_Exec_AND)) {
return;
}

Expand Down
56 changes: 43 additions & 13 deletions amxmodx/scripting/VipM-M-WeaponMenu.sma
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public stock const PluginDescription[] = "Vip modular`s module - Weapon Menu";

new const MODULE_NAME[] = "WeaponMenu";

new const CMD_WEAPON_MENU_OPEN[] = "vipmenu";
new const CMD_WEAPON_MENU[] = "vipmenu";
new const CMD_WEAPON_MENU_SILENT[] = "vipmenu_silent";
new const CMD_SWITCH_AUTOOPEN[] = "vipmenu_autoopen";

#include "VipM/ArrayTrieUtils"
Expand All @@ -21,6 +22,7 @@ new const CMD_SWITCH_AUTOOPEN[] = "vipmenu_autoopen";

new gUserLeftItems[MAX_PLAYERS + 1] = {0, ...};
new bool:gUserAutoOpen[MAX_PLAYERS + 1] = {true, ...};
new bool:gUserExecutedAutoOpen[MAX_PLAYERS + 1] = {false, ...};

#include "VipM/WeaponMenu/Structs"
#include "VipM/WeaponMenu/Configs"
Expand Down Expand Up @@ -65,7 +67,8 @@ public VipM_OnInitModules() {
RegisterHookChain(RG_CBasePlayer_Spawn, "@OnPlayerSpawn", true);

CommandAliases_Open(GET_FILE_JSON_PATH("Cmds/WeaponMenu"), true);
CommandAliases_RegisterClient(CMD_WEAPON_MENU_OPEN, "@Cmd_OpenMenu");
CommandAliases_RegisterClient(CMD_WEAPON_MENU, "@Cmd_Menu");
CommandAliases_RegisterClient(CMD_WEAPON_MENU_SILENT, "@Cmd_MenuSilent");
CommandAliases_RegisterClient(CMD_SWITCH_AUTOOPEN, "@Cmd_SwitchAutoOpen");
CommandAliases_Close();
}
Expand All @@ -86,46 +89,64 @@ public VipM_OnInitModules() {
return;
}

if (!VipM_Limits_ExecuteList(VipM_Params_GetCell(Params, "AutoopenLimits", Invalid_Array), UserId)) {
if (!VipM_Params_ExecuteLimitsList(Params, "AutoopenLimits", UserId, Limit_Exec_AND)) {
return;
}

CommandAliases_ClientCmd(UserId, CMD_WEAPON_MENU_OPEN);
gUserExecutedAutoOpen[UserId] = true;
CommandAliases_ClientCmd(UserId, CMD_WEAPON_MENU);
}

@Cmd_SwitchAutoOpen(const UserId) {
gUserAutoOpen[UserId] = !gUserAutoOpen[UserId];
ChatPrintL(UserId, gUserAutoOpen[UserId] ? "MSG_AUTOOPEN_TURNED_ON" : "MSG_AUTOOPEN_TURNED_OFF");
}

@Cmd_OpenMenu(const UserId) {
@Cmd_Menu(const UserId) {
_Cmd_Menu(UserId);
}

@Cmd_MenuSilent(const UserId) {
_Cmd_Menu(UserId, true);
}

_Cmd_Menu(const UserId, const bool:bSilent = false) {
if (!IsUserValid(UserId)) {
return;
}

if (!is_user_alive(UserId)) {
ChatPrintL(UserId, "MSG_YOU_DEAD");
if (!bSilent) {
ChatPrintL(UserId, "MSG_YOU_DEAD");
}

return;
}

new Trie:Params = VipM_Modules_GetParams(MODULE_NAME, UserId);
new Array:aMenus = VipM_Params_GetArr(Params, "Menus");

if (ArraySizeSafe(aMenus) < 1) {
ChatPrintL(UserId, "MSG_NO_ACCESS");
if (!bSilent) {
ChatPrintL(UserId, "MSG_NO_ACCESS");
}

return;
}

if (!VipM_Limits_ExecuteList(VipM_Params_GetCell(Params, "Limits", Invalid_Array), UserId)) {
ChatPrintL(UserId, "MSG_MAIN_NOT_PASSED_LIMIT");
if (!VipM_Params_ExecuteLimitsList(Params, "Limits", UserId, Limit_Exec_AND)) {
if (!bSilent) {
ChatPrintL(UserId, "MSG_MAIN_NOT_PASSED_LIMIT");
}

return;
}

CMD_INIT_PARAMS();

if (CMD_ARG_NUM() < 1) {
if (ArraySizeSafe(aMenus) == 1) {
CommandAliases_ClientCmd(UserId, CMD_WEAPON_MENU_OPEN, "0");
CommandAliases_ClientCmd(UserId, CMD_WEAPON_MENU, "0");
} else {
static MainMenuTitle[128];
VipM_Params_GetStr(Params, "MainMenuTitle", MainMenuTitle, charsmax(MainMenuTitle));
Expand All @@ -146,7 +167,10 @@ public VipM_OnInitModules() {
ArrayGetArray(aMenus, MenuId, Menu);

if (!VipM_Limits_ExecuteList(Menu[WeaponMenu_Limits], UserId)) {
ChatPrintL(UserId, "MSG_MENU_NOT_PASSED_LIMIT");
if (!bSilent) {
ChatPrintL(UserId, "MSG_MENU_NOT_PASSED_LIMIT");
}

return;
}

Expand All @@ -167,12 +191,18 @@ public VipM_OnInitModules() {
ArrayGetArray(Menu[WeaponMenu_Items], ItemId, MenuItem);

if (gUserLeftItems[UserId] < 1) {
ChatPrintL(UserId, "MSG_NO_LEFT_ITEMS");
if (!bSilent) {
ChatPrintL(UserId, "MSG_NO_LEFT_ITEMS");
}

return;
}

if (!VipM_Limits_ExecuteList(MenuItem[MenuItem_Limits], UserId)) {
ChatPrintL(UserId, "MSG_MENUITEM_NOT_PASSED_LIMIT");
if (!bSilent) {
ChatPrintL(UserId, "MSG_MENUITEM_NOT_PASSED_LIMIT");
}

return;
}

Expand Down
11 changes: 8 additions & 3 deletions amxmodx/scripting/VipM/CommandAliases.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,33 @@ enum _:{
static JSON:jFile = Invalid_JSON;
static Trie:g_tMainCmd = Invalid_Trie;

stock CommandAliases_Open(const sFilePath[], const bool:bCreateIfNotExists = false) {
stock bool:CommandAliases_Open(const sFilePath[], const bool:bCreateIfNotExists = false) {
jFile = Invalid_JSON;

if (!file_exists(sFilePath)) {
if (bCreateIfNotExists) {
new JSON:jObj = json_init_object();
json_serial_to_file(jObj, sFilePath, true);
json_free(jObj);
} else {
return false;
}
return;
}

jFile = json_parse(sFilePath, true, true);

if (jFile == Invalid_JSON) {
log_amx("[CommandAliases][Warn] Can't read from file: %s", sFilePath);
return false;
}

if (!json_is_object(jFile)) {
jFile = Invalid_JSON;
log_amx("[CommandAliases][Warn] Invalid file format: %s", sFilePath);
return false;
}

return true;
}

stock CommandAliases_Close() {
Expand All @@ -68,6 +73,7 @@ static stock Array:ReadCommandsByKey(const sCmdKey[]) {
new JSON:jCmds = json_object_get_value(jFile, sCmdKey);
if (!json_is_array(jCmds)) {
log_amx("[CommandAliases][Warn] Invalid file format. Commands list must be an array.");
return aCmds;
}

aCmds = ArrayCreate(COMMAND_ALIASES_COMMAND_MAX_LENGTH, json_array_get_count(jCmds));
Expand Down Expand Up @@ -150,4 +156,3 @@ stock bool:CommandAliases_ClientCmd(const UserId, const sCmdKey[], const sArgsFm
}
}
}

2 changes: 1 addition & 1 deletion amxmodx/scripting/VipM/Core/Natives.inc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Array:Native_GetParamsList(const NullArg, const ParamsCount, Array:aParams = Inv
Param[CfgParam_Type] = E_ParamType:get_param_byref(i+1);
Param[CfgParam_Required] = bool:get_param_byref(i+2);

Dbg_PrintServer("^t- %s: %d, %s", Param[CfgParam_Name], _:Param[CfgParam_Type], Param[CfgParam_Required] ? "+" : "-");
// Dbg_PrintServer("^t- %s: %d, %s", Param[CfgParam_Name], _:Param[CfgParam_Type], Param[CfgParam_Required] ? "+" : "-");

ArrayPushArray(aParams, Param);
}
Expand Down
4 changes: 2 additions & 2 deletions amxmodx/scripting/VipM/Core/Natives/Modules.inc
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ Natives_Modules_Init(){
GET_MODULE(ModuleName, Module);
new bool:bSave = (Module[Module_Params] == Invalid_Array);

Dbg_PrintServer("Module_AddParams(%s): bSave = %s", ModuleName, bSave ? "+" : "-");
// Dbg_PrintServer("Module_AddParams(%s): bSave = %s", ModuleName, bSave ? "+" : "-");

Module[Module_Params] = Native_GetParamsList(Arg_Params - 1, ParamsCount, Module[Module_Params]);

Dbg_PrintServer(":---");
// Dbg_PrintServer(":---");

if (bSave) {
SET_MODULE(Module);
Expand Down
Loading

0 comments on commit 7d00e07

Please sign in to comment.