[Tutorial] How to make a dialog
#1

I creating this because i see some new scripters don't know how to make this so i think will be more usefull for they...
I will learn how to create all type of dialog : msgbox, input, list
Dialog: a box what will apear for player when is created.... he will apear only in center of the screen

So first we must create the dialog
pawn Code:
ShowPlayerDialog(playerid,dialogid,dialog_style,title[],text[],button1[],button2[]);
playerid - id of the player
dialogid - id of the dialog
dialgo_style - the style of dialog: all dialogs type: DIALOG_STYLE_LIST ( list dialogs), DIALOG_STYLE_INPUT ( wite dialog) , DIALOG_STYLE_MSBOX ( only mesage)
title[] - the title of the dialog, text[] the text of the dialog, button1[], button2[] - button 1 and 2 what can be pressed with mouse( for newbies)
example :
pawn Code:
ShowPlayerDialog(playerid,10,DIALOG_STYLE_MSGBOX,"Test Box","Test box","Box","Test");
and this can be used anywhere you want for example when player connect
pawn Code:
public OnPlayerConnect(playerid)      
      {
                    ShowPlayerDialog(playerid,10,DIALOG_STYLE_MSGBOX,"Test Box","Test box","Box","Test");
          return 1;    
      }
pawn Code:
and the callback
     public OnDialogResponse(playerid,dialogid,response,listitem,inputtext)
playerid - id of the player
dialogid - id of the dialog
response - the first button if use ! in front of response this mean the second button..
listitem - items from list this will be something like this
pawn Code:
if(listitem == 0)
first item from the list
inputtext - a string for dialogs

1. DIALOG_STYLE_MSGBOX
now wherever you want to create the function for example

our dialog
Code:
ShowPlayerDialog(playerid,10,DIALOG_STYLE_MSGBOX,"Rules","Do not use hacks","Accept","Decline");
pawn Code:
public OnDialogResponse(playerid,dialogid,response,listitem,inputtext)
      {
                  if(dialogid == 10) //verify if our dialog id is = with dialog created and if exist
                  {
                       if(!response) return Kick(playerid) // if player press Decline the rules he will get kick
                        if(response) // press the Accept button
                          {
                                          GivePlayerMoney(playerid,500); // he will get 500 $ for accepting the rules
                                             SendClientMessage(playerid,-1,"You got + 500 $ for accepting the rules!"); // send him/her a message
                           }

                  }
      }
2. DIALOG_STYLE_INPUT
our dialog
pawn Code:
ShowPlayerDialog(playerid,10,DIALOG_STYLE_INPUT,"Skin Dialog,"Write an existent skin!","Finish","Cancel");
pawn Code:
public OnDialogResponse(playerid,dialogid,response,listitem,inputtext)
            {
                  if(dialogid == 10)
                    {
                             if( ! response) return 1; // in this case if press Cancel button it don't make anything but if write a skin and press Finish him/her skin will be setted!
                            if(response)
                              {
                                        SetPlayerSkin(playerid,inputtext[0]); // set the desired skin by player
                                         SendClientMessage(playerid,-1,"Skin succesfull setted");
                              }
                     }
            }
3.DIALOG_STYLE_LIST

pawn Code:
ShowPlayerDialog(playerid,10,DIALOG_STYLE_LISTS,"Skin List","Skin CJ\nSkin Police","Select","Cancel");
pawn Code:
public OnDialogResponse(playerid,dialogid,response,listitem,inputtext)
            {
                       if(dialogid == 10)
                       {
                                   if(listitem == 0) //first item from list
                                  {
                                         SetPlayerSkin(playerid,0); //set the skn
                                         SendClientMessage(playerid,-1,"Skin cj succesufll setted!");
                                  }
                                     if(listitem == 1) //second item from list
                                    {
                                                SetPlayerSkin(playerid,280);
                                                  SendClientMessage(playerid,-1,"Skin Police succesful setted!");
                                     }
                        }
            }
functions used in this tutorial
Code:
Kick(playerid);
GivePlayerMoney(playerid,cash);
SetPlayerSkin(playerid,skin);
SendClientMessage(playerid,color,message);
ShowPlayerDialog(playerid,dialogid,dialog_style,title[],text[],button1[],button2[]);
Check it on Help section
https://sampwiki.blast.hk/wiki/Category:Scripting_Functions

Ths for reading my tutorial , i hope this will be usefull for begginers , Comment if i did a mistake , or if you understand something, Good luck to learning
Reply
#2

Hello nice Tutorial but if i want to a admins dialog.. so what i need to do??
Reply
#3

+1 for the effort you put in to making the most easiest thing to create into a tutorial!

Not.


Quote:
Originally Posted by Tuntun
View Post
Hello nice Tutorial but if i want to a admins dialog.. so what i need to do??
What? Please rephrase that.
Reply
#4

Can i make a tutorial on this and explain it much more?
Edit: Not much explained
Reply
#5

Oh sorry i was so borred fine..
Can you make what you want to do...because i created this to be te easiliest mod to create a dialog

and for dialogs admin you can make something like this
pawn Code:
CMD:admindialog(playerid,params[]) //zcmd command
{
        if(! IsPlayerAdmin(playerid) ) return SendClientMessage(playerid,-1,"You are not an Admin!"); //verify if he is admin or not and if isn't will send a "You are not an Admin" msg
       else ShowPlayerDialog(...) // your dialog
   return 1; //return the value
}
adding ! to a variable or a function this mean is not for ex:
pawn Code:
if(PlayerInfo[playerid][pAdmin] != 1)
=> this is for roleplay
and this function verify if player admin is not 1.... and for function example is above
pawn Code:
if( ! IsPlayerInAnyVehicle(playerid) ) /for example this verify  if is on foot and if remove ! will verify if is in vehicle
{
        //do something
    return 1; // returning the value
}
Reply
#6

Hey, can you make one that shows the player stats (/stats) and one that shows different rims that can be placed on your car like /rims
Reply
#7

Very Nice and useful tutorial
Just one more thing, please include how to start a new line in DIALOG_STYLE_MSGBOX dialog.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)