AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [HOWTO] ShowMenus (https://forums.alliedmods.net/showthread.php?t=54975)

Tobi17 05-09-2007 18:25

[HOWTO] ShowMenus
 
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


All times are GMT -4. The time now is 17:51.

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