// ModTest will be the string in MySQL stored and VehicleToImplement will be the MODEL to show the components.
new ModTest[100] = "1000,1004,1006,1007,1013,0,1018,1078,0,1087,0,0,0,1143";
new VehicleToImplement = 496;
// This is called from OnGameModeInit because I create the cars from MySQL. 'idx' is the id of the car in MySQL.
CreateVehicleTest(idx)
{
Car[idx][VehicleID] = CreateVehicle(Car[idx][Model], Car[idx][pX], Car[idx][pY], Car[idx][pZ], Car[idx][pA], Car[idx][Color1], Car[idx][Color2], -1);
SetVehicleNumberPlate(Car[idx][VehicleID], VehiclePlate(idx));
SetVehicleHealth(Car[idx][VehicleID], Car[idx][Health]);
UpdateVehicleDamageStatus(Vehicle[idx][VehicleID], 0, 0, 0, 0);
if(Car[idx][Model] == VehicleToImplement)
{
printf("SQL: %i", Car[idx][ID]);
new a[14];
sscanf(ModTest, "p<,>a<i>[14]", a);
for (new s; s < 14; ++s)
{
if (a[s] > 0)
{
AddVehicleComponent(Car[idx][VehicleID], a[s]);
printf("Component: %i", a[s]);
}
}
printf("-------------- END");
}
}
[14:03:54] SQL: 69 [14:03:54] Component: 1000 [14:03:54] Component: 1004 [14:03:54] Component: 1006 [14:03:54] Component: 1007 [14:03:54] Component: 1013 [14:03:54] Component: 1018 [14:03:54] Component: 1078 [14:03:54] Component: 1087 [14:03:54] Component: 1143 [14:03:54] -------------- END
1000, -> Loads 1004, -> Loads 1006, -> Loads 1007, -> Loads 1013, -> Loads 0, -> Stops and is not applying the rest of components 1018, 1078, 0, 1087, 0, 0, 0, 1143
if (a[s] > 0) // <- Here, if component is > 0 will apply the component ant get printed.
{
AddVehicleComponent(Car[idx][VehicleID], a[s]);
printf("Component: %i", a[s]);
}
1000, -> Loads 1004, -> Loads 1006, -> Loads 1007, -> Loads 1013, -> Loads 0, -> Stops and is not applying the rest of components 1018, 1078, 0, 1087, 0, 0, 0, 1143
if (a[s] > 0)
{
AddVehicleComponent(Car[idx][VehicleID], a[s]);
printf("Component: %i", a[s]);
}
// The printf results:
[14:03:54] Component: 1000
[14:03:54] Component: 1004
[14:03:54] Component: 1006
[14:03:54] Component: 1007
[14:03:54] Component: 1013
[14:03:54] Component: 1018
[14:03:54] Component: 1078
[14:03:54] Component: 1087
[14:03:54] Component: 1143
// As you can see, printf prints all the components to install, but the string contains zeros. When the for arrives to a 0, no component is added, logical because the slot is empty but then, the rest of the components installed are not applied.
/*
1000, -> Load, printed and installed.
1004, -> Load, printed and installed.
1006, -> Load, printed and installed.
1007, -> Load, printed and installed.
1013, -> Load, printed and installed.
0, -> Load, not printed and not installed because is 0 (empty).
1018, -> Load, printed and NOT installed
1078, -> Load, printed and NOT installed
0, -> Load, not printed and not installed because is 0 (empty).
1087, -> Load, printed and NOT installed
0, -> Load, not printed and not installed because is 0 (empty).
0, -> Load, not printed and not installed because is 0 (empty).
0, -> Load, not printed and not installed because is 0 (empty).
1143 -> Load, printed and NOT installed
*/
|
I think sscanf it's a simpliest way to save 14 columns in mysql.
Код:
if (a[s] > 0)
{
AddVehicleComponent(Car[idx][VehicleID], a[s]);
printf("Component: %i", a[s]);
}
// The printf results:
[14:03:54] Component: 1000
[14:03:54] Component: 1004
[14:03:54] Component: 1006
[14:03:54] Component: 1007
[14:03:54] Component: 1013
[14:03:54] Component: 1018
[14:03:54] Component: 1078
[14:03:54] Component: 1087
[14:03:54] Component: 1143
// As you can see, printf prints all the components to install, but the string contains zeros. When the for arrives to a 0, no component is added, logical because the slot is empty but then, the rest of the components installed are not applied.
/*
1000, -> Load, printed and installed.
1004, -> Load, printed and installed.
1006, -> Load, printed and installed.
1007, -> Load, printed and installed.
1013, -> Load, printed and installed.
0, -> Load, not printed and not installed because is 0 (empty).
1018, -> Load, printed and NOT installed
1078, -> Load, printed and NOT installed
0, -> Load, not printed and not installed because is 0 (empty).
1087, -> Load, printed and NOT installed
0, -> Load, not printed and not installed because is 0 (empty).
0, -> Load, not printed and not installed because is 0 (empty).
0, -> Load, not printed and not installed because is 0 (empty).
1143 -> Load, printed and NOT installed
*/
The vehicles first are created OnGameModeInit(); because I have to load them from MySQL. |