How to make a dialog display your item.
#1

I want it so i buy forexample a banana, and then i get 1, i am thinking like PlayerInfo[playerid][banana] = 1;

And when i type /craft i want this banana to show up. How?

And if you can explain this too:

After the banana show up i want it like we click the banana, then the same dialog comes up again, and you can forexample click the knife.

Thanks!
Reply
#2

Show it like this:

pawn Код:
format(info,sizeof(info),"Bananas: %d",PlayerInfo[playerid][banana]);
when you show the dialog, use the formatted string "info" as your text.
then under OnDialogResponse, make a response for the dialogid shown, and add a line, showplayerdialog, that shows a dialog with your knife
Reply
#3

Could you post an example please, about how i use the strings and how i use them in a dialog box, i am new to strings.
Reply
#4

First we declare variables to store bananas, knifes etc, as you already did
pawn Код:
enum pInfo
{
//Your current data +
    banana,
    knife
}
new PlayerInfo[MAX_PLAYERS][pInfo]
PlayerInfo[playerid][banana];
PlayerInfo[playerid][knife];
Now, when player gets a banana or a knife
pawn Код:
++PlayerInfo[playerid][banana]; //for banana
++PlayerInfo[playerid][knife];//for knife
Now, to show him dialog
pawn Код:
//In the command where you want to display them
new str[150] = " ";//Initialize str with a space.
switch(PlayerInfo[playerid][banana]
{
    case 0: break;//If he dont hava banana, it wont show in dialog
    default : format(str,sizeof(str),"%s\nBanana's : %d",str,PlayerInfo[playerid][banana]);
}
//Now silimarly for knife
switch(PlayerInfo[playerid][knife]
{
    case 0: break;//If he dont hava knife, it wont show in dialog
    default : format(str,sizeof(str),"%s\nKnife : %d",str,PlayerInfo[playerid][knife]);
}
//Now if he dont have anything
switch(PlayerInfo[playerid][banana] + PlayerInfo[playerid][knife]/*And all other variables if you need*/)
{
    case 0: format(str,sizeof(str),"You dont have any thing");
}

ShowPlayerDialog(playerid,1891/*Any random number*/,DIALOG_STYLE_MSGBOX,"Items",str,"OK","");
What the
Код:
format(str,sizeof(str),"%s\nKnife : %d",str,PlayerInfo[playerid][knife]);
does is
  • It replaces the first %s with the first argument (string)
    Therefore, str gets copied in place of %s.
  • And second %d with second argument.
    And, the value of Player's Knife's gets copied in %d.
For Example
pawn Код:
format(str,sizeof(str),"%s%d%s%d%s%d","A",1,"B",2,"C",3,"D",4);
Result shall be
Код:
str equal to A1B2C3D4
If you do like
Код:
format(str,sizeof(str),"%d%s","A",90)
Compiler will find ASCII value of "A" and put it in place of %d.
Similarly 90 shall be converted to it's equivalent char

Result :
Код:
string is now 65Z
ASCII value of A = 65
char equivalent to 90 = Z
Reply
#5

Thank you so much, Sir !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)