[Tutorial] How to Make Dialogs!
#1

WHAT IS IT
This is a Tutorial which will teach you how to create Dialogs with Responses.


DESCRIPTION
I have seen many people who dont know how to create Dialogs with Responses but they will now learn it using this Tutorial.


LET'S START
First I will explain How to create Dialog. "ShowPlayerDialog" is used to create a Dialog. This is the format:
Код:
ShowPlayerDialog(playerid, Dialogid, Style, Caption[], Info[], Button1[], Button2[])
These are it's Parameters:

Код:
playerid	 - The ID of the player to show the dialog to.
Dialogid 	 - The Dialog ID. Max Dialog ID is 32767.
Style  		 - The style of the dialog.
Caption		 - The Heading of The Dialog.
Info		 - The Main Text in the Dialog. Use \n for Next Line and \t for Tabulate.
Button1		 - The Text on The Left Button.
Button2		 - The Text on the Right Button.
I hope you understand it by seeing the Picture.

I will be making a Teleport Dialog. First make a command for Showing players the Dialog e.g.
Код:
CMD:teles(playerid, params)
Now I will make the fuction for it. The fuction would be:
Код:
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_LIST, "Teleports", "Abondoned Airport\nSan Ferrieno Airport\nLos Santos Airport\nLas Venturas Airport","Teleport","Cancel");
This will show the Player Something like this:


Now Time for "OnDialogResponse"

