AlliedModders Donor
Join Date: May 2017
Location: Poland
|
05-08-2019
, 00:38
Re: Getting first value of the menu function and take points.
|
#3
|
Quote:
Originally Posted by Powerlord
If you ever plan on changing the point values on this menu, you may want to add MenuAction_DrawItem to the actions list and then use that action in your menu handler to check the items. Something like this:
PHP Code:
//When you create the menu Menu next = new Menu(PointAct_MenuHandler, MENU_ACTIONS_DEFAULT|MenuAction_DrawItem);
// In your menu handler switch (action) { // code to retrieve the client here
case MenuAction_Select: { // Your other existing menu code here }
case MenuAction_End: { delete menu; }
// param1 is the admin calling the menu, param2 is the menu item // If you changed these variable names in your handler declaration, change them here too case MenuAction_DrawItem: { char item[9]; int style; menu.GetItem(param2, item, sizeof(item), style);
if (StrEqual(item, "-SELECT-") || StrEqual(item, "-CLIENT-")) return style;
int itemValue = StringToInt(item); if (g_iPoints[client] < itemValue) style = ITEMDRAW_DISABLED;
return style; }
return 0; }
|
Thank you for fast reply, your code doesn`t really work for me, but i never createdmenu in sourcepawn like you in my life im still going to study that method.
My whole code for this is down below, i actually tried to rewrite for your method, but i got lots of errors, so i just keeped it my way.
PHP Code:
#define LoopItemCount(%1) for(int %1 = 0; %1 < menu.ItemCount; %1++)
public Action CreateMenu_AddRemovePoints(int admin, int client, int iSelect) { Menu next = new Menu(PointAct_MenuHandler); char frm[128]; char pname[MAX_NAME_LENGTH + 1]; GetClientName(client, pname, sizeof pname); Format(frm, sizeof frm, "Ranks - %s", pname); next.SetTitle(frm); next.AddItem("1", "1 points"); next.AddItem("5", "5 points"); next.AddItem("10", "10 points"); next.AddItem("20", "20 points"); next.AddItem("50", "50 points"); next.AddItem("1000", "1000 points"); next.AddItem("2500", "2500 points"); next.AddItem("5000", "5000 points"); char sInfo[12];
Format(sInfo, sizeof(sInfo), "%d", iSelect); next.AddItem("-SELECT-", sInfo, ITEMDRAW_IGNORE); Format(sInfo, sizeof(sInfo), "%d", client); next.AddItem("-CLIENT-", sInfo, ITEMDRAW_IGNORE); next.ExitButton = true; next.Display(admin, 60); }
public int PointAct_MenuHandler(Menu menu, MenuAction action, int param1, int param2) { char sInfo[12], sDane[12]; int iSelect, client; LoopItemCount(i) { menu.GetItem(i, sInfo, sizeof(sInfo), _, sDane, sizeof(sDane));
if (StrEqual(sInfo, "-SELECT-")) iSelect = StringToInt(sDane); if (StrEqual(sInfo, "-CLIENT-")) client = StringToInt(sDane); } if (action == MenuAction_Select) { char item[32]; menu.GetItem(param2, item, sizeof(item)); if (IsValidClient(client)) { if (iSelect == 1) g_iPoints[client] +=StringToInt(item); else if (iSelect == 2) if(g_iPoints[client] < StringToInt(item)) { CPrintToChat(client, "{darkred}[✖] {yellow}You can't choose this option because player will get points < 0", g_iPoints[client]); } else { g_iPoints[client] -= StringToInt(item); } CreateMenu_AddRemovePoints(param1, client, iSelect); CheckRank(client); } } else if (action == MenuAction_End) delete menu; }
Last edited by Mesharsky How2Kill; 06-17-2019 at 20:37.
|
|