SA-MP Forums Archive
On INIT twice, but on cmd once ! - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: On INIT twice, but on cmd once ! (/showthread.php?tid=233506)



On INIT twice, but on cmd once ! - blackwave - 01.03.2011

pawn Код:
Loop(h, MAX_VEHICLES)
    {
          format(file,sizeof(file),local,h);
          if(fexist(file))
          {
               INI_Open(file);
               INI_ReadString(Vehicle[h][Owner], "Owner", MAX_PLAYER_NAME);
               INI_ReadString(Vehicle[h][Plate], "Plate", 32);
               Vehicle[h][Model] = INI_ReadInt("Model");
               Vehicle[h][Color1] = INI_ReadInt("Color1");
               Vehicle[h][Color2] = INI_ReadInt("Color2");
               Vehicle[h][ID] = INI_ReadInt("ID");
               Vehicle[h][x] = INI_ReadFloat("x");
               Vehicle[h][y] = INI_ReadInt("y");
               Vehicle[h][z] = INI_ReadInt("z");
               CreateVehicle(Vehicle[h][Model],Vehicle[h][x],Vehicle[h][y],Vehicle[h][z],Vehicle[h][a],Vehicle[h][Color1],Vehicle[h][Color2],500000);
               Owned[h] = 1;
               SetVehicleNumberPlate(h,Vehicle[h][Plate]);
               hcount++;
          }
           
    }
    printf(" * Amount of loaded vehicles: %d * ",hcount);
I put for show all owners names on the printf, and detected twice my name, as I have two cars. But on my command, it just detects there were found a single car with my name, as I made a count and put for each time it finds my name:
pawn Код:
for(new v; v < MAX_VEHICLES; v++)
    {
        if(!strcmp(Vehicle[v][Owner],GetMyName(playerid),true))
        {
            contagem++;
            printf("%i",contagem); // Says just founds 1 vehicles with my owner name
            format(string,sizeof(string),""#red"Name: %s | Model: %d | ID: %d\n",VehicleNames[Vehicle[v][Model]-400],Vehicle[v][Model],Vehicle[v][ID]);
            return ShowPlayerDialog(playerid,ME_DIALOG,DIALOG_STYLE_MSGBOX,""#green"Your vehicles",string,"Ok","");
           
        }
    }
What may be wrong?


Re: On INIT twice, but on cmd once ! - JaTochNietDan - 01.03.2011

That would be because when it does find names that matchup, then you're returning a value in the loop, which will stop the loop from running past the first names that match. Just take out the return, like so:
pawn Код:
for(new v; v < MAX_VEHICLES; v++)
{
    if(!strcmp(Vehicle[v][Owner],GetMyName(playerid),true))
    {
        contagem++;
        printf("%i",contagem); // Says just founds 1 vehicles with my owner name
        format(string,sizeof(string),""#red"Name: %s | Model: %d | ID: %d\n",VehicleNames[Vehicle[v][Model]-400],Vehicle[v][Model],Vehicle[v][ID]);
        ShowPlayerDialog(playerid,ME_DIALOG,DIALOG_STYLE_MSGBOX,""#green"Your vehicles",string,"Ok","");
    }
}
There's another problem with this of course, the ShowPlayerDialog function should be outside of the loop. Test it and you will see why.


Re: On INIT twice, but on cmd once ! - blackwave - 01.03.2011

I simply put return becuz it was giving me:
pawn Код:
The command /status doesn't exists
But it does run, and just show now ID 1, model: 559, name: JESTER

It'd be like UNKNOWN COMMAND error, which means command is broken. Almost the variable of counting is printing 3 times:
Код:
1
2
3
Also if I simply put a return as before or a return 1; , it works without the broken message, but just shows ID 0


Re: On INIT twice, but on cmd once ! - JaTochNietDan - 01.03.2011

Unknown command does not mean the command is broken, it means that you do not return a value in the command, which means it goes to the end of the OnPlayerCommandText function and hits your return 0, which tells the SA-MP client to send that default Unknown Command message. To fix this you should at a return 1; at the very end of the command. Also like I said, you need to move the ShowPlayerDialog function out of the loop. My posts have to be read in full to understand them, and if you don't understand, please say so, otherwise the help I'm providing is useless!


Re: On INIT twice, but on cmd once ! - blackwave - 01.03.2011

Well, that's simply impossible. Never happened before. I've tried with client MSG and has shown both vehicles, but this the message there. And it has two return values. Also tried with dcmd and zcmd. With a return value, shows simply nothing:
pawn Код:
dcmd_sta(playerid, params[])
{
    new string[200];
    new model;
    for(new v; v < MAX_VEHICLES; v++)
    {
      if(!strcmp(Vehicle[v][Owner],GetMyName(playerid),true))
      {
        contagem++;
        printf("%i",contagem); // Says just founds 1 vehicles with my owner name
        format(string,sizeof(string),""#red"Name: %s | Model: %d | ID: %d\n",VehicleNames[Vehicle[v][Model]-400],Vehicle[v][Model],Vehicle[v][ID]);


      }
     



    }
    return MsgForAll(color,string);
}



Re: On INIT twice, but on cmd once ! - blackwave - 02.03.2011

Just forget this topic, since none helps.