[Tutorial] Dialog Types and Other stuffs
#1

Hello , I am going to Explain how to make Random Spawns Through Dialog box and how to make them Response through in it..

What is Dialog box?

Dialog box is nothing but , a source where you can add a Dialog popup on a players screen by a Key or a Command text , It is usually used to make Login / Register System , Spawning Car's / Player's Skin , Commands info's , Server Info , Credits , Server Information and much more by your Creativity.

So, What types of Dialog box exists in SA-MP scripting ?
-List Dialog : To show a list of stuffs , that you want the player to choose and have 2 buttons to reply.
-Message Box Dialog : This is a simple one. It just is a textbox with two buttons no input no different choices just two buttons to process.
-Input Dialog : This dialog will have a line for input. (as the name implies).

List Dialog

Ok , So how to make a List Dialog and make the player to response them..

It's Easy , Let me Explain.

Код:
Here we Use , some called 
ShowPlayerDialog(playerid , DIALOG_NAME , DIALOG_TYPE,"DIALOG_CAPTION",DIALOG_INFO,"BUTTON1","BUTTON2");
Here Let me Explain you every Component -
playerid - The id of the player who type the Command.
DIALOG_NAME - You can write a number here , to specify the DIALOG.. Orelse you can make it in this way
new DIALOG_NAME NumberOfList
Example - new DIALOG_CARS 200
DIALOG_TYPE - As this is a list dialog , we put here - DIALOG_STYLE_LIST.
DIALOG_CAPTION - The name you want to put on the DIALOG Top.
DIALOG_INFO - The info you want to add there , Example - Infernus\nBullet\nCheetah\nBanshee , etc ....and it will show line wise.
BUTTON1 - It is the True button , it will make the Thing comes on , for example , if a player press on Infernus and press the button1 he gets the infernus. Mostly People name it , "SELECT".
BUTTON2 - This will make the action false. Mostly People name it , "CLOSE" or "CANCEL".

To make a response we must use " public OnDialogResponse(playerid) "

So this was what we can understand with DIALOG List type.
For a Example - I make a Gun Dialog.

new DIALOG_WEAPONS 3
Using ZCMD
Код:
CMD:guns(playerid,params[])
{
         ShowPlayerDialog(playerid, DIALOG_WEAPONS, DIALOG_STYLE_LIST, "Weapons", "Desert Eagle\nAK-47\nCombat Shotgun", "Select", "Close");
}
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == DIALOG_WEAPONS)
    {
        if(response) // If they clicked 'Select' or double-clicked a weapon
        {
            // Give them the weapon
            switch(listitem)
            {
                case 0: GivePlayerWeapon(playerid, WEAPON_DEAGLE, 14); // Give them a desert eagle
                case 1: GivePlayerWeapon(playerid, WEAPON_AK47, 120); // Give them an AK-47
                case 2: GivePlayerWeapon(playerid, WEAPON_SHOTGSPA, 28); // Give them a Combat Shotgun
            }
        }
        return 1; // We handled a dialog, so return 1. Just like OnPlayerCommandText.
    }
 
    return 0; // You MUST return 0 here! Just like OnPlayerCommandText.
}
This was a small example for Dialog List Type.. And it works WOW.. Now we go on with the Message type Dialog Box

Message Box Dialog

Everything is same , You just show the guy a message on his Screen , And 2 Options at the same time , As this is a message box you can make it , "Yes" and "No" , orelse if you want a single button , leave one as , " " and "Close"
This will show only 1 option "Close".

Example - We ask them about the Rules.
#define COLOR_RED 0xAA3333AA
new DIALOG_RULES 1
Код:
CMD:rules(playerid,params[])
{
         ShowPlayerDialog(playerid, DIALOG_RULES, DIALOG_STYLE_MSGBOX, "Server Rules", "- No Cheating\n- No Spamming\n- Respect the commands\nNo BUGS\nNo BUG abuse\n\nDo you agree to these rules?", "Yes", "No");
}
And in OnDialogResponse

we type
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == DIALOG_RULES)
    {
        if(response) // If they clicked "Yes" or if he press ENTER
        {
            SendClientMessage(playerid, COLOR_GREEN, "Thank you for agreeing to the server rules!");
        }
        else // Prssed ESC or clicked cancel
        {
            SendClientMessage(playerid, COLOR_RED, "You MUST agree to the server rules to play here.");
            
        }
        return 1; 
    }
 
    return 0; 
}
And WoW we are done.

Now here is the Input type Dialog.

