Raised This Month: $32 Target: $400
 8% 

[HOWTO] ShowMenus


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Tobi17
Senior Member
Join Date: May 2005
Old 05-09-2007 , 18:25   [HOWTO] ShowMenus
Reply With Quote #1

Hello

I have created two functions to display a "ShowMenu" within the HLstatsX Plugin of sourcemod. This is the way to achieve this:

Code:
stock build_menu(player_index, String: message[230], time, finish = 1)
{
	decl Handle:hBf;
	hBf = StartMessageOne("ShowMenu", player_index);
	if (hBf != INVALID_HANDLE) {
		BfWriteShort(hBf, -1); 
		BfWriteChar(hBf, time);
		BfWriteByte(hBf, finish);
		BfWriteString(hBf, message);
		EndMessage();
	}
}

stock display_menu(player_index, time, String: full_message[1024])
{
	new String: display_message[1024];
	new offset = 0;
	new message_length = strlen(full_message); 
	for(new i = 0; i < message_length; i++) {
		if (i > 0) {
			if ((full_message[i-1] == 92) && (full_message[i] == 110)) {
				new String: buffer[1024];
				strcopy(buffer, (i - offset), full_message[offset]);
				if (strlen(display_message) == 0) {
					strcopy(display_message[strlen(display_message)], strlen(buffer) + 1, buffer); 
				} else {
					display_message[strlen(display_message)] = 10;
					strcopy(display_message[strlen(display_message)], strlen(buffer) + 1, buffer); 
				}
				i++;
				offset = i;
			}
		}
	}

	new String: partial_message[230];
	new maximum_splits = 5;
	new splits = 0;
	while ((splits < maximum_splits) && (strlen(display_message) > 0)) {
		if (strlen(display_message) > 230) {
			strcopy(partial_message, 230, display_message);
			build_menu(player_index, partial_message, time, 1);
			strcopy(display_message, 1024, display_message[229]);
		} else {
			strcopy(partial_message, 230, display_message);
			build_menu(player_index, partial_message, time, 0);
			display_message = ""
		}
		splits++;
	}
}
To display a ShowMenu you would have to execute for excample:
Code:
display_menu(client, 15, "This is a menu");
Multiple Lines are defined with:
Code:
display_menu(client, 15, "This is a menu\nwhich have multiple\nlines");
Remember the menu can currently not(!) respond to any key input (its not needed in HLstatsX). However it would be very cool if someone could explain how to handle the key triggers, currently all keys are valid and static defined.


Bye
Tobi

Last edited by Tobi17; 05-09-2007 at 18:47.
Tobi17 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:13.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode