Skip to content

Implement per-client randomized menus with MenuShufflePerClient native.#1073

Merged
KyleSanderson merged 5 commits intoalliedmodders:masterfrom
BotoX:feature-MenuShufflePerClient
Aug 7, 2020
Merged

Implement per-client randomized menus with MenuShufflePerClient native.#1073
KyleSanderson merged 5 commits intoalliedmodders:masterfrom
BotoX:feature-MenuShufflePerClient

Conversation

@BotoX
Copy link
Contributor

@BotoX BotoX commented Sep 2, 2019

BUMPS IMenuManager VERSION

Example:

#include <sourcemod>

public void OnPluginStart()
{
	RegConsoleCmd("menu_test1", Menu_Test1);
}

public int MenuHandler1(Menu menu, MenuAction action, int param1, int param2)
{
	/* If an option was selected, tell the client about the item. */
	if (action == MenuAction_Select)
	{
		char info[32];
		char disp[32];
		bool found = menu.GetItem(param2, info, sizeof(info), _, disp, sizeof(disp), param1);
		PrintToConsole(param1, "You selected item: %d (found? %d info: %s | disp: %s)", param2, found, info, disp);
	}
	/* If the menu was cancelled, print a message to the server about it. */
	else if (action == MenuAction_Cancel)
	{
		PrintToServer("Client %d's menu was cancelled.  Reason: %d", param1, param2);
	}
	/* If the menu has ended, destroy it */
	else if (action == MenuAction_End)
	{
		delete menu;
	}
}

public Action Menu_Test1(int client, int args)
{
	Menu menu = new Menu(MenuHandler1);
	menu.SetTitle("Do you like apples?");
	menu.AddItem("A0", "B0");
	menu.AddItem("A1", "B1");
	menu.AddItem("A2", "B2");
	menu.AddItem("A3", "B3");
	menu.AddItem("A4", "B4");
	menu.AddItem("A5", "B5");
	menu.AddItem("A6", "B6");
	menu.AddItem("A7", "B7");
	menu.AddItem("A8", "B8");
	menu.AddItem("A9", "B9");
	menu.AddItem("A10", "B10");
	menu.AddItem("A11", "B11");
	menu.AddItem("A12", "B12");
	menu.AddItem("A13", "B13");
	menu.AddItem("A14", "B14");
	menu.AddItem("A15", "B15");
	menu.ExitButton = false;
	menu.ShufflePerClient(1, 15);
	menu.Display(client, 20);

	return Plugin_Handled;
}

@kice
Copy link

kice commented Sep 4, 2019

Would you like to add a native that can change the position of choice for each client?

@BotoX
Copy link
Contributor Author

BotoX commented Sep 4, 2019

Yeah that could be added, what's your use case for that though?

You mean something like:

1
2
3
4

and then you do menu.SwapClient(client, 0, 2); and get:

3
2
1
4

@kice
Copy link

kice commented Sep 4, 2019

Since I would like to show different clients with different predetermined orders, and a swap will make thing a little bit complicated, a direct call to set all options or a callback like typedef OnSetMenuOptions = function void(int client, int pos[], int options) will make it easier.

// Assume we have menu has 6 options
Menu menu;
int choice[6];

GetChoiceForClient(client, choice, sizeof(choice)); // return: choice = {2, 1, 0, 4, 5, 3};
menu.SetOptionsPos(client, choice, sizeof(choice));

/*
Vote menu for client:
2
1
0
4
5
3
*/

@peace-maker
Copy link
Member

That extra native seems out of scope for this PR.
What's the use case for different predetermined menu item orders over just randomizing all items per client?

@kice
Copy link

kice commented Sep 5, 2019

@peace-maker
To your concern, you may want to recommend some choices on a per user basis or use predetermined order to manipulate the voting results since too many people just press first item on map voting.

@BotoX
Copy link
Contributor Author

BotoX commented Sep 5, 2019

User tailored menu option order sounds cool.
Can't mix it with the integrated random shuffling right now though. Like putting your own nomination on top but shuffling the rest.
But no problem to do this in the plugin.

Putting your favorite map to slot 1 should be done by inserting it first and not per client.

@kice
Copy link

kice commented Sep 6, 2019

In fact, the voting API should have more customizations, or move all the functionality to a SM plugin (like MapChooser) instead of a SM module; but I dont think it is worth it to open a PR for it since right now is more than enough for everyone.

And the part was just make up by me, if you just want to do so, I, however, will suggest only make part of the voters have it on the first place thus nobody will noticed it xD.

@BotoX
Copy link
Contributor Author

BotoX commented Sep 6, 2019

In my example A0 will be the first item for everyone, since I specified start to be 1 instead of 0.
so you can do:

menu.AddItem("bestmap", "bestmap");
menu.AddItem("okaymap", "okaymap");
menu.AddItem("badmap", "badmap");
menu.AddItem("badmap", "badmap");
menu.AddItem("badmap", "badmap");

menu.ShufflePerClient(2);

that should put bestmap on top, okaymap as 2nd and the badmaps will be randomized.

I use the end param to not randomize the extend option for example, so it is always on number 9.
And if you had some text on line 1 then you'd set the start param to 1 to not randomize entry 0.

@KyleSanderson
Copy link
Member

I don't think this needs to be securely shuffled. Think we can just "shift" the options per client index? if they're client 9 -> shift all elements by 9 on a circular buffer.

@BotoX
Copy link
Contributor Author

BotoX commented Sep 7, 2019

Sure but this is barely any more complex, doesn't use much memory and enables setting options to fixed slots per client with the new native.
And most importantly it's already implemented and works as expected.
Also real random is just better :p

@BotoX BotoX force-pushed the feature-MenuShufflePerClient branch 2 times, most recently from 65aed6f to 7185be1 Compare September 10, 2019 09:21
Copy link
Member

@Headline Headline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with taking this as-is, looks good to me.

I'll leave it for someone else to 🚢, though.

Good work BotoX!

@Headline Headline added the Feature Request user requested feature label Feb 9, 2020
@BotoX BotoX force-pushed the feature-MenuShufflePerClient branch from 7185be1 to 8d6f1b4 Compare July 9, 2020 12:02
@KyleSanderson KyleSanderson merged commit 6f21138 into alliedmodders:master Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Request user requested feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants