Hello.
My cars don't load properly from mysql.
This is my code
My cars don't load properly from mysql.
This is my code
PHP Code:
getFreeCarID()
{
for(new i=0; i<sizeof(cInfo); i++)
{
if(cInfo[i][id_x]==0)return i;
}
return 0;
}
forward onPlayerCarLoad(playerid);
public onPlayerCarLoad(playerid)
{
new num_fields,num_rows;
cache_get_data(num_rows,num_fields,dbhandle);
if(!num_rows)return 1;
for(new i=0; i<num_rows; i++)
{
new id=getFreeCarID();
cInfo[id][carmodelid]=cache_get_field_content_int(id,"model",dbhandle);
cInfo[id][c_x]=cache_get_field_content_float(id,"x",dbhandle);
cInfo[id][c_y]=cache_get_field_content_float(id,"y",dbhandle);
cInfo[id][c_z]=cache_get_field_content_float(id,"z",dbhandle);
cInfo[id][c_r]=cache_get_field_content_float(id,"a",dbhandle);
cInfo[id][c_color1]=cache_get_field_content_int(id,"color1",dbhandle);
cInfo[id][c_color2]=cache_get_field_content_int(id,"color2",dbhandle);
cInfo[id][c_respawntime]=cache_get_field_content_int(id,"autorespawn",dbhandle);
cInfo[id][carteam]=cache_get_field_content_int(id,"carteam",dbhandle);
cache_get_field_content(id, "plate", cInfo[id][plate]);
cache_get_field_content(id, "owner", cInfo[id][carowner]);
CreateVehicle(cInfo[id][carmodelid],cInfo[id][c_x],cInfo[id][c_y],cInfo[id][c_z],cInfo[id][c_r],cInfo[id][c_color1],cInfo[id][c_color2],cInfo[id][c_respawntime]);
cInfo[id][cnitro]=cache_get_field_content_int(i,"nitro",dbhandle);
AddVehicleComponent(id,cInfo[id][cnitro]);
SetVehicleNumberPlate(id,cInfo[id][plate]);
SetVehicleToRespawn(id);
}
return 1;
}
loadPlayerCars(playerid)
{
new query[128],name[35];
GetPlayerName(playerid,name,35);
format(query,sizeof(query),"SELECT * FROM vehicles WHERE owner='%s'",name);
mysql_function_query(dbhandle,query,true,"onPlayerCarLoad","i",playerid);
}