Finished weapon restriction menu. Still needs validations and default restrictions.

This commit is contained in:
Greyscale 2009-04-13 23:55:02 +02:00
parent 34d357a2c3
commit 55ddce0734
3 changed files with 352 additions and 159 deletions

View File

@ -157,42 +157,7 @@ public Action:Command_Restrict(client, argc)
decl String:display[WEAPONS_MAX_LENGTH];
new WpnRestrictQuery:output = RestrictRestrict(arg1, display);
switch(output)
{
case Successful_Weapon:
{
ZR_PrintToChat(0, "Restrict weapon", display);
}
case Successful_Group:
{
decl String:weaponlist[128];
RestrictGetGroupWeapons(display, weaponlist, sizeof(weaponlist), ", ");
ZR_PrintToChat(0, "Restrict custom weapon group", display, weaponlist);
}
case Failed_Weapon:
{
ZR_ReplyToCommand(client, "Restrict weapon failed", display);
return Plugin_Handled;
}
case Failed_Group:
{
decl String:weaponlist[128];
RestrictGetGroupWeapons(display, weaponlist, sizeof(weaponlist), ", ");
ZR_ReplyToCommand(client, "Restrict custom weapon group failed", display, weaponlist);
return Plugin_Handled;
}
case Invalid:
{
ZR_ReplyToCommand(client, "Weapon invalid", display);
return Plugin_Handled;
}
}
RestrictPrintRestrictOutput(client, output, display, true);
if (LogFlagCheck(LOG_GAME_EVENTS, LOG_MODULE_COMMANDS))
{
@ -231,33 +196,7 @@ public Action:Command_Unrestrict(client, argc)
decl String:display[WEAPONS_MAX_LENGTH];
new WpnRestrictQuery:output = RestrictUnrestrict(arg1, display);
switch(output)
{
case Successful_Weapon:
{
ZR_PrintToChat(0, "Unrestrict weapon", display);
}
case Successful_Group:
{
decl String:weaponlist[128];
RestrictGetGroupWeapons(display, weaponlist, sizeof(weaponlist), ", ");
ZR_PrintToChat(0, "Unrestrict custom weapon group", display, weaponlist);
}
case Failed_Weapon:
{
ZR_ReplyToCommand(client, "Unrestrict weapon failed", display);
return Plugin_Handled;
}
case Invalid:
{
ZR_ReplyToCommand(client, "Weapon invalid", display);
return Plugin_Handled;
}
}
RestrictPrintUnrestrictOutput(client, output, display, true);
if (LogFlagCheck(LOG_GAME_EVENTS, LOG_MODULE_COMMANDS))
{

View File

@ -20,6 +20,11 @@ enum WeaponsMenu
*/
new WeaponsMenu:curMenuWeapons[MAXPLAYERS + 1];
/**
* Array to store the client's current weapon group menu
*/
new String:curMenuGroup[WEAPONS_MAX_LENGTH][MAXPLAYERS + 1];
/**
* Sends main weapon menu to client.
* @param client The client index.
@ -43,7 +48,7 @@ WeaponsMenuMain(client)
Format(zmarket, sizeof(zmarket), "%t", "Weapons menu main market");
AddMenuItem(menu_weapons_main, "toggleweaponrestriction", toggleweaponrestriction);
AddMenuItem(menu_weapons_main, "togglewgrouprestriction", togglewgrouprestriction, ITEMDRAW_DISABLED);
AddMenuItem(menu_weapons_main, "togglewgrouprestriction", togglewgrouprestriction);
// Disable market option if market isn't installed
if (market)
@ -86,7 +91,7 @@ public WeaponsMenuMainHandle(Handle:menu_weapons_main, MenuAction:action, client
}
case 2:
{
// WeaponsMenuMarket(client);
//WeaponsMenuMarket(client);
}
}
}
@ -177,10 +182,14 @@ WeaponsMenuWeapons(client, WeaponsMenu:type)
strcopy(display, sizeof(display), weapongroup);
if (RestrictIsGroupRestricted(weapongroup))
if (RestrictIsPartialRestricted(weapongroup))
{
Format(display, sizeof(display), "%s*", weapongroup);
}
else if (RestrictIsGroupRestricted(weapongroup))
{
Format(display, sizeof(display), "%s**", weapongroup);
}
AddMenuItem(menu_weapons_weapons, weapongroup, display);
}
@ -189,6 +198,7 @@ WeaponsMenuWeapons(client, WeaponsMenu:type)
CloseHandle(arrayWeaponGroups);
}
}
SetMenuExitBackButton(menu_weapons_weapons, true);
DisplayMenu(menu_weapons_weapons, client, MENU_TIME_FOREVER);
@ -209,87 +219,34 @@ public WeaponsMenuWeaponsHandle(Handle:menu_weapons_weapons, MenuAction:action,
decl String:weapon[WEAPONS_MAX_LENGTH];
GetMenuItem(menu_weapons_weapons, slot, weapon, sizeof(weapon));
new WpnRestrictQuery:output;
// Set restrict to true if were restricting a weapon/group, false if not
new bool:restrict;
if (RestrictIsWeaponGroup(weapon))
switch(curMenuWeapons[client])
{
restrict = RestrictIsGroupRestricted(weapon);
}
else
{
restrict = RestrictIsWeaponRestricted(weapon);
}
if (!restrict)
{
decl String:display[WEAPONS_MAX_LENGTH];
output = RestrictRestrict(weapon, display);
switch(output)
// Client is restricting a single weapon
case Weapon:
{
case Successful_Weapon:
new WpnRestrictQuery:output;
if (!RestrictIsWeaponRestricted(weapon))
{
ZR_PrintToChat(0, "Restrict weapon", weapon);
output = RestrictRestrict(weapon);
RestrictPrintRestrictOutput(client, output, weapon, false);
}
case Successful_Group:
else
{
decl String:weaponlist[128];
RestrictGetGroupWeapons(weapon, weaponlist, sizeof(weaponlist), ", ");
ZR_PrintToChat(0, "Restrict custom weapon group", weapon, weaponlist);
}
case Failed_Weapon:
{
ZR_PrintToChat(client, "Restrict weapon failed", weapon);
}
case Failed_Group:
{
decl String:weaponlist[128];
RestrictGetGroupWeapons(weapon, weaponlist, sizeof(weaponlist), ", ");
ZR_PrintToChat(client, "Restrict custom weapon group failed", weapon, weaponlist);
}
case Invalid:
{
ZR_PrintToChat(client, "Weapon invalid", weapon);
output = RestrictUnrestrict(weapon);
RestrictPrintUnrestrictOutput(client, output, weapon, false);
}
// Resend menu
WeaponsMenuWeapons(client, curMenuWeapons[client]);
}
// Client is accessing a weapon group
case WeaponGroup:
{
// Send weapon group menu
WeaponsMenuWeaponGroup(client, weapon);
}
}
else
{
decl String:display[WEAPONS_MAX_LENGTH];
output = RestrictUnrestrict(weapon, display);
switch(output)
{
case Successful_Weapon:
{
ZR_PrintToChat(0, "Unrestrict weapon", weapon);
}
case Successful_Group:
{
decl String:weaponlist[128];
RestrictGetGroupWeapons(weapon, weaponlist, sizeof(weaponlist), ", ");
ZR_PrintToChat(0, "Unrestrict custom weapon group", weapon, weaponlist);
}
case Failed_Weapon:
{
ZR_PrintToChat(client, "Unrestrict weapon failed", weapon);
}
case Invalid:
{
ZR_PrintToChat(client, "Weapon invalid", weapon);
}
}
}
// Resend menu
WeaponsMenuWeapons(client, curMenuWeapons[client]);
}
// Client closed the menu
if (action == MenuAction_Cancel)
@ -305,4 +262,129 @@ public WeaponsMenuWeaponsHandle(Handle:menu_weapons_weapons, MenuAction:action,
{
CloseHandle(menu_weapons_weapons);
}
}
WeaponsMenuWeaponGroup(client, const String:weapongroup[])
{
strcopy(curMenuGroup[client], WEAPONS_MAX_LENGTH, weapongroup);
// Create menu handle
new Handle:menu_weapons_groupweapon = CreateMenu(WeaponsMenuWeaponGroupHandle);
SetMenuTitle(menu_weapons_groupweapon, "%t\n ", "Weapons menu weapon group title", weapongroup);
decl String:restrictall[64];
decl String:unrestrictall[64];
Format(restrictall, sizeof(restrictall), "%t", "Weapons menu weapon group restrict all");
Format(unrestrictall, sizeof(unrestrictall), "%t", "Weapons menu weapon group unrestrict all");
if (RestrictIsGroupRestricted(weapongroup))
{
AddMenuItem(menu_weapons_groupweapon, "restrictall", restrictall, ITEMDRAW_DISABLED);
}
else
{
AddMenuItem(menu_weapons_groupweapon, "restrictall", restrictall);
}
if (RestrictIsGroupUnrestricted(weapongroup))
{
AddMenuItem(menu_weapons_groupweapon, "unrestrictall", unrestrictall, ITEMDRAW_DISABLED);
}
else
{
AddMenuItem(menu_weapons_groupweapon, "unrestrictall", unrestrictall);
}
decl String:groupweapon[WEAPONS_MAX_LENGTH];
decl String:display[WEAPONS_MAX_LENGTH + 1];
new Handle:arrayGroupWeapons = INVALID_HANDLE;
new size = RestrictCreateGroupWeaponsArray(arrayGroupWeapons, weapongroup);
// x = Array index
for (new x = 0; x < size; x++)
{
GetArrayString(arrayGroupWeapons, x, groupweapon, sizeof(groupweapon));
strcopy(display, sizeof(display), groupweapon);
if (RestrictIsWeaponRestricted(groupweapon))
{
Format(display, sizeof(display), "%s*", groupweapon);
}
AddMenuItem(menu_weapons_groupweapon, groupweapon, display);
}
// Kill the array handle
CloseHandle(arrayGroupWeapons);
SetMenuExitBackButton(menu_weapons_groupweapon, true);
DisplayMenu(menu_weapons_groupweapon, client, MENU_TIME_FOREVER);
}
/**
* Called when client selects option in the weapon group menu, and handles it.
* @param menu_weapons_main Handle of the menu being used.
* @param action The action done on the menu (see menus.inc, enum MenuAction).
* @param client The client index.
* @param slot The slot index selected (starting from 0).
*/
public WeaponsMenuWeaponGroupHandle(Handle:menu_weapons_groupweapon, MenuAction:action, client, slot)
{
// Client selected an option
if (action == MenuAction_Select)
{
switch(slot)
{
case 0:
{
new WpnRestrictQuery:output = RestrictRestrict(curMenuGroup[client]);
RestrictPrintRestrictOutput(client, output, curMenuGroup[client], false);
}
case 1:
{
new WpnRestrictQuery:output = RestrictUnrestrict(curMenuGroup[client]);
RestrictPrintUnrestrictOutput(client, output, curMenuGroup[client], false);
}
default:
{
new WpnRestrictQuery:output;
decl String:groupweapon[WEAPONS_MAX_LENGTH];
GetMenuItem(menu_weapons_groupweapon, slot, groupweapon, sizeof(groupweapon));
if (!RestrictIsWeaponRestricted(groupweapon))
{
output = RestrictRestrict(groupweapon);
RestrictPrintRestrictOutput(client, output, groupweapon, false);
}
else
{
output = RestrictUnrestrict(groupweapon);
RestrictPrintUnrestrictOutput(client, output, groupweapon, false);
}
}
}
// Resend menu
WeaponsMenuWeaponGroup(client, curMenuGroup[client]);
}
// Client closed the menu
if (action == MenuAction_Cancel)
{
// Client hit "Back" button
if (slot == MenuCancel_ExitBack)
{
WeaponsMenuWeapons(client, curMenuWeapons[client]);
}
}
// Client hit "Exit" button
else if (action == MenuAction_End)
{
CloseHandle(menu_weapons_groupweapon);
}
}

View File

@ -184,7 +184,7 @@ public Action:RestrictBuyHook(client, argc)
* Failed_Group: The call failed to restrict a weapon group.
* Invalid: The call was unsuccessful due to invalid weapon.
*/
WpnRestrictQuery:RestrictRestrict(const String:weapon[], String:display[])
WpnRestrictQuery:RestrictRestrict(const String:weapon[], String:display[] = "")
{
if (RestrictIsWeaponGroup(weapon))
{
@ -249,10 +249,15 @@ WpnRestrictQuery:RestrictRestrict(const String:weapon[], String:display[])
* Failed_Group: The call failed to restrict a weapon group.
* Invalid: The call was unsuccessful due to invalid weapon.
*/
WpnRestrictQuery:RestrictUnrestrict(const String:weapon[], String:display[])
WpnRestrictQuery:RestrictUnrestrict(const String:weapon[], String:display[] = "")
{
if (RestrictIsWeaponGroup(weapon))
{
if (RestrictIsGroupUnrestricted(weapon))
{
return Failed_Group;
}
KvRewind(kvWeaponGroups);
KvJumpToKey(kvWeaponGroups, weapon);
@ -307,6 +312,128 @@ WpnRestrictQuery:RestrictUnrestrict(const String:weapon[], String:display[])
return Successful_Weapon;
}
/**
* Prints text to server or client based off the output it RestrictRestrict().
* @param client The client index.
* @param output The output of RestrictRestrict().
* @param weapon The weapon client is trying to restrict.
* @param cmd True if printing output in reply to a client command.
*/
RestrictPrintRestrictOutput(client, WpnRestrictQuery:output, const String:weapon[], bool:cmd)
{
switch(output)
{
case Successful_Weapon:
{
ZR_PrintToChat(0, "Restrict weapon", weapon);
}
case Successful_Group:
{
decl String:weaponlist[128];
RestrictGetGroupWeapons(weapon, weaponlist, sizeof(weaponlist), ", ");
ZR_PrintToChat(0, "Restrict custom weapon group", weapon, weaponlist);
}
case Failed_Weapon:
{
if (cmd)
{
ZR_ReplyToCommand(client, "Restrict weapon failed", weapon);
}
else
{
ZR_PrintToChat(client, "Restrict weapon failed", weapon);
}
}
case Failed_Group:
{
decl String:weaponlist[128];
RestrictGetGroupWeapons(weapon, weaponlist, sizeof(weaponlist), ", ");
if (cmd)
{
ZR_ReplyToCommand(client, "Restrict custom weapon group failed", weapon, weaponlist);
}
else
{
ZR_PrintToChat(client, "Restrict custom weapon group failed", weapon, weaponlist);
}
}
case Invalid:
{
if (cmd)
{
ZR_ReplyToCommand(client, "Weapon invalid", weapon);
}
else
{
ZR_PrintToChat(client, "Weapon invalid", weapon);
}
}
}
}
/**
* Prints text to server or client based off the output it RestrictUnrestrict().
* @param client The client index.
* @param output The output of RestrictUnrestrict().
* @param weapon The weapon client is trying to unrestrict.
* @param cmd True if printing output in reply to a client command.
*/
RestrictPrintUnrestrictOutput(client, WpnRestrictQuery:output, const String:weapon[], bool:cmd)
{
switch(output)
{
case Successful_Weapon:
{
ZR_PrintToChat(0, "Unrestrict weapon", weapon);
}
case Successful_Group:
{
decl String:weaponlist[128];
RestrictGetGroupWeapons(weapon, weaponlist, sizeof(weaponlist), ", ");
ZR_PrintToChat(0, "Unrestrict custom weapon group", weapon, weaponlist);
}
case Failed_Weapon:
{
if (cmd)
{
ZR_ReplyToCommand(client, "Unrestrict weapon failed", weapon);
}
else
{
ZR_PrintToChat(client, "Unrestrict weapon failed", weapon);
}
}
case Failed_Group:
{
decl String:weaponlist[128];
RestrictGetGroupWeapons(weapon, weaponlist, sizeof(weaponlist), ", ");
if (cmd)
{
ZR_ReplyToCommand(client, "Unrestrict custom weapon group failed", weapon, weaponlist);
}
else
{
ZR_PrintToChat(client, "Unrestrict custom weapon group failed", weapon, weaponlist);
}
}
case Invalid:
{
if (cmd)
{
ZR_ReplyToCommand(client, "Weapon invalid", weapon);
}
else
{
ZR_PrintToChat(client, "Weapon invalid", weapon);
}
}
}
}
/**
* Checks if a weapon is restricted.
*
@ -341,17 +468,21 @@ bool:RestrictIsGroupRestricted(const String:weapongroup[])
{
decl String:groupweapon[WEAPONS_MAX_LENGTH];
do
if (KvGotoFirstSubKey(kvWeaponGroups))
{
KvGetSectionName(kvWeaponGroups, groupweapon, WEAPONS_MAX_LENGTH);
if (!RestrictIsWeaponRestricted(groupweapon))
do
{
return false;
}
} while (KvGotoNextKey(kvWeaponGroups));
return true;
KvGetSectionName(kvWeaponGroups, groupweapon, WEAPONS_MAX_LENGTH);
// Return false is a weapon isn't restricted, but only if the weapon is valid (we ignore invalid ones)
if (WeaponsIsValidWeapon(groupweapon) && !RestrictIsWeaponRestricted(groupweapon))
{
return false;
}
} while (KvGotoNextKey(kvWeaponGroups));
return true;
}
}
return false;
@ -369,17 +500,21 @@ bool:RestrictIsGroupUnrestricted(const String:weapongroup[])
{
decl String:groupweapon[WEAPONS_MAX_LENGTH];
do
if (KvGotoFirstSubKey(kvWeaponGroups))
{
KvGetSectionName(kvWeaponGroups, groupweapon, WEAPONS_MAX_LENGTH);
if (RestrictIsWeaponRestricted(groupweapon))
do
{
return false;
}
} while (KvGotoNextKey(kvWeaponGroups));
return true;
KvGetSectionName(kvWeaponGroups, groupweapon, WEAPONS_MAX_LENGTH);
// Return false if a weapon is restricted
if (RestrictIsWeaponRestricted(groupweapon))
{
return false;
}
} while (KvGotoNextKey(kvWeaponGroups));
return true;
}
}
return false;
@ -460,6 +595,43 @@ RestrictCreateGroupArray(&Handle:arrayWeaponGroups, maxlen = WEAPONS_MAX_LENGTH)
return count;
}
/**
* Creates an array of all weapons listed in a custom weapon group.
* @param arrayWeaponGroups The handle of the array, don't forget to call CloseHandle
* on it when finished!
* @return The size of the array.
*/
RestrictCreateGroupWeaponsArray(&Handle:arrayGroupWeapons, const String:weapongroup[], maxlen = WEAPONS_MAX_LENGTH)
{
arrayGroupWeapons = CreateArray(maxlen);
new count = 0;
KvRewind(kvWeaponGroups);
if (KvJumpToKey(kvWeaponGroups, weapongroup))
{
decl String:groupweapon[maxlen];
if (KvGotoFirstSubKey(kvWeaponGroups))
{
do
{
KvGetSectionName(kvWeaponGroups, groupweapon, maxlen);
// If the weapon is invalid, then stop
if (!WeaponsIsValidWeapon(groupweapon))
{
continue;
}
PushArrayString(arrayGroupWeapons, groupweapon);
count++;
} while (KvGotoNextKey(kvWeaponGroups));
}
}
return count;
}
/**
* Returns a string of all weapons in a custom weapon group separated
* by the provided character.