SA-MP Forums Archive
[HELP] Show list in DialogStyleList with 'if' possible strcat - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [HELP] Show list in DialogStyleList with 'if' possible strcat (/showthread.php?tid=531667)



[HELP] Show list in DialogStyleList with 'if' possible strcat - iryston - 13.08.2014

Hi, i want put in Dialog a list with itens of player, for example.
I have Item 1, item 2 and item 4;

and i want show, in dialog.

pawn Код:
if(PlayerHaveEagle == 1)
 {
    format(string,sizeof(string),"Item 1: Eagle (Have)\n");
 }
 else{
    format(string,sizeof(string),"Item 1: Eagle (Don't Have)\n");
 }
 if(PlayerHaveKnife == 1)
 {
    format(string,sizeof(string),"Item 1: Knife (Have)\n");
 }
 else{
    format(string,sizeof(string),"Item 1: Knife (Don't Have)\n");
 }if(PlayerHaveShotgun == 1)
 {
    format(string,sizeof(string),"Item 1: ShotGun (Have)\n");
 }
 else{
    format(string,sizeof(string),"Item 1: ShotGun (Don't Have)\n");
 }
 strcat(str,string);
 ShowPlayerDialog(playerid, DialogWeapons, DIALOG_STYLE_LIST, "Chose a weapon to get:", str, "Select", "Cancel");
Is only a base of my idea, so don't have script complete, i need only base to create correct, this method is correct?

But, how show in dialog it? with strcat?


Re: [HELP] Show list in DialogStyleList with 'if' possible strcat - Jefff - 13.08.2014

Its not ok because you can see only last item, use strcat, char array and packed strings

pawn Код:
static itemstr[128 char];

if(PlayerHaveEagle == 1) itemstr = !"Item 1: Eagle (Have)\n";
else itemstr = !"Item 1: Eagle (Don't Have)\n";

if(PlayerHaveKnife == 1) strcat(itemstr,!"Item 1: Knife (Have)\n");
else strcat(itemstr,!"Item 1: Knife (Don't Have)\n");

if(PlayerHaveShotgun == 1) strcat(itemstr,!"Item 1: ShotGun (Have)");
else strcat(itemstr,!"Item 1: ShotGun (Don't Have)");
show itemstr


Re: [HELP] Show list in DialogStyleList with 'if' possible strcat - iryston - 14.08.2014

Very thanks, work.

But if i want put a string in itemstr? example:
pawn Код:
itemstr = !"Item 1: Eagle (Have) Ammo: %i\n",EagleAmo;
Is wrong, the pawn don't show error, but don't work, how be?

Thanks!


Re: [HELP] Show list in DialogStyleList with 'if' possible strcat - Jefff - 14.08.2014

You need use 'format' for this

pawn Код:
static itemstr[128];

if(PlayerHaveEagle == 1) format(itemstr,sizeof(itemstr),"Item 1: Eagle (Have) Ammo: %i\n",EagleAmo);
else itemstr = "Item 1: Eagle (Don't Have)\n";

if(PlayerHaveKnife == 1) format(itemstr,sizeof(itemstr),"%sItem 1: Knife (Have) Ammo: %i\n",itemstr, KnifeAmo);
else strcat(itemstr,"Item 1: Knife (Don't Have)\n");

if(PlayerHaveShotgun == 1) format(itemstr,sizeof(itemstr),"%sItem 1: ShotGun (Have) Ammo: %i",itemstr, ShotGunAmo);
else strcat(itemstr,"Item 1: ShotGun (Don't Have)");



Re: [HELP] Show list in DialogStyleList with 'if' possible strcat - iryston - 14.08.2014

Perfectly work. Very very thanks man!