Have you ever been annoyed like I have at the fact that when you are adding items to a menu, you can't format what is displayed?
What I mean by this is when you do something like:
PHP Code:
menu.AddItem("example", "Name: Client's name");
You can't actually format the second string. This fixes that problem!
I present to you...
Menu.AddItemFormat!
PHP Code:
// Appends a new item to the end of a menu.
//
// @param info Item information string.
// @param display Default item display string.
// @param style Drawing style flags. Anything other than DEFAULT or
// DISABLED will be completely ignored when paginating.
// @param ... Formatting parameters for the display string.
// @return True on success, false on failure.
// @error Item limit reached.
public bool AddItemFormat(const char[] info, const char[] display, int style=ITEMDRAW_DEFAULT, any ...)
{
int length = strlen(display) + 255;
char[] buffer = new char[length];
VFormat(buffer, length, display, 5);
return this.AddItem(info, buffer, style);
}
Simply just add this code into the methodmap portion for menus in the menus.inc include file!
Here is an example of this being used in a plugin:
PHP Code:
#include <sourcemod>
public void OnPluginStart()
{
RegConsoleCmd("sm_menutest", Command_Callback);
}
public Action Command_Callback(int client, int args)
{
Menu menu = new Menu(Menu_Handler);
menu.SetTitle("Menu Format Test");
menu.AddItemFormat("test", "Hey guys, my name is %N!", _, client);
menu.Display(client, MENU_TIME_FOREVER);
return Plugin_Handled;
}
public int Menu_Handler(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_End)
delete menu;
return 0;
}
Enjoy!
EDIT: I just noticed that this function pretty much exists with this include
https://forums.alliedmods.net/showthread.php?t=265325
Use this version if you prefer using methodmaps.