cars don't load properly
#1

Hello.
My cars don't load properly from mysql.
This is my code
PHP код:
getFreeCarID()
{
    for(new 
i=0i<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=0i<num_rowsi++)
 {
  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);

Reply
#2

Why do you return 0 in the first function?
Reply
#3

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
Why do you return 0 in the first function?
no idea to be honest, got this from a tutorial
Reply
#4

i kind of re-coded it.
this is my new code.
still doesn't work tho.
PHP код:
getFreeCarID()
{
    for(new 
i=0i<sizeof(cInfo); i++)
    {
    if(
cInfo[i][id_x]==0)return i;
    }
    return 
1;
}

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=0i<num_rowsi++)
 {
  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]);

CreateVehicle2(id);

}
return 
1;
}
stock CreateVehicle2(vehicleid)
{
    
cInfo[vehicleid][data1337] = CreateVehicle(cInfo[vehicleid][carmodelid], cInfo[vehicleid][c_x], cInfo[vehicleid][c_y], cInfo[vehicleid][c_z], cInfo[vehicleid][c_r], cInfo[vehicleid][c_color1], cInfo[vehicleid][c_color2], cInfo[vehicleid][c_respawntime]);
    
SetVehicleNumberPlate(cInfo[vehicleid][data1337], cInfo[vehicleid][plate]);
    
AddVehicleComponent(cInfo[vehicleid][data1337], cInfo[vehicleid][cnitro]);
    
SetVehicleToRespawn(vehicleid);
    return 
1;

Reply
#5

fixed - thanks luke.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)