[Tutorial] Creating Menus/Dialog Box's

Started by SA:MP, May 05, 2023, 05:48 AM

Previous topic - Next topic

0 Members and 4 Guests are viewing this topic.

FrankJScott

To the people asking about electric brake system, master brake, automotive aftermarket companies, piese auto uk, part on line, vehicle parts website, spare parts dubai online, air brake system, buy brake calipers, world america parts,  I highly suggest this she said for car part link or cheap car parts online, auto parts online catalog, best cheap auto parts online, air compressor for pickup truck, brake finder, trailer brake system for truck, air hose for trailer, auto supplier, truck oem parts, air compressor parts store near me, not to mention this published here for car part forum as well as general motors truck parts, car pieces shop, parts for my car, international air compressor, na motor, auto parts suppliers in south africa, auto parts bulgaria, search auto parts by part number, trailer brake control valve, air compressor for auto, on top of this excellent car part forum which is also great. Also, have a look at this recommended you read about car part site which is worth considering with disc brake system, parts website, best auto car parts, truck auto parts store near me, best online car parts, oem part search, vaden catalog online, trailer air valve, part search by number, air brake compressor rebuilders, which is worth considering with this the full report on car part blog bearing in mind volvo truck parts catalog pdf, commercial vehicle parts near me, international parts, shops that buy car parts, parts for my truck,  see on together with search parts by part number, car caliper, truck air tank check valve, trailer relay valve, original parts,  for good measure. Check more @ Cool Tents Supplier In Ksa Website 456a027

FrankJScott

In response to the person asking about abl inhibitor, parp1 inhibitor, gpcr diseases, nadh reaction, pluripotent progenitor cells, methenamine hip, aeb071, tideglusib where to buy, carboxyl amino acid, h1 histamine receptor antagonist,  I highly suggest this resources on amino acid site or parp2 inhibitor, methenamine hipp 1 gm, cy5 dye color, nicotinamide adenine dinucleotide, dimethylglycine, mtor inhibitor foods, mtor signaling pathway, histone modification gene expression, e1 enzyme, arq 531, on top of this discover more here for amino acid forum not to mention amino acid 6, 3 3 diiodo l thyronine, dheas y dhea, calcium d saccharate, calmodulin dependent kinase, pdl1 drugs, ots964, arv825, vitamin b2 metabolism, riboflavin storage, as well as this a replacement on amino acid tips which is also great. Also, have a look at this that guy for amino acid blog and don't forget sybr green mix, k+ channel blockers, calcium blockers list, name of 9 essential amino acids, betahistine drug, ion channel blocker drugs, potassium acetate pka, cariprazine hcl, sik inhibitor for sale, asarone, together with this description on amino acid tips together with methenamine hippurate antibiotic, rt qpcr protocol sybr green, pdl pdl1, virtual screening methods, phospholipase inhibitor,  my latest blog post for as well as enclomiphene citrate buy, anti pdl1 drugs, fmn vitamin b2, oligomycin inhibits complex, amino acids what is it,  for good measure. Check more @ Recommended Natural Pet Supplements Blog b9d6845

FrankJScott

In reply to the guy inquiring about face fillers before and after, face tightening laser treatment, best face skin tightening treatment, lip filler rha, lip dermal fillers, anti wrinkle fillers, fillers best, most effective wrinkle filler, botox help, the best treatment for face wrinkles,  I highly suggest this this contact form for platelet rich plasma therapy for men sarasota advice or red light therapy for wrinkles, priapus shot, red light therapy best, best treatment for fat loss, best botox treatment near me, dermal fillers for lip lines before and after, orange peel chin botox before and after, botox and forehead wrinkles, wrinkle treatment injections, lip enlargement, not to mention this my review here for pshot services sarasota advice alongside all best facial, injections for fat reduction, botox injections how much, laser treatment for frown lines, best co2 laser for face, microneedling for skin rejuvenation, best tightening skin care, red light therapy for skin care, best place to have botox, best skin rejuvenation treatments, alongside all this read more on platelet rich plasma therapy for men sarasota blog which is also great. Also, have a look at this breaking news for platelet rich plasma therapy for men sarasota url not forgetting sites such as a lift facial, microneedling skin rejuvenation, wrinkles care, best skin fillers wrinkles, best skin therapy, xeomin forehead, peel of treatment, popular dermal fillers, wrinkle medication, best lip filler, not to mention this recommended male rejuvenation sarasota tips and don't forget botox med spa sarasota, prp vampire treatment, plasma facial rejuvenation, best chemical peel treatment, filler rha,  check this out on alongside all laser rejuvenation, rf skin care, botox like treatment, facial wrinkle removal, skin rejuvenation what is it,  for good measure. Check more @ Recommended Penile Treatment Sarasota Blog 2f8d49c

