[Include] GMenus Include (stylish GTA V themed* interaction menus!)
#21

This include don't work on the basis of pages, its actually listitems.

If you had noticed, i don't give option to start a menu from any numbered listitem, thats because you would have to calculate a lot and get page ids from a listitem.

But you may check out the dialogs include.

So basically we start from page 1. You must have a macro or defination of listitems per page. For example:
pawn Code:
#define LISTITEMS_PER_PAGE 10
Now using ceildiv(a function from y_utils)
pawn Code:
#define ceildiv(%0,%1) (((%0)-1)/(%1)+1)//thansk to ******
Just get the total amount of listitems your menu or dialog have and input in the macro. For example:
Assuming you have total 50 items in your menu.
pawn Code:
ceildiv(50, LISTITEMS_PER_PAGE);
Will return the page id.

___

Where in this include, I simply use arrays to store player and menu data.
pawn Code:
gMenu[<menuid>][M_LISTITEMS];
^^ This for total lisitems.

pawn Code:
gPlayerMenu[<playerid>][PM_LISTITEM];
^^ This for player's current lisitem highlighted.

For detecting the page, i use two additional enums
pawn Code:
gPlayerMenu[<playerid>][PM_LISTITEM_FIRST];
gPlayerMenu[<playerid>][PM_LISTITEM_LAST];
These stores the first most item and the last most item, so its easy for me to calculate the next page or previous page.
Reply
#22

Quote:
Originally Posted by Gammix
View Post
...
That's why I asked you, the include seems to have more code than needed. And there's no need to store anything else than the page the player was last viewing, since the menus are static.

Obtain the total amount of pages:
pawn Code:
#define GetPageCount(%0,%1) floatround(%1 / %0, floatround_floor) + 1
Usage example:
pawn Code:
new pages = GetPageCount(results, total_results);
Obtain the current element count by the current page count:
pawn Code:
new resultcount = ((MAX_RESULTS * pLastPage[playerid]) - MAX_RESULTS);
Example of usage in play:
pawn Code:
// [ DEVELOPMENT GAMEMODE ]

// INCLUDES:

#include <a_samp>
#include <sscanf2>
#include <zcmd>

// DEFINES:

// GENERAL:

#define MAX_RESULTS 20
#define TOTAL_VEHICLES 212

// FUNCTIONS:

#define GetPageCount(%0,%1) floatround(%1 / %0, floatround_floor) + 1

// DIALOGS:

#define DIALOG_OK 500
#define DIALOG_VEHICLE_LIST 501

// ARRAYS AND ENUMERATORS:

