How to Create a Dialog RU

From SA-MP Wiki

Jump to: navigation, search

Contents

Как создать диалог

Создание диалоговых окон

How to Create a Dialog RU была добавлена в SA-MP 0.3 Эта функция была добавлена в SA-MP 0.3 и не работает в более ранних версиях!


Вступление

Создание диалогов (в новом samp 0.3) может показаться довольно трудным, хотя на самом деле довольно просто создать диалоговое окно. Эта краткая инструкция продемонстрирует вам, как сделать диалоговый список. Это диалоговое окно для демонстрационных целей и будет довольно ограниченным.

Сдесь будут показаны 3 примера стилей диалоговых окон: DIALOG_STYLE_MSGBOX, DIALOG_STYLE_INPUT и DIALOG_STYLE_LIST.

Объяснение

Сначала рассмотрим функцию ShowPlayerDialog

И все её параметры:

ShowPlayerDialog(playerid, dialogid, style, caption[], info[], button1[], button2[])
playeridID игрока которому будет показан данный диалог.
dialogidID диалога, чтобы в дальнейшем мы могли с ним работать.
styleСтиль диалога.
caption[]Заголовок вверху окна диалога.
info[]Текст в окне диалога. Используйте \n чтобы начать писать с новой строки и \t для сведения в таблицу.
button1[]Текст кнопки №1.
button2[]Текст кнопки №2.


и обработка вызовов при нажатии кнопок диалога (button1[] или button2[])

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
playeridID игрока который нажал кнопку
dialogidID диалога в котором игрок нажал кнопку
responseЛогика: true - если была нажата кнопка №1, false - если была нажата кнопка №2
listitemИспользуется только в диалоге со стилем DIALOG_STYLE_LIST, первый элемент 0 и т.д. по возрастанию.
inputtext[]Используется только в диалоге со стилем DIALOG_STYLE_INPUT, это строка ввода в диалоговом окне.


now that is done we can proceed

List dialog

Во первыъ, рассмотрим пример с показом диалога по команде ввода. С использованием OnPlayerCommandText:

if(!strcmp(cmdtext, "/напитки", true))
{
    ShowPlayerDialog(playerid, 1, DIALOG_STYLE_LIST, "Что вы хотите выпить?", "Спранк ($1)\nПиво ($2)\nВино ($3)", "Выбрать", "Отмена");
    return 1;
}

Теперь, когда мы создали даилог вызываемый командой, мы должны настроить обработку вызовов OnDialogResponse при нажатии кнопок.

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(response)//they pressed the first button 
    {
    switch(dialogid)//if your using only one dialog this isn't needed but you never know.
        {
		case 1://наш диалог.
    	    {
           	switch(listitem)// элементы которые выбирают.
        	{
        	    case 0://the first item in the list
        	    {
        	        if(GetPlayerMoney(playerid) < 1) return SendClientMessage(playerid, 0xFFFFFF, "У вас недостаточно денег.");
        	        GivePlayerMoney(playerid, -1);
        	        SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DRINK_SPRUNK);
        	    }
        	    case 1:
        	    {
        	        if(GetPlayerMoney(playerid) < 2) return SendClientMessage(playerid, 0xFFFFFF, "У вас недостаточно денег.");
        	        GivePlayerMoney(playerid, -2);
        	        SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DRINK_BEER);
        	    }
        	    case 2:
        	    {
        	        if(GetPlayerMoney(playerid) < 3) return SendClientMessage(playerid, 0xFFFFFF, "У вас недостаточно денег.");
        	        GivePlayerMoney(playerid, -3);
        	        SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DRINK_WINE);
        	    }
        	}
    	    }
	}
    }
    return 1;
}

Let me explain what this does, there are two switches. one for the dialogid, and one for the listitem. the if statement at top is needed else it doesnt check what button you clicked.

msgbox dialog

This is a simple one. it just is a textbox with two buttons no input no different choises just two buttons to process

add this under OnPlayerCommandText

if(!strcmp(cmdtext, "/relax", true))
{
    ShowPlayerDialog(playerid, 2, DIALOG_STYLE_MSGBOX, "are you sure?", "Are you sure you have time to relax?", "yes", "no");
    return 1;
}

