View Single Post
Reiko1231
Member
Join Date: Apr 2013
Location: Russia
Old 01-26-2018 , 04:35   Re: Checking if a player hits "Next" and "Previous" in a menu
Reply With Quote #11

You can listen to menuselect with listener. This way you will know (at least for menus) when client pressed next or previous. Here is example code for cs:s. If you need it for cs:go, change +- in listener from 7 to 6 and arg == (8 and 9) to (7 and 8). If you write "sm_open_menu" in console you will see menu. You can move forward and back. Then you can write "sm_interrupt_menu" to interrupt this menu. If you type "sm_open_menu" again you will see interrupted menu on page you previously was. But if you close this menu via exit, typing this command again will always start from 1 page (so it restore page only on menu interrupts).
Hope this is what you wanted.

Code:
// ==============================================================================================================================
// >>> GLOBAL INCLUDES
// ==============================================================================================================================
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

// ==============================================================================================================================
// >>> DEFINES
// ==============================================================================================================================
#define MPS 		MAXPLAYERS+1
#define MTF 		MENU_TIME_FOREVER
#define SZF(%0) 	%0, sizeof(%0)

// ==============================================================================================================================
// >>> GLOBAL VARIABLES
// ==============================================================================================================================
new	Handle:	g_menu;
new	Handle:	g_interruptor;
new bool:	g_listen[MPS];
new 		g_menupos[MPS];

// ==============================================================================================================================
// >>> FORWARDS
// ==============================================================================================================================
public OnPluginStart() 
{
	RegConsoleCmd("sm_open_menu", Command_OpenMenu);
	RegConsoleCmd("sm_interrupt_menu", Command_InterruptMenu);
	AddCommandListener(Listener_MenuSelect, "menuselect");
	
	g_menu = CreateMenu(Handler_Menu);
	g_interruptor = CreateMenu(Handler_InterruptMenu);
	
	decl String:buffer[4];
	for ( new i = 1; i < 45; ++i ) {
		IntToString(i, SZF(buffer));
		AddMenuItem(g_menu, buffer, buffer);
	}
	
	AddMenuItem(g_interruptor, "", "interrupted!");
}

public OnClientPutInServer(client)
{
	g_listen[client] = false;
}

// ==============================================================================================================================
// >>> COMMANDS 
// ==============================================================================================================================
public Action:Command_OpenMenu(client, argc)
{
	g_listen[client] = true;
	DisplayMenuAtItem(g_menu, client, g_menupos[client], MTF);
	return Plugin_Handled;
}

public Action:Command_InterruptMenu(client, argc)
{
	DisplayMenu(g_interruptor, client, MTF);
	return Plugin_Handled;
}

public Action:Listener_MenuSelect(client, String:command[], argc)
{
	if ( g_listen[client] ) {
		decl String:arg[4];
		GetCmdArg(1, SZF(arg));
		
		if ( arg[0] == '8' ) {
			g_menupos[client] -= 7;
		}
		else if ( arg[0] == '9' ) {
			g_menupos[client] += 7;
		}
	}
	
	return Plugin_Continue;
}

// ==============================================================================================================================
// >>> HANDLERS 
// ==============================================================================================================================
public Handler_Menu(Handle:menu, MenuAction:action, client, slot)
{
	if ( action == MenuAction_Cancel ) {
		g_listen[client] = false;
		if ( slot != MenuCancel_Interrupted ) {
			g_menupos[client] = 0;
		}
	}
}

public Handler_InterruptMenu(Handle:menu, MenuAction:action, client, slot)
{
	
}
Reiko1231 is offline