static const stock aVehicles[TOTAL_VEHICLES][] =
{
    {"Landstalker"},
    {"Bravura"},
    {"Buffalo"},
    {"Linerunner"},
    {"Perrenial"},
    {"Sentinel"},
    {"Dumper"},
    {"Firetruck"},
    {"Trashmaster"},
    {"Stretch"},
    {"Manana"},
    {"Infernus"},
    {"Voodoo"},
    {"Pony"},
    {"Mule"},
    {"Cheetah"},
    {"Ambulance"},
    {"Leviathan"},
    {"Moonbeam"},
    {"Esperanto"},
    {"Taxi"},
    {"Washington"},
    {"Bobcat"},
    {"Mr Whoopee"},
    {"BF Injection"},
    {"Hunter"},
    {"Premier"},
    {"Enforcer"},
    {"Securicar"},
    {"Banshee"},
    {"Predator"},
    {"Bus"},
    {"Rhino"},
    {"Barracks"},
    {"Hotknife"},
    {"Trailer 1"},
    {"Previon"},
    {"Coach"},
    {"Cabbie"},
    {"Stallion"},
    {"Rumpo"},
    {"RC Bandit"},
    {"Romero"},
    {"Packer"},
    {"Monster"},
    {"Admiral"},
    {"Squalo"},
    {"Seasparrow"},
    {"Pizzaboy"},
    {"Tram"},
    {"Trailer 2"},
    {"Turismo"},
    {"Speeder"},
    {"Reefer"},
    {"Tropic"},
    {"Flatbed"},
    {"Yankee"},
    {"Caddy"},
    {"Solair"},
    {"Berkley's RC Van"},
    {"Skimmer"},
    {"PCJ-600"},
    {"Faggio"},
    {"Freeway"},
    {"RC Baron"},
    {"RC Raider"},
    {"Glendale"},
    {"Oceanic"},
    {"Sanchez"},
    {"Sparrow"},
    {"Patriot"},
    {"Quad"},
    {"Coastguard"},
    {"Dinghy"},
    {"Hermes"},
    {"Sabre"},
    {"Rustler"},
    {"ZR-350"},
    {"Walton"},
    {"Regina"},
    {"Comet"},
    {"BMX"},
    {"Burrito"},
    {"Camper"},
    {"Marquis"},
    {"Baggage"},
    {"Dozer"},
    {"Maverick"},
    {"News Chopper"},
    {"Rancher"},
    {"FBI Rancher"},
    {"Virgo"},
    {"Greenwood"},
    {"Jetmax"},
    {"Hotring"},
    {"Sandking"},
    {"Blista Compact"},
    {"Police Maverick"},
    {"Boxville"},
    {"Benson"},
    {"Mesa"},
    {"RC Goblin"},
    {"Hotring Racer A"},
    {"Hotring Racer B"},
    {"Bloodring Banger"},
    {"Rancher"},
    {"Super GT"},
    {"Elegant"},
    {"Journey"},
    {"Bike"},
    {"Mountain Bike"},
    {"Beagle"},
    {"Cropdust"},
    {"Stunt"},
    {"Tanker"},
    {"Roadtrain"},
    {"Nebula"},
    {"Majestic"},
    {"Buccaneer"},
    {"Shamal"},
    {"Hydra"},
    {"FCR-900"},
    {"NRG-500"},
    {"HPV1000"},
    {"Cement Truck"},
    {"Tow Truck"},
    {"Fortune"},
    {"Cadrona"},
    {"FBI Truck"},
    {"Willard"},
    {"Forklift"},
    {"Tractor"},
    {"Combine"},
    {"Feltzer"},
    {"Remington"},
    {"Slamvan"},
    {"Blade"},
    {"Freight"},
    {"Streak"},
    {"Vortex"},
    {"Vincent"},
    {"Bullet"},
    {"Clover"},
    {"Sadler"},
    {"Firetruck LA"},
    {"Hustler"},
    {"Intruder"},
    {"Primo"},
    {"Cargobob"},
    {"Tampa"},
    {"Sunrise"},
    {"Merit"},
    {"Utility"},
    {"Nevada"},
    {"Yosemite"},
    {"Windsor"},
    {"Monster A"},
    {"Monster B"},
    {"Uranus"},
    {"Jester"},
    {"Sultan"},
    {"Stratum"},
    {"Elegy"},
    {"Raindance"},
    {"RC Tiger"},
    {"Flash"},
    {"Tahoma"},
    {"Savanna"},
    {"Bandito"},
    {"Freight Flat"},
    {"Streak Carriage"},
    {"Kart"},
    {"Mower"},
    {"Duneride"},
    {"Sweeper"},
    {"Broadway"},
    {"Tornado"},
    {"AT-400"},
    {"DFT-30"},
    {"Huntley"},
    {"Stafford"},
    {"BF-400"},
    {"Newsvan"},
    {"Tug"},
    {"Trailer 3"},
    {"Emperor"},
    {"Wayfarer"},
    {"Euros"},
    {"Hotdog"},
    {"Club"},
    {"Freight Carriage"},
    {"Trailer 3"},
    {"Andromada"},
    {"Dodo"},
    {"RC Cam"},
    {"Launch"},
    {"LSPD Police Car"},
    {"SFPD Police Car"},
    {"LVPD Police Car"},
    {"Police Ranger"},
    {"Picador"},
    {"SWAT Van"},
    {"Alpha"},
    {"Phoenix"},
    {"Glendale"},
    {"Sadler"},
    {"Luggage Trailer A"},
    {"Luggage Trailer B"},
    {"Stair Trailer"},
    {"Boxville"},
    {"Farm Plow"},
    {"Utility Trailer"}
};

// VARIABLES:

new pLastPage[MAX_PLAYERS];

// MAIN:

main()
{
    print("Development Mode: vehicle_list.amx");
}

// CALLBACKS:

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case DIALOG_OK: return 1;
        case DIALOG_VEHICLE_LIST:
        {
            if(!response) return 1;
            else if(response)
            {
                pLastPage[playerid] ++;
                ShowVehicleList(playerid);
            }
        }
    }
    return 1;
}

// COMMANDS:

CMD:vehiclelist(playerid, params[])
{
    pLastPage[playerid] = 1;
    ShowVehicleList(playerid);
    return 1;
}

// FUNCTIONS:

