for loop question - 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: for loop question (
/showthread.php?tid=504544)
for loop question -
MrPlaysino - 04.04.2014
Hello,
I have 4 vehicles in the mysql database. And I want to let them display a dialog box. Now I have the following code:
Код:
new string2[200];
for(new i=0;i!=MAX_AUTOHAUS;i++)
{
if(IsPlayerInRangeOfPoint(playerid,3,AutoHaus[i][aX],AutoHaus[i][aY],AutoHaus[i][aZ]))
{
for(new n = 0; n <sizeof(AutoHausAuto);n++)
{
if(n == 1)
{
format(string2,sizeof string2,"%s",CarName[AutoHausAuto[n][aAutoID] - 400]);
}
else
{
format(string2,sizeof string2,"%s\n%s",string2,CarName[AutoHausAuto[n][aAutoID] - 400]);
}
}
}
}
ShowPlayerDialog(playerid,DIALOG_AUTOHAUS,DIALOG_STYLE_LIST,"Autohaus",string2,"Weiter","");
However, he shows no code. But if I take a 0 everywhere instead of the one he shows only one vehicle.
Here's my remaining code:
Код:
enum AutoHausAA {
aAutoID,
aaID,
aPreis,
aBenzin,
aBenzinArt,
AutoHausID
}
new AutoHausAuto[MAX_AUTOHAUSAUTO][AutoHausAA];
Код:
public LoadAutoHausAutos()
{
new rows, fields, content[MAX_PLAYER_NAME];
cache_get_data(rows, fields);
for(new i = 0; i != rows; i++)
{
cache_get_row(i, 0, content);
AutoHausAuto[i][aaID] = strval(content);
cache_get_row(i, 1, content);
AutoHausAuto[i][aAutoID] = strval(content);
cache_get_row(i, 2, content);
AutoHausAuto[i][aPreis] = strval(content);
cache_get_row(i, 3, content);
AutoHausAuto[i][aBenzin] = strval(content);
cache_get_row(i, 4, content);
AutoHausAuto[i][aBenzinArt] = strval(content);
cache_get_row(i, 5, content);
AutoHausAuto[i][AutoHausID] = strval(content);
}
printf("AutoHausAutos: Es wurden %i AutoHausAutos geladen.", rows); //this is in german!
return 1;
}
Re: for loop question -
CoaPsyFactor - 04.04.2014
Try this, but I'm not sure it will help
Код:
new string2[200];
for(new i = 0;i != MAX_AUTOHAUS;i++) {
if(IsPlayerInRangeOfPoint(playerid, 3, AutoHaus[i][aX], AutoHaus[i][aY], AutoHaus[i][aZ])) {
for(new n = 0;n < sizeof(AutoHausAuto);n++) {
if (n == 1) {
format(string2, 200, "%s", CarName[AutoHausAuto[n][aAutoID] - 400]);
} else {
format(string2, 200, "%s\n%s", string2, CarName[AutoHausAuto[n][aAutoID] - 400]);
}
}
}
}
ShowPlayerDialog(playerid, DIALOG_AUTOHAUS, DIALOG_STYLE_LIST, "Autohaus", string2, "Weiter", "");