stock sql_LoadAllCars() {
for(new i = 0; i < MAX_VEHICLES; i++) {
if(IsValidVehicle(i)) {
DestroyVehicle(i);
DestroyDynamic3DTextLabel(vInfo[i][CarText]);
}
}
mysql_tquery(mysql, "SELECT * FROM `cars`", "OnVehicleLoad", "");
}
public OnVehicleLoad() {
new rows, fields;
cache_get_data(rows, fields, mysql);
if(rows) {
for(new i=0; i < rows; i++) {
new carid = CreateVehicle(cache_get_field_content_int(i,"carid"),cache_get_field_content_float(i,"X"),cache_get_field_content_float(i,"Y"),cache_get_field_content_float(i,"Z"),cache_get_field_content_float(i,"A"),cache_get_field_content_int(i,"color"),cache_get_field_content_int(i,"color2"),0,cache_get_field_content_int(i,"siren"));
vInfo[carid][CarID] = cache_get_field_content_int(i,"ID");
vInfo[carid][CModel] = cache_get_field_content_int(i,"carid");
vInfo[carid][VCol1] = cache_get_field_content_int(i,"color");
vInfo[carid][VCol2] = cache_get_field_content_int(i,"color2");
vInfo[carid][VX] = cache_get_field_content_float(i,"X");
vInfo[carid][VY] = cache_get_field_content_float(i,"Y");
vInfo[carid][VZ] = cache_get_field_content_float(i,"Z");
vInfo[carid][VA] = cache_get_field_content_float(i,"A");
vInfo[carid][VSiren] = cache_get_field_content_int(i,"siren");
vInfo[carid][VTeam] = cache_get_field_content_int(i,"team");
vInfo[carid][VPrice] = cache_get_field_content_int(i,"price");
vInfo[carid][ForSale] = cache_get_field_content_int(i,"forsale");
vInfo[carid][VOwner] = cache_get_field_content_int(i,"Owner");
new Sname[50],xName[55];
cache_get_field_content(i,"OwnerName",Sname);
strcpy(xName,Sname,60);
vInfo[carid][VHealth] = 1000.00;
new string[64];
if(vInfo[carid][ForSale] == 0) format(string,sizeof(string),"{FFFFFF}SQL ID: {FF0000}%i\n{FFFFFF}Vehicle Team: {FF0000}%s",vInfo[carid][CarID],TeamInfo[vInfo[carid][VTeam]][TeamName]);
else if(vInfo[carid][ForSale] == 1) format(string,sizeof(string),"{FF0000}For sale: {FFFFFF}%i$",vInfo[carid][VPrice]);
vInfo[carid][CarText] = CreateDynamic3DTextLabel(string, COLOR_RED,vInfo[carid][VX],vInfo[carid][VY],vInfo[carid][VZ] , 10.0, INVALID_PLAYER_ID, carid, 0, -1, -1, -1, 100.0);
if(vInfo[carid][VOwner] >= 1) {
format(string,sizeof(string),"{FF0000}Owner: {FFFFFF}%s",xName);
UpdateDynamic3DTextLabelText(vInfo[carid][CarText],COLOR_RED,string);
}
}
}
}
mysql_log(LOG_ERROR | LOG_WARNING | LOG_DEBUG);
mysql_log(LOG_ERROR | LOG_WARNING);
To be more precise: it slows down the queries when LOG_DEBUG is used. You can have it as:
pawn Код:
TIP: Don't create variables inside loops, move them outside. |