this will show the dialog with ID 2(we already used dialogid 1) to the player. the style here is DIALOG_STYLE_MSGBOX.

now we need to setup the response again.

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(response)//they pressed the first button    
    {
    switch(dialogid)//if your using only one dialog this isn't needed but you never know.
        {
	    case 1://our dialog
    	    {
           	switch(listitem)//wich listitem is chosen
        	{
        	    case 0://the first item in the list
        	    {
        	        if(GetPlayerMoney(playerid) < 1) return SendClientMessage(playerid, 0xFFFFFF, "You don't have enough cash.");
        	        GivePlayerMoney(playerid, -1);
        	        SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DRINK_SPRUNK);
        	    }
        	    case 1:
        	    {
        	        if(GetPlayerMoney(playerid) < 2) return SendClientMessage(playerid, 0xFFFFFF, "You don't have enough cash.");
        	        GivePlayerMoney(playerid, -2);
        	        SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DRINK_BEER);
        	    }
        	    case 2:
        	    {
        	        if(GetPlayerMoney(playerid) < 3) return SendClientMessage(playerid, 0xFFFFFF, "You don't have enough cash.");
        	        GivePlayerMoney(playerid, -3);
        	        SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DRINK_WINE);
        	    }
        	}
    	    }
            //from here we added things
            case 2://the new dialog
            {
                 ApplyAnimation(playerid,"BEACH","Lay_Bac_Loop",4.1,1,1,1,1,10);//this will let you relax for 10 seconds
            }
            //till here
	}
    }
    return 1;
}

explanation: this only checks the dialogid because it already checked if you pressed the first button wich is yes. and then applys the animation for 10 seconds

input dialog

This dialog will have a line for input. (as the name implies).

We will make a chatdialog (what is typed in the dialog will appear in the chat).

This is a command created with strcmp, so it belongs under the OnPlayerCommandText callback.

if(!strcmp(cmdtext, "/chat", true))
{
    ShowPlayerDialog(playerid, 3, DIALOG_STYLE_INPUT, "Chat", "Type your chat input here.", "Submit", "Cancel");
    return 1;
}

Let's set-up the response, again..

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(response)// Checking if they pressed the first button, if so continue:
    {
    switch(dialogid)//if your using only one dialog this isn't needed but you never know.
        {
	    case 1:// Our dialog
    	    {
           	switch(listitem)// Checking which listitem was chosen
        	{
        	    case 0: // The first item in the list 
        	    {
        	        if(GetPlayerMoney(playerid) < 1) return SendClientMessage(playerid, 0xFFFFFF, "You don't have enough cash.");
        	        GivePlayerMoney(playerid, -1);
        	        SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DRINK_SPRUNK);
        	    }
        	    case 1: // The second item in the list
        	    {
        	        if(GetPlayerMoney(playerid) < 2) return SendClientMessage(playerid, 0xFFFFFF, "You don't have enough cash.");
        	        GivePlayerMoney(playerid, -2);
        	        SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DRINK_BEER);
        	    }
        	    case 2: // The third item in the list
        	    {
        	        if(GetPlayerMoney(playerid) < 3) return SendClientMessage(playerid, 0xFFFFFF, "You don't have enough cash.");
        	        GivePlayerMoney(playerid, -3);
        	        SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DRINK_WINE);
        	    }
        	}
    	    }
 
            case 2:// The new dialog
            {
                 ApplyAnimation(playerid,"BEACH","Lay_Bac_Loop",4.1,1,1,1,1,10);// This will let you "relax" for 10 seconds. 
            }
            // Here we add new things...
            case 3:
            {
                 if(strlen(inputtext) > 0)
                 {
                     SendPlayerMessageToAll(playerid, inputtext);
                 }
                 else
                 {
                     SendClientMessage(playerid,0xFFFFFFAA,"Your input was too short.");
                 }
            }
            // Until here.
	}
    }
    return 1;
}

As seen, this will print the inputtext string into a chat message for everyone.


credits

tutorial made by Legodude. With parts of freddoX his previous tutorial.

Personal tools
Navigation
Toolbox
In other languages