28.08.2015, 02:20
Why did not you declare a local variable new result[256]; as a string and use it as a global? I do not see it, but I see new stringcar[256]; which is generally useless.
PHP код:
enum vehicleE {
vVehicleModelID,
Float: vVehiclePosition[3],
Float: vVehicleRotation,
vVehicleGroup,
vVehicleJob,
vVehicleGroupRank,
vVehicleColour[2],
vVehicleScriptID,
vVehicleNumber[8+1],
}
public IniVehs()
{
new Cache: result5 = mysql_query (handle, "SELECT * FROM `vehicles` ORDER BY `vehicles`.`vehicleID` ASC");
new // <- Refactoring
success = 1,
x,
result[256] // Added local varible
;
for ( new i, j = cache_get_row_count ( ); i != j; ++i )
{
cache_get_field_content(i, "vehicleID", result); x = strval(result);
if(systemVariables[vehicleCounts][0] + systemVariables[vehicleCounts][1] + systemVariables[vehicleCounts][2] < MAX_VEHICLES)
{
cache_get_field_content(i, "vehicleModelID", result); vehicleVariables[x][vVehicleModelID] = strval(result);
cache_get_field_content(i, "vehiclePosX", result); vehicleVariables[x][vVehiclePosition][0] = floatstr(result);
cache_get_field_content(i, "vehiclePosY", result); vehicleVariables[x][vVehiclePosition][1] = floatstr(result);
cache_get_field_content(i, "vehiclePosZ", result); vehicleVariables[x][vVehiclePosition][2] = floatstr(result);
cache_get_field_content(i, "vehiclePosRotation", result); vehicleVariables[x][vVehicleRotation] = floatstr(result);
cache_get_field_content(i, "vehicleGroup", result); vehicleVariables[x][vVehicleGroup] = strval(result);
cache_get_field_content(i, "vehicleGroupRank", result); vehicleVariables[x][vVehicleGroupRank] = strval(result);
cache_get_field_content(i, "vehicleJob", result); vehicleVariables[x][vVehicleJob] = strval(result);
cache_get_field_content(i, "vehicleCol1", result); vehicleVariables[x][vVehicleColour][0] = strval(result);
cache_get_field_content(i, "vehicleCol2", result); vehicleVariables[x][vVehicleColour][1] = strval(result);
cache_get_field_content(i, "vehicleNumberPlate", result); format(vehicleVariables[x][vVehicleNumber], 9, "%s", result);
if(vehicleVariables[x][vVehicleColour][0] < 0) {
vehicleVariables[x][vVehicleColour][0] = random(126);
}
if(vehicleVariables[x][vVehicleColour][1] < 0) {
vehicleVariables[x][vVehicleColour][1] = random(126);
}
format(stringcar, 256, "Group %d",vehicleVariables[x][vVehicleGroup]);
vehicleVariables[x][vVehicleScriptID] = CreateVehicle(vehicleVariables[x][vVehicleModelID], vehicleVariables[x][vVehiclePosition][0], vehicleVariables[x][vVehiclePosition][1], vehicleVariables[x][vVehiclePosition][2], vehicleVariables[x][vVehicleRotation], vehicleVariables[x][vVehicleColour][0], vehicleVariables[x][vVehicleColour][1], 300);
if(vehicleVariables[x][vVehicleGroup] >= 1)
{
SetVehicleNumberPlate(x, vehicleVariables[x][vVehicleNumber]);
}
systemVariables[vehicleCounts][0]++;
}
else
{
success = 0;
printf("ERROR: Vehicle limit reached (MODEL %d, VEHICLEID %d, MAXIMUM %d, TYPE STATIC) [01x08]", vehicleVariables[x][vVehicleModelID], x, MAX_VEHICLES);
}
}
cache_delete(result5);
if(success) printf("[script] %d vehicles loaded.", systemVariables[vehicleCounts][0]);
return 1;
}