How to make a dialog display your item.

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.


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

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.

First we declare variables to store bananas, knifes etc, as you already did
pawn Код:
enum pInfo
//Your current data +
new PlayerInfo[MAX_PLAYERS][pInfo]
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.
    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
    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 Код:
Result shall be
str equal to A1B2C3D4
If you do like
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

Thank you so much, Sir !

Forum Jump:

Users browsing this thread: 1 Guest(s)