SA:MP

[Tutorial] Creating Menus/Dialog Box's



Creating A Menu with a Dialog




Syntax for Dialogs


PHP Code:




ShowPlayerDialog(playerid, **DIALOGID**, **DIALOGSTYLE**, "**DIALOGTITLE**""**DIALOGBODYCONTENT**""**LEFTBUTTONTEXT**""**RIGHTBUTTONTEXT**"); 






DialogID - This is used to reference a Dialog in different area's of your Gamemode/Filterscript.

DialogStyle - This is a multi choice depending what kind of Dialog Style you need or want, you will learn about these in this tutorial.

DialogTitle - This goes on the Dialog at the top, as the Title shown.

DialogBodyContent - This is what is in the middle of your Dialog, weather that is Text,Numbers,Items etc, you will also learn how to create Listitems in this tutorial.

Left & Right Button - This is to make your Dialogs Responsive and do different things, adding extra dialogs to open after you click it, or do certain tasks.





Setting Up Framework for Dialogs

We will use an Enumerator for this, so we don't have to constantly define numbers and have a possibility of forgetting DialogID's along the way.

If you don't know how to use an Enumerator, there is a great Article about this already.

https://sampforum.blast.hk/showthread.php?tid=318307


PHP Code:




enum

{

    
DIALOG_UNUSED

}; 






First off the bat, you'll want to make sure this Enumerator is placed at the top of your script, below your Includes,Defines, beside any custom Global Variables you've created already.



What is DIALOG_UNUSED? This is basically DIALOG ID 0, we are using this as a placeholder and I will explain why.



Say you have your Help Command, which just shows all the available CMD's on your server, but it doesn't do anything else when you click the Menu Buttons on the Dialog? That mean's we wont need to use OnDialogResponse Callback's features for that Dialog, and if there is any more Dialogs you have, that have no functions with the buttons, you also wont need OnDialogResponse's Features, therefore you're able to use the same Dialog ID, so we can just use DIALOG_UNUSED like this


Code:

ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, "Messagebox Title 1", "This is Information inside the first Messagebox", "Ok", "");

ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, "Messagebox Title 2", "This is Information inside the second Messagebox", "Okay", "");

DIALOG_STYLE_MSGBOX



This is a MessageBox, You can fit a lot of text into these, It's useful for Help Commands such as /ahelp or /help

or even /stats or whatever feature you want, like maybe even Text Messages in a Roleplay Gamemode?

Literally your Imagination will be the limit of this Dialog's Usage.



So lets create one!

First we should have another look at that Enumerator


PHP Code:




enum

{

    
DIALOG_UNUSED

}; 






We can add more DialogID's we are actually going to use with response functions, so for now lets just show a Helpful MessageBox with information.


PHP Code:




enum

{

    
DIALOG_UNUSED,

    
DIALOG_HELP,

    
DIALOG_HELP2

}; 






So now we have the DialogID DIALOG_HELP and DIALOG_HELP2 defined and now ready to be used, so lets use them in a Command.



NOTE: I am not creating a tutorial on CMDS and Processors, this is ZCMD Format, if you can't understand it then I suggest you go study it a little.


PHP Code:




CMD:help(playeridparams[])