Input Dialog
So this is same Aswell, Put here it goes as Follows
Код:
Here we Use , some called 
ShowPlayerDialog(playerid , DIALOG_NAME , DIALOG_TYPE,"DIALOG_CAPTION",DIALOG_INFO,"BUTTON1","BUTTON2");
Here Let me Explain you every Component -
playerid - The id of the player who type the Command.
DIALOG_NAME - You can write a number here , to specify the DIALOG.. Orelse you can make it in this way
new DIALOG_NAME NumberOfList
Example - new DIALOG_LOGIN_4
DIALOG_TYPE - As this is a list dialog , we put here - DIALOG_STYLE_INPUT.
DIALOG_CAPTION - The name you want to put on the DIALOG Top.
DIALOG_INFO - The Message you want to DISPLAY.
BUTTON1 - It is the True button , it will make the Thing comes on , for example , if a player press on Infernus and press the button1 he gets the infernus. Mostly People name it , "LOGIN".
BUTTON2 - This will make the action false. Mostly People name it , "CANCEL".

For any Easy Explanation let me explain you with an example -

Here i am going to make a Input box , that ask for age and save it.

Код:
enum pInfo
{
	pAge
}
That was simple enough.. to understand now let us make a " new " variable.
Код:
new pData[MAX_PLAYERS][pInfo];
Here we made a " new " variable.
Now we make a Define for our Dialog.
Код:
#define DIALOG_AGES 1
Now let's go with the Command, i use ZCMD.

Код:
CMD:age(playerid,params[])
{
	ShowPlayerDialog(playerid, DIALOG_AGES, DIALOG_STYLE_INPUT, "AGE", "Enter your age", "Done"," ");
}
Ok i choosed the dialog stype [ INPUT ] and the caption as age , and the data as " Enter your age " , and only one option " Done ".
Now on Dialog Response
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	if(dialogid == DIALOG_AGES]
	{
	    if(response)
	    {
			 pData[playerid][pAge] = strval(inputtext); // This will save the age.
	    }
	}
	return 1;
}
Ok , now a command to check the age.
Код:
CMD:checkage(playerid,params[])
{
	SendClientMessage(playerid,0x0000BBAA,"Your age is (pData[playerid][pAge])"); //The Color indicates Blue , and now the age will be Displayed.
}
And WOW , we are Done , If you again want to change the age , you need to do nothing , it saves the age automatically.

So , this is how we work with DIALOG.
I made this tutorial , to make it more Easy, If someone don't Understand Anything from other Tutorials, they can understand from here.

Thanks.
P.S - If i am wrong anywhere Please inform me , i will correct myself.
Reply
#2

Nice
Reply
#3

Quote:
pawn Код:
new pData[MAX_PLAYERS][pInfo];
Here we made a " new " variable.
Now we make a Define for our Dialog.
pawn Код:
#define DIALOG_AGE 1
Now let's go with the Command, i use ZCMD.

Код:
CMD:age(playerid,params[])
{
	ShowPlayerDialog(playerid, DIALOG_AGES, DIALOG_STYLE_INPUT, "AGE", "Enter your age", "Done"," ");
}
You misspelled "DIALOG_AGES" there.
And also i'd just like to add, that it's an array, not a variable.
And using an enumerator would be better than using #define to define numbers for each dialog.

But i feel like it would be nicer if you could go more in-depth.
Here's one example, like you just say you make a define for the dialog.
But what you're actually doing, is making DIALOG_AGE the same as writing 1.
So you could just
pawn Код:
ShowPlayerDialog(playerid, 1, ...)
which would be the exact same as
pawn Код:
ShowPlayerDialog(playerid, DIALOG_AGE, ...)
when using #define.

Didn't read the whole tutorial, but overall though it's a good tutorial that may help some new scripters, but there's some tips you could improve.
Reply
#4

Another bug in your code:

pawn Код:
pData[playerid][pAge] = 1; // This will save the age.
Should be:
pawn Код:
pData[playerid][pAge] = strval(inputtext); // This will save the age.
Otherwise players can enter anything in that box and the age will always be 1.
Reply
#5

Thanks guys I edited..
Reply
#6

You didn't see what i mentioned?
pawn Код:
ShowPlayerDialog(playerid, DIALOG_AGES, DIALOG_STYLE_INPUT, "AGE", "Enter your age", "Done"," ");
You misspelled DIALOG_AGE there.
Also in your OnPlayerDialogResponse i just saw
pawn Код:
if(dialogid == DIALOG_AGES]
Reply
#7

Could you use proper grammar when making a tutorial? I don't like those random caps everywhere in the post, it just makes me want to click the little x on the tab of my browser.
Reply
#8

Sorry dude for the inconvinence .. I will edit the post asap
Reply
#9

Easy Dialogs
Quote:

stock SPDM(pl, dl, desc[], info[], but1[], but2[]){return ShowPlayerDialog(pl,dl,DSM,desc,info,but1,but2);}
stock SPDL(pl, dl, desc[], info[], but1[], but2[]){return ShowPlayerDialog(pl,dl,DSL,desc,info,but1,but2);}
stock SPDI(pl, dl, desc[], info[], but1[], but2[]){return ShowPlayerDialog(pl,dl,DSI,desc,info,but1,but2);}

Reply
#10

Quote:
Originally Posted by SnoopDy
Посмотреть сообщение
Easy Dialogs
Well first of all, you didn't define "DSI", so it wont work.
And all it does is just taking away the dialog type, which isn't really for much use.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)