SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 26/05/2015, 06:14 AM   #21
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,806
Reputation: 831
Default Re: GMenus Include (stylish GTA V themed* interaction menus!)

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 Y_Less

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.
__________________

My GitHub:

Gammix is offline   Reply With Quote
Old 26/05/2015, 10:17 PM   #22
SickAttack
Godfather
 
Join Date: Dec 2013
Posts: 5,113
Reputation: 754
Default Re: GMenus Include (stylish GTA V themed* interaction menus!)

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.
SickAttack is offline   Reply With Quote
Old 27/05/2015, 04:06 AM   #23
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,806
Reputation: 831
Default Re: GMenus Include (stylish GTA V themed* interaction menus!)

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
__________________

My GitHub:

Gammix is offline   Reply With Quote
Old 13/07/2015, 01:50 PM   #24
Saddin
Huge Clucker
 
Saddin's Avatar
 
Join Date: Mar 2011
Posts: 373
Reputation: 35
Default Re: GMenus Include (stylish GTA V themed* interaction menus!)

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; ....}
Saddin is offline   Reply With Quote
Old 13/07/2015, 02:12 PM   #25
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,806
Reputation: 831
Default Re: GMenus Include (stylish GTA V themed* interaction menus!)

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;
}
__________________

My GitHub:

Gammix is offline   Reply With Quote
Old 16/07/2015, 09:13 PM   #26
bruxo00
High-roller
 
bruxo00's Avatar
 
Join Date: Oct 2012
Location: Portugal
Posts: 1,074
Reputation: 137
Default Re: GMenus Include (stylish GTA V themed* interaction menus!)

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.
__________________
RELEASES

[INC] SAMPMailJS
[FS] doxIT!
[GM] Paradise City Roleplay
[TOOL] bAnticheat
[TOOL] Logs Checker
[TUTORIAL] Email confirmation system

https://etherumble.com - Ethereum gambling powered by Smart Contracts and the Blockchain technology
Coming soon...
bruxo00 is offline   Reply With Quote
Old 22/07/2015, 04:28 PM   #27
LegendOfScripts
Banned
 
Join Date: Feb 2015
Posts: 80
Reputation: 5
Default Re: GMenus Include (stylish GTA V themed* interaction menus!)

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.
LegendOfScripts is offline   Reply With Quote
Old 23/07/2015, 04:01 PM   #28
Excel™
Gangsta
 
Excel™'s Avatar
 
Join Date: Jul 2012
Posts: 559
Reputation: 95
Default Re: GMenus Include (stylish GTA V themed* interaction menus!)

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!
__________________
NO MORE CODING SAMP :V
JUST PLAYING...
Excel™ is offline   Reply With Quote
Old 23/07/2015, 04:20 PM   #29
NegoEnsina
Big Clucker
 
Join Date: Jun 2015
Posts: 70
Reputation: 28
Default Re: GMenus Include (stylish GTA V themed* interaction menus!)

Pretty good.
NegoEnsina is offline   Reply With Quote
Old 27/07/2015, 02:32 PM   #30
LegendOfScripts
Banned
 
Join Date: Feb 2015
Posts: 80
Reputation: 5
Default Re: GMenus Include (stylish GTA V themed* interaction menus!)

future release could be you could make it so we can show a menu after one has been shown.
LegendOfScripts is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[FilterScript] Stylish login screen. CharlieSanchez Filterscripts 45 18/10/2017 06:22 AM
Interaction with objects Laurentziu Scripting Help 12 12/03/2015 09:29 AM
[FilterScript] ::: Sleek & Stylish Digital Speedometer ::: iPLEOMAX Filterscripts 70 28/10/2012 05:09 AM
[Map] New stylish map Vegetathebest Maps 2 14/04/2012 12:27 PM
The interaction between AMX and DLL webcode421F Plugin Development 8 13/10/2011 10:02 PM


All times are GMT. The time now is 11:14 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.