{

    
ShowPlayerDialog(playeridDIALOG_HELPDIALOG_STYLE_MSGBOX"Help Page 1""This is Page 1 of the Help Messagebox""Page 2""Exit");

    return 
1;








Now that we have that Command created, if you were to test it, you'd notice typing /help will show a Messagebox, with what we wrote in it, furthermore youll notice the Page 2 Button does not actually do anything, so lets change that and make it do something.



First I would like to mention, using Switches is the best method here, youll have less confusion with your code and switch brings some great benefits and in some cases less code to actually write.



And theres been mention if youre running filterscripts with dialogs in them, that when youre coding your dialog response  you should be returning 0, ill quote something here for you guys.




Quote:







Originally Posted by l0gic

View Post


OnDialogResponse

"Returning 0 in this callback will pass the dialog to another script in case no matching code were found in your gamemode's callback.

It is always called first in filterscripts so returning 1 there blocks other filterscripts from seeing it."


In my opinion all dialogs should be together and in one place however thats not always the case, so return however you need, thanks l0gic for this information, but lets pretend all our dialogs are just in the gamemode for this Tutorial.



So lets do our response for our help command we created.


PHP Code:




public OnDialogResponse(playeriddialogidresponselistiteminputtext[])

{

    switch(
dialogid)

    {

        case 
DIALOG_UNUSED: return 1//This is the Empty Dialog that isn't used as I previously mentioned.

        
case DIALOG_HELP://This is our Help Dialog called from CMD:help

        
{

            if(!
response) return 1;//This is the Exit Button we made, the right side Button

            
else if(response)//This is the Page 2 Button we made, the left side Button

            
{

                
//We want to show the Page 2 Dialog now that they have pressed the Help Page 2 Button

                
ShowPlayerDialog(playeridDIALOG_HELP2DIALOG_STYLE_MSGBOX"Help Page 2""This is Page 2 of the Help Messagebox""Page 1""Exit");

                return 
1;

            }

        }

        case 
DIALOG_HELP2://This is our Page 2 Dialog Response, called from DIALOG_HELP Button

        
{

            if(!
response) return 1;//This is the Exit Button we made, the right side Button

            
else if(response)//This is the Page 1 Button we made, the left side Button, to take us back to the Page 1 Dialog

            
{

                
//We want to show the Page 1 Dialog now that they have pressed the Help Page 1 Button

                
ShowPlayerDialog(playeridDIALOG_HELPDIALOG_STYLE_MSGBOX"Help Page 1""This is Page 1 of the Help Messagebox""Page 2""Exit");

                return 
1;

            }

        }

    }

    return 
1;








Now if you go ingame and test that, you'll see that /help still works the same, but the button "Page 2" Actually displays the Page 2 Dialog now.

and if we click the "Page 1" Button, you'll be directed back to the 1st Page of Help.

Things to note: You can add new lines in a Messagebox by writing "\n" within the Text for the Messagebox Content, See Below as an Example.


PHP Code:




ShowPlayerDialog(playeridDIALOG_UNUSEDDIALOG_STYLE_MSGBOX"Line Testing""This is Line 1\nThis is Line 2\nThis is Line 3""Ok"""); 











DIALOG_STYLE_INPUT



This is an Input Box, This can be used for many different things, Setting a Skin ID, by typing it into the Dialog Input, anything to do with Numbers really, or even Strings!, changing a players name can be done here aswell!



SOoOoO let's create a Name Change Input Box!



First off, we will add a new DialogID into our Enum, name it DIALOG_CHANGENAME


PHP Code:




enum

{

    
DIALOG_CHANGENAME

}; 






Now we have a Dialog ID for Change Name Dialog, we can make the Command to show the Dialog itself.




PHP Code:




CMD:changename(playeridparams[])

{

    
ShowPlayerDialog(playeridDIALOG_CHANGENAMEDIALOG_STYLE_INPUT"Change Name","Enter your new desired Name you wish to use:","Change","Exit");

    return 
1;








There we go, if you go ingame, you'll see when you type /changename, a dialog will show up, with an input field, to change your name, however it won't do anything, because again, we have not setup the response in OnDialogResponse.



So let's do that now!




PHP Code:




public OnDialogResponse(playeriddialogidresponselistiteminputtext[])

{

    switch(
dialogid)

    {

        case 
DIALOG_UNUSED: return 1//This is the Empty Dialog that isn't used as I previously mentioned.

        
case DIALOG_CHANGENAME://This is our Changename Dialog called from CMD:changename

        
{

            if(!
response) return 1;//This is the Exit Button we made, the right side Button

            
else if(response)//This is the Change Button we made, the left side Button

            
{

                if(!
strlen(inputtext) || strlen(inputtext) > 24) return SendClientMessage(playerid, -1"Name Changing requires the name to be of a length between 1-24");//This checks if they typed nothing or too much.

                //We want to Change the Players Username based on what they typed in the Box earlier since we now know its between 1-24, so we use "inputtext" for that again.

                
SetPlayerName(playeridinputtext);//This will change the players name based on what they wrote in the Input Dialog.

                
SendClientMessage(playerid, -1"You have successfully changed your name, enjoy!");

                return 
1;

            }

        }

    }

    return 
1;








Now when you go ingame, typing /changename and enter a name in the Input Box, you'll notice your name will be changed!, quite a small basic feature but you can imagine how complicated it would get, if you want to check if another player has that name, but this is for the sake of a Tutorial and learning to use the Dialog's themselves, not feature packed Functions within them.



DIALOG_STYLE_LIST



This is a ListBox, personally my favorite of them all, because of how Dynamic this can be, and its functions, so much use within this 1 Dialog type that it's hard for me to pick a Feature to use for the Tutorial, Teleport List? Yeah lets do it.



So again, we need that Enum to have our new Dialog ID, name it DIALOG_TELEPORTS.




PHP Code:




enum

{

    
DIALOG_UNUSED,

    
DIALOG_TELEPORTS

}; 






Now we have a Dialog ID for Teleport List, we can make the Command to show the Dialog itself.


PHP Code:




CMD:teleport(playeridparams[])

{

    
ShowPlayerDialog(playeridDIALOG_TELEPORTSDIALOG_STYLE_LIST"Teleport","Los Santos\nSan Fierro\nLas Venturas","Teleport","Exit");

    return 
1;








See how we are using that "\n" in the string there, thats because again we are making a new line, like how I exampled earlier, but this time, it does a little more than adding a new "line", let me explain this here.

"Los Santos" will be now on its own line, and when we click only that line, its response would be different than "San Fierro" or "Las Venturas"

they basically get split up into a ***LIST*** Simple right? sure is!



So if we go ingame, yet again we can use the Command associated with our new Dialog Type, /teleport, we can click all 3 but nothing will happen because again OnDialogResponse needs to be coded for it, so lets get going with our response code.




PHP Code:




public OnDialogResponse(playeriddialogidresponselistiteminputtext[])

{

    switch(
dialogid)

    {

        case 
DIALOG_UNUSED: return 1//This is the Empty Dialog that isn't used as I previously mentioned.

        
case DIALOG_TELEPORTS://This is our Teleports Dialog called from CMD:teleport

        
{

            if(!
response) return 1;//This is the Exit Button we made, the right side Button

            
else if(response)//This is the Teleport Button we made, the left side Button

            
{

                switch(
listitem)//This is switching ListItems, self explanatory BUT this is smart, them "\n" we added play the role on determining how many List Items we have.

                
{

                    
//We always start with "0" which is essentially the First List Item from the top.

                    
case 0://Los Santos Teleport

                    
{

                        
SetPlayerPos(playerid1532.0996,-1675.6741,13.3828);

                        
SendClientMessage(playerid, -1"You've teleported to Los Santos");

                        return 
1;

                    }

                    case 
1://San Fierro Teleport

                    
{

                        
SetPlayerPos(playerid, -2649.0630,21.0362,6.1328,357.6369); // San Fierro

                        
SendClientMessage(playerid, -1"You've teleported to San Fierro");

                        return 
1;

                    }

                    case 
2://Las Venturas Teleport

                    
{

                        
SetPlayerPos(playerid1687.0597,1446.8789,10.7688,275.8561); // Las Venturas

                        
SendClientMessage(playerid, -1"You've teleported to Las Venturas");

                        return 
1;

                    }

                }

            }

        }

    }

    return 
1;








That should be perfect, going ingame, typing /teleport should bring us to our Teleport Menu with our 3 Options, selecting one and pressing "Teleport" Button should teleport us to the desired Location now, you can easily add onto this list and create more teleports and modify the existing ones.



DIALOG_STYLE_PASSWORD



This is a Password Input, exactly the same type of Input Dialog as the standard Input one we used to change our name, but this one simply covers the password with the

hidden character, during input... using this is exactly the same as DIALOG_STYLE_INPUT.

Create one and see for yourself, you'd use this specifically for a password screen.


PHP Code:




ShowPlayerDialog(playeridPUTDIALOGIDHEREDIALOG_STYLE_PASSWORD"Password","Things you type here will be shown as a password:","Ok",""); 









And that concludes the Tutorial, I seen a few different Tutorials for Dialogs, I even created one myself a few years ago, however that was in 2012 and I wasn't as smart as I am now, so reiterating on it, with switches and decent examples of usage, hopefully this helps someone, it's good to know how to use these, even with all the Textdraws nowadays I still personally prefer Dialogs, feel free to comment any ideas for another Tutorial if you guys need help with something else.


Source: [Tutorial] Creating Menus/Dialog Box's