Код:
OnDialogResponse(playerid, Dialogid, Response, Listitem, Inputtext[])
Parameters:
Код:
playerid 	- The Player ID that responded to the Dialog.
Dialogid 	- The Dialog ID we used in ShowPlayerDialog.
Response	- 1 for left button and 0 for right button.
Listitem	- The listitem if the Dialog is a List.
Inputtext	- The Input Text if it is a Input Dialog
First we will check what is the ID of the Dialog the Player Responded.
Код:
if(dialogid == 2) {
Then we will check what Button did he Pressed.
Код:
if(response) { //It means the player pressed the left Button which was "Teleport"
Then check what was the List Item he selected.
Код:
if(listitem == 0) { //It means he selected the first List Item which was "Abondoned Airport"
You will get this:
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 98) {
if(response) {
if(listitem == 0) {
Now lets Put the Function:
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 98) {
if(response) {
if(listitem == 0) {

SetPlayerPos(playerid,404.0729,2464.5574,16.5000);
SendClientMessage(playerid, 0xFFFF00AA, "You Have Teleported To Abondoned Airport" ); 

} //It means End of functions of List Item 0
Similarly we will put the other functions.
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 98) {
if(response) {
if(listitem == 0) {

SetPlayerPos(playerid,404.0729,2464.5574,16.5000);
SendClientMessage(playerid, 0xFFFF00AA, "You Have Teleported To Abondoned Airport" ); 
}

if(listitem == 1) { //It means if he selected "San Ferrieno Airport"

SetPlayerPos(playerid,-1353.3026,-235.7281,14.1440);
SendClientMessage(playerid, 0xFFFF00AA, "You Have Teleported To San Ferrieno Airport" ); 
}

if(listitem == 2) { //It means if he selected "Los Santos Airport"

SetPlayerPos(playerid,1422.1212,-2541.3335,13.5469);
SendClientMessage(playerid, 0xFFFF00AA, "You Have Teleported To Los Santos Airport" ); 
}

if(listitem == 3) { //It means if he selected "Las Venturas Airport"

SetPlayerPos(playerid,1319.9559,1269.4812,10.8203);
SendClientMessage(playerid, 0xFFFF00AA, "You Have Teleported To Las Venturas Airport" ); 
}
This is my first Tutorial so please go easy on me. This is the best I could explain. I hope you guys get it. Ask me if you have any problems.

Source: http://wiki.sa-mp.com
Reply
#2

In the last piece of code, it's better to use switch-case instead of multiple if's.

PHP код:
switch (listitem)
{
    case 
0:
    {
        
SetPlayerPos(playerid,404.0729,2464.5574,16.5000);
        
SendClientMessage(playerid0xFFFF00AA"You Have Teleported To Abondoned Airport" ); 
    }
    case 
1:
    {
        
SetPlayerPos(playerid,-1353.3026,-235.7281,14.1440);
        
SendClientMessage(playerid0xFFFF00AA"You Have Teleported To San Ferrieno Airport" ); 
    }
    case 
2:
    {
        
SetPlayerPos(playerid,1422.1212,-2541.3335,13.5469);
        
SendClientMessage(playerid0xFFFF00AA"You Have Teleported To Los Santos Airport" ); 
    }
    case 
3:
    {
        
SetPlayerPos(playerid,1319.9559,1269.4812,10.8203);
        
SendClientMessage(playerid0xFFFF00AA"You Have Teleported To Las Venturas Airport" ); 
    }

Reply
#3

Nice Tutorial Useful For New scripters
Reply
#4

use [php] instead of [code]
Reply
#5

Not putting you down, but this has been done way too many times..

https://sampwiki.blast.hk/wiki/How_to_Create_a_Dialog

https://sampforum.blast.hk/showthread.php?tid=379247
https://sampforum.blast.hk/showthread.php?tid=158858
https://sampforum.blast.hk/showthread.php?tid=109610
https://sampforum.blast.hk/showthread.php?tid=105229
https://sampforum.blast.hk/showthread.php?tid=361014
https://sampforum.blast.hk/showthread.php?tid=293436
https://sampforum.blast.hk/showthread.php?tid=247503

Doing a search on the forums or even ****** will give you many of these.
Reply
#6

Dude but I tried to explain better with pics
Reply
#7

I really don't like doing dialogs like this y_inline/y_dialog is by far superior to any other method why would you want to waste time doing it like this?

Example
Код:
#include <a_samp>
#include <YSI\y_inline>
#include <YSI\y_dialog>
#include <YSI\y_commands>

CMD:teles(playerid, params[])
{
	inline TeleportMenu(pid, dialogid, response, listitem, string:text[])
	{
		#pragma unused listitem, dialogid, pid, text
		if(response)
		{
			switch(listitem)
			{
			    case 0:
			    {
					SetPlayerPos(playerid,404.0729,2464.5574,16.5000);
					SendClientMessage(playerid, 0xFFFF00AA, "You Have Teleported To Abondoned Airport" );
				}
			    case 1:
			    {
					SetPlayerPos(playerid,-1353.3026,-235.7281,14.1440);
					SendClientMessage(playerid, 0xFFFF00AA, "You Have Teleported To San Ferrieno Airport" );
				}
			    case 2:
			    {
					SetPlayerPos(playerid,1422.1212,-2541.3335,13.5469);
					SendClientMessage(playerid, 0xFFFF00AA, "You Have Teleported To Los Santos Airport" );
				}
			    case 3:
			    {
					SetPlayerPos(playerid,1319.9559,1269.4812,10.8203);
					SendClientMessage(playerid, 0xFFFF00AA, "You Have Teleported To Las Venturas Airport" );
				}
			}
		}
	}
	Dialog_ShowCallback(playerid, using inline TeleportMenu, DIALOG_STYLE_LIST, "Teleports", "Abondoned Airport\nSan Ferrieno Airport\nLos Santos Airport\nLas Venturas Airport", "Teleport", "Cancel");
	return 1;
}
Reply
#8

Quote:
Originally Posted by Pottus
Посмотреть сообщение
why would you want to waste time doing it like this?
https://en.wikipedia.org/wiki/Not_invented_here

Especially "lack of understanding of the foreign work". I do not like to use code that I do not understand. YSI especially because it is such a mess of defines, macros, assembly code and other kinds of compiler hacks.
PHP код:
#define _DO_LAMBDA|||%6|||%5|||<%9>{%0}(%1)%8; LAM@0()%8;{LAM@1();static const YSII[]="@:....";if(I@E(YSII))for(%6;I@F();)while(I@L(I@K()%5))YSI_gInlineRet+=(%0);LAM@2(%9(callback_tag:YSII%1));} 
Actual line of code. Totally understandable.
Reply
#9

Yes the absurdity of that line could only be understood by a master of obfuscation.
Reply
#10

Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)