Hey undzwar trägt er kein Fahrzeug in die Tabelle ein wen ich ein Fahrzeug gekauft habe.
Hier mal die Codes:
Datenbank Struktur:
Code
CREATE TABLE IF NOT EXISTS `autos` (
`besitzer` varchar(24) NOT NULL,
`model` int(11) NOT NULL,
`x` int(11) NOT NULL,
`y` int(11) NOT NULL,
`z` int(11) NOT NULL,
`r` int(11) NOT NULL,
`nitro` int(11) NOT NULL,
PRIMARY KEY (`besitzer`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=91 ;
Code
forward OnPlayerCarsLoad(playerid);
public OnPlayerCarsLoad(playerid)
{
new num_fields,num_rows;
cache_get_data(num_rows,num_fields,db);
if(!num_rows)return 1;
for(new i=0; i<num_rows; i++)
{
new id=getFreeCarID();
cInfo[id][model]=cache_get_field_content_int(i,"model",db);
cInfo[id][besitzer]=cache_get_field_content_int(i,"besitzer",db);
cInfo[id][c_x]=cache_get_field_content_float(i,"x",db);
cInfo[id][c_y]=cache_get_field_content_float(i,"y",db);
cInfo[id][c_z]=cache_get_field_content_float(i,"z",db);
cInfo[id][c_r]=cache_get_field_content_float(i,"r",db);
cInfo[id][nitro]=cache_get_field_content_int(i,"nitro",db);
cInfo[id][id_x]=CreateVehicle(cInfo[id][model],cInfo[id][c_x],cInfo[id][c_y],cInfo[id][c_z],cInfo[id][c_r],-1,-1,-1);
}
return 1;
}
Alles anzeigen
Code
createPlayerCar(playerid,modelid,Float:x,Float:y,Float:z,Float:r)
{
for(new i=0; i<sizeof(cInfo); i++)
{
if(cInfo[i][id_x]!=0)continue;
cInfo[i][besitzer]=SpielerInfo[playerid][Name];
cInfo[i][c_x]=x;
cInfo[i][c_y]=y;
cInfo[i][c_z]=z;
cInfo[i][c_r]=r;
cInfo[i][nitro]=0;
cInfo[i][model]=modelid;
cInfo[i][id_x] = CreateVehicle(modelid,x,y,z,r,-1,-1,-1);
/*new string[128];
format(string,sizeof(string),"Das Auto cInfo[%i] wurde erstellt.",i);
SendClientMessage(COLOR_RED,string);*/
saveCarToDB(playerid,i);
return 1;
}
return 1;
}
Alles anzeigen
Code
saveCarToDB(playerid,hehe)
{
new query[128];
mysql_format(db, query,sizeof(query),"INSERT INTO autos (besitzer,model,x,y,z,r,nitro) VALUES ('%e','%i','%i','%f','%f','%f','%f','%i')",SpielerInfo[playerid][Name],cInfo[hehe][model],cInfo[hehe][c_x],cInfo[hehe][c_y],cInfo[hehe][c_z],cInfo[hehe][c_r],cInfo[hehe][nitro]);
mysql_function_query(db,query,true,"carSavedToDB","i",hehe);
return 1;
}
Code
loadPlayerCars(playerid)
{
new query[128];
mysql_format(db, query,sizeof(query),"SELECT * FROM autos WHERE besitzer='%e'",SpielerInfo[playerid][Name]);
mysql_function_query(db,query,true,"OnPlayerCarsLoad","i",playerid);
return 1;
}