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 :
ASCII value of A = 65
char equivalent to 90 = Z