[Tutorial] Detailing in dialogs - Easy For Newbies
#1

Hello guys,

today i'm going to show you how to detail anything you want in any dialog! That's very easy but yet some people do not know how to do so. So, i made this tutorial to show them some examples of it. So, without wasting times, we'll start our tutorial!

STEP 1 - USING FORMAT


So, about using formats, it's really very simple. I'll show you an example of it right now.

PHP код:
CMD:name(playerid,params[])
{
    new 
string[128], /*This is to define the string and the size of it*/ pName[MAX_PLAYER_NAME]; // Name variable
    
GetPlayerName(playeridpNamesizeof(pName)); // Getting the player name
    
format(stringsizeof(string), "Your name is %s with ID %i !"pNameplayerid); // Formatting the message
    
SendClientMessage(playerid, -1string); // Sending the message to the player
    
return 1;

You see, it's very simple. But now, instead of using SendClientMessage, we will change it to ShowPlayerDialog!

Format explained more easily here!

STEP 2 - SHOWPLAYERDIALOG


So, now we will change the same thing to showplayerdialog!

PHP код:
CMD:name(playerid,params[])
{
    new 
string[128], /*This is to define the string and the size of it*/ pName[MAX_PLAYER_NAME]; // Name variable
    
GetPlayerName(playeridpNamesizeof(pName)); // Getting the player name
    
format(stringsizeof(string), "Your Name: %s \n Your ID: %i"pNameplayerid); // Formatting the message
    
ShowPlayerDialog(playerid21DIALOG_STYLE_MSGBOX"EXAMPLE" string "Ok"""); // ShowPlayerDialog
    
return 1;

So now, we have formatted it to ShowPlayerDialog!

Additional Note: While formatting to message, use \n for the dialog to skip one line! And also instead of usig DIALOG_STYLE_MSGBOX you can use any type of dialog style, this doesn't require only DIALOG_STYLE_MSGBOX!

STEP 3 - STRCAT


So, we use strcat to make really long dialog without making them crashing, strcat has also other more purposes.

Here, strcat is more explained!

PHP код:
CMD:name(playerid,params[])
{
    new 
Dialog[128], /*This is to define the string and the size of it*/ pName[MAX_PLAYER_NAME]; // Name variable
    
GetPlayerName(playeridpNamesizeof(pName)); // Getting the player name
    
format(Dialogsizeof(Dialog), "Your Name: %s "pName); // Strcat
    
format(Dialogsizeof(Dialog), "Your ID: %i "playerid); // Strcat
    // You can add more formats here
    
ShowPlayerDialog(playerid21DIALOG_STYLE_MSGBOX"EXAMPLE" Dialog "Ok"""); // ShowPlayerDialog
    
return 1;

STEP 4 - DEFINE THEM


So, now we are going to define the IDs of the dialogs we are going to be using. Defining dialogs are important! If we do not define them, we can make another dialog and use an already defined id for a dialog. So, let's proceed in for more information.

PHP код:
enum 
{
    
DIALOG_NAME
}
#define DIALOG_NAME 1
 
CMD:name(playerid,params[])
{
    new 
string[128], /*This is to define the string and the size of it*/ pName[MAX_PLAYER_NAME]; // Name variable
    
GetPlayerName(playeridpNamesizeof(pName)); // Getting the player name
    
format(stringsizeof(string), "Your Name: %s \n Your ID: %i"pNameplayerid); // Formatting the message
    
ShowPlayerDialog(playeridDIALOG_NAMEDIALOG_STYLE_MSGBOX"EXAMPLE" string "Ok"""); // ShowPlayerDialog and using defined dialog IDs
    
return 1;

END OF TUTORIAL


Credits

Karan007 - Created this tutorial
SA-MP Team - Created SA-MP
****** - Sscanf
Zeex - ZCMD
PawnHunter - Strcat suggestion
MartinSwag - Defining suggestion
TheBetaFox - Strcat tutorial


Enjoy!
Reply
#2

Nice efforts, +rep.
Reply
#3

Nice tutorial, But actually you should add Strcat to your tutorial, Its very use full for very big dialogs (car dealership / top players )
Reply
#4

Nice tutorial. I would recommend using an enum to store dialog names. If you just use an ID, there's a chance you'll accidentally use that ID again and that can be confusing.



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

- It's possible to declare just one string variable and re-format it multiple times (So there's no need for string2, string3 etc. unless you know one string might become longer than the other one. For example, the string length of a textdraw can be 1024 characters and the string in SendClientMessage can only be up to 144 characters)

Example:
Код:
format(string, sizeof(string), "You've been kicked by Admin %s | Reason: %s", PlayerInfo[playerid][Name], reason);
SendClientMessage(targetid, -1, string);
KickEx(targetid);
format(string, sizeof(string), "You've kicked %s | Reason: %s", PlayerInfo[targetid][Name], reason);
SendClientMessage(playerid, -1, string);
format(string, sizeof(string), "%s has been kicked by Admin %s | Reason: %s", PlayerInfo[targetid][Name], PlayerInfo[playerid][Name], reason);
SendClientMessageToAll(-1, string);
https://sampwiki.blast.hk/wiki/Limits
Reply
#5

@Zeus - Thank you.

@PawnHunter - Thank you, suggestion added to the tutorial.

@MartinSwag - I knew it already, but thank you, your suggestion has been added to the tutorial.

-Thank you,
~Karan007.
Reply
#6

Useful tutorials for newbies ... Good Job
Reply
#7

Thank you!
Reply
#8

Nice one Karan007
Reply
#9

Thank you!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)