Guten Tag,
Wenn ich die Positionen der Cars aus der Datenbank lese, sind sie ja noch ein String.
Wenn ich sie dann mit floatstr in eine Float konvertiere, verändert sich die Zahl.
Beispielsweise hab ich mir den String und den konvertierten String werte ausgeben lassen.
Datenbank Einträge:
X = 1134.621
Y = 13.4
Z = 180.0
printf("%s | %s | %s",vx,vy,vz);
printf("%f | %f | %f",floatstr(vx),floatstr(vy),floatstr(vz));
Ausgegeben wird:
1134.621 | 13.4 | 180.0
1134.620971 | 13.399999 | 180.000000
Hier mein kompletter Stock:
stock LoadVehicleFromDatabase(playerid,fahrzeugNumber)
{
new query[512];
new vid;
format(query,sizeof(query),"SELECT * FROM `fahrzeuge` WHERE `name`='%s'",sInfo[playerid][name]);
new DBResult:result = db_query(Database,query);
for(new i = 1; i<fahrzeugNumber;i++)
{
db_next_row(result);
}
new modelid,vx[30],vy[30],vz[30],rotation[30],color1,color2;
db_get_field_assoc(result,"modelid",query,3);
modelid = strval(query);
db_get_field_assoc(result,"x",vx,30);
db_get_field_assoc(result,"y",vy,30);
db_get_field_assoc(result,"z",vz,30);
db_get_field_assoc(result,"rotation",rotation,30);
db_get_field_assoc(result,"color1",query,3);
color1 = strval(query);
db_get_field_assoc(result,"color2",query,3);
color2 = strval(query);
printf("%s | %s | %s",vx,vy,vz);
printf("%f | %f | %f",floatstr(vx),floatstr(vy),floatstr(vz));
vid = CreateVehicle(modelid,floatstr(vx),floatstr(vy),floatstr(vz),floatstr(rotation),color1,color2,0);
db_free_result(result);
return vid;
}
{
new query[512];
new vid;
format(query,sizeof(query),"SELECT * FROM `fahrzeuge` WHERE `name`='%s'",sInfo[playerid][name]);
new DBResult:result = db_query(Database,query);
for(new i = 1; i<fahrzeugNumber;i++)
{
db_next_row(result);
}
new modelid,vx[30],vy[30],vz[30],rotation[30],color1,color2;
db_get_field_assoc(result,"modelid",query,3);
modelid = strval(query);
db_get_field_assoc(result,"x",vx,30);
db_get_field_assoc(result,"y",vy,30);
db_get_field_assoc(result,"z",vz,30);
db_get_field_assoc(result,"rotation",rotation,30);
db_get_field_assoc(result,"color1",query,3);
color1 = strval(query);
db_get_field_assoc(result,"color2",query,3);
color2 = strval(query);
printf("%s | %s | %s",vx,vy,vz);
printf("%f | %f | %f",floatstr(vx),floatstr(vy),floatstr(vz));
vid = CreateVehicle(modelid,floatstr(vx),floatstr(vy),floatstr(vz),floatstr(rotation),color1,color2,0);
db_free_result(result);
return vid;
}
MfG JumperKenny