stock ShowVehicleList(playerid)
{
    new title[128], string[300], pages = GetPageCount(MAX_RESULTS, TOTAL_VEHICLES), resultcount = ((MAX_RESULTS * pLastPage[playerid]) - MAX_RESULTS), bool:nextpage = false;
    strcat(string, "ID\tName");

    for(new i = resultcount; i < TOTAL_VEHICLES; i ++)
    {
        resultcount ++;
        if(resultcount <= MAX_RESULTS * pLastPage[playerid])
        {
            format(string, sizeof(string), "%s\n%d\t%s", string, resultcount, aVehicles[i]);
        }
        if(resultcount > MAX_RESULTS * pLastPage[playerid])
        {
            nextpage = true;
            break;
        }
    }

    format(title, sizeof(title), "{FFFF00}Vehicles - Page %d of %d", pLastPage[playerid], pages);
    if(nextpage) return ShowPlayerDialog(playerid, DIALOG_VEHICLE_LIST, DIALOG_STYLE_TABLIST_HEADERS, title, string, "Next", "Close");
    return ShowPlayerDialog(playerid, DIALOG_OK, DIALOG_STYLE_TABLIST_HEADERS, title, string, "Close", "");
}
Instead of giving them an option to go to a certain element, let them go to a page.
Reply
#23

Yes, first i was also building my menus based on that method but just lost my mind somewhere and couldn't continue.

I must rebuild this with the page method and with that i can also add custom row selection.

But all matters is time, i have lots of ideas but less time to implement
Reply
#24

Can anyone help me with this

i want to get result of choosing, for example when i choose listItem3, to write code like

if(listitem = 3) { //code here; ....}
Reply
#25

Its pretty straight using the callback:
pawn Code:
public OnMenuResponse(playerid, menuid, response, listitem)
{
    if(response == MENU_RESPONSE_SELECT)
    {
        if(listitem == 3)
        {
            //your code when the player selects listitem 3 (pressed the SPACE key)
        }
    }
    return 1;
}
Reply
#26

How can I make the player not move when the menu is visible? Already tried toggleplayercontrolabble but it don't work.

Awesome include!

@EDIT

Fixed. But the down arrow triggers the OnMenuResponse. It should not be trigged only when I clicked enter?

@EDIT 2

Only realised response now. Fixed.
Reply
#27

How many menus can I have, Can I make 100 menu's seen as I love this idea? and will it bug out if I have over 100 players?

I want to use these menu's for my weapon shop, Inventory system, House Inventory, House system buying ETC, Vehicle System, Help System, All shops and alot of other things.
Reply
#28

pawn Code:
#define MAX_G_MENUS             10 //maximum menus your script can have
Just change it to 100 and add your menus. I tried this include with 10 players and it works fine, so it will with more players!
Reply
#29

Pretty good.
Reply
#30

future release could be you could make it so we can show a menu after one has been shown.
Reply
#31

Quote:
Originally Posted by wampiros6
View Post
who help me with my problem?
I am working on an update, but it's not a fix for your problem or maybe it is.
Till then, please wait.
Reply
#32

Like That,
I Will try it...
Reply
#33

Update v2.0:
- New syntax
pawn Code:
ShowPlayerMenu(playerid, menuid, caption[], info[], type[] = "Interaction Menu", selectioncolor = 0x3F7FBFFF, textcolor = 0xFFFFFFFF, caption_boxcolor = 0xC51A71FF, listitem_boxcolor = 0x000000FF);
- New callback syntax:
pawn Code:
forward OnMenuResponse(playerid, menuid, response, listitem);
- Improved code, much optimized

"Syntax similar to dialogs, so no static menus anymore!"
Reply
#34

Quote:
Originally Posted by Gammix
View Post
Update v2.0:
- New syntax
pawn Code:
ShowPlayerMenu(playerid, menuid, caption[], info[], type[] = "Interaction Menu", selectioncolor = 0x3F7FBFFF, textcolor = 0xFFFFFFFF, caption_boxcolor = 0xC51A71FF, listitem_boxcolor = 0x000000FF);
- New callback syntax:
pawn Code:
forward OnMenuResponse(playerid, menuid, response, listitem);
- Improved code, much optimized

"Syntax similar to dialogs, so no static menus anymore!"
Good Work
Reply
#35

Update v2.0.1:
- Fixes menu auto hiding when you simultaneously shows another menu in OnMenuResponse.
- Fixed menu response type (when you selected any menu item, OnMenuResponse returned MENU_RESPONSE_CLOSE instead of MENU_RESPONSE_SELECT).
Reply
#36

Update v2.1.0:
- Menu page switching bug fixed
- Optimized, reduce if-else checks in OnPlayerUpdate
- Color transparency for dark bar decreased by (-30)!
Reply
#37

Yet another cool release, keep it up
Reply
#38

BUG: The red/pink box that says Test Menu in your screenshots disappears after using KEY_UP/KEY_DOWN for some reason.
Reply
#39

Very useful man =)
Reply
#40

Good to see the frequency in updating this include. +1 Reputation point for your efforts.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)