25.06.2015, 21:08
Is there anyone who can teach me more about formating strings Ive used wikipedia but I dont get it, I really need somone to explain it better.
%i Integer (whole number)
%d Integer (whole number).
%s String
%f Floating-point number (Float: tag)
%c ASCII character
%x Hexadecimal number
%b Binary number
%% Literal '%'
new message[128]; // '[128]' = the lenght of the message. In this case its 128. (You can use less or more. E.g. 64 or 32 or 256)...
new Number = 9; // So we made new number which is 9.
format(message,sizeof(message),"The number is %d",Number); // Okay so lets explain the part in (). I think you now know what is 'message' so lets skip just 1. part. 2. part = 'sizeof(message)' = Here are u checking the message size so its 128. Instead of 'sizeof(message)' you can write 128. 'The number is %d",Number' = Okay so %d means integer so we use numbers. You defined up there number 9 so it will send message: "The number is 9". You must use %d or %i with numbers or it won't display it.
SendClientMessage(playerid,-1,message); // I think you know this part.
new message[128]; // You learned what this is.
new PlayerName[MAX_PLAYER_NAME]; // Okay so as you can se we created new 'PlayerName' because we are gonna use it in message. 'MAX_PLAYER_NAME' = This represents the maximum player's name which can be displayed. Instead of that you can also write '64' or '32'.
GetPlayerName(playerid,PlayerName,sizeof(PlayerName)); // okay so this is a function which takes player's name as you can see.
format(message,128,"My name is %s",PlayerName(playerid)); // This is a example with string. So i made message "My name is Dino",and i displayed it with %s because it is a string (text). 'PlayerName(playerid)' = This is what we used in GetPlayerName function where we discovered our name. And we had to put it here to send us our name.
SendClientMessage(playerid,-1,message);
// First of all, we need a public variable, so put this at the top of your script:
new gender[MAX_PLAYERS];
// If you have created dialogs already, you probably don't need this...
// But it is a good way to keep track of your dialog IDs. It works almost like #define but easier.
enum
{
DIALOG_INFO,
DIALOG_SEX,
}
// Then, show the list dialog for player, inside your command, or where ever you want.
ShowPlayerDialog(playerid, DIALOG_SEX, DIALOG_STYLE_LIST, "Select gender:","Male\n\Female","Select", "Cancel");
// This goes anywhere outside other functions and is reachable through the entire script.
getsex(playerid) // I had to :D
{
new gend[10];
if(!gender[playerid]) gend = "Male"; // '!' means "NOT", so this means 'if zero set string to Male'
if(gender[playerid]) gend = "Female"; // Means 'if one set string to Female'
return gend; // returns the string, so you can format your string with getsex(playerid)
}
// Now, when the player responds with a result, we will need to store this.
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case DIALOG_SEX:
{
if(response)
{
if(listitem == 1){ gender[playerid] = 1; } // Picked 'Female'
// The variable is already 0, so we don't have to specify that should he pick 'Male'.
// You can move this if gender is not the last step.
new str[128],playername[MAX_PLAYER_NAME];
GetPlayerName(playerid,playername,sizeof(playername));
// Here, we format the string you were talking about. %s is for string.
format(str,sizeof(str),"Name: %s\nSex: %s",playername,getsex(playerid));
ShowPlayerDialog(playerid,DIALOG_INFO,DIALOG_STYLE_MSGBOX,"Player Information",str,"OK","Cancel");
}
}
}
return 1;
}
stock MaleFemale(gender) { new string[8]; if(gender == 1) { format(string, sizeof(string), "Male"); return string; } else if(gender == 2) { format(string, sizeof(string), "Female"); return string; } format(string, sizeof(string), "None"); // If the gender number is neither 1 or 2 return string; }
new string[128]; format(string, sizeof(string), "Your current gender is %s!", MaleFemale(1)); // You would replace the number 1 by whatever variable saves your player's gender. SendClientMessage(playerid, COLOR_WHITE, string);