MySQL CarKey laden

Wichtiger Hinweis: Bitte ändert nicht manuell die Schriftfarbe auf schwarz sondern belasst es bei der Standardeinstellung. Somit tragt ihr dazu bei dass euer Text auch bei Verwendung unseren dunklen Forenstils noch lesbar ist!

Tipp: Ihr wollt längere Codeausschnitte oder Logfiles bereitstellen? Benutzt unseren eigenen PasteBin-Dienst Link
  • Hallo Beadfish-Community,


    ich bin derzeitig am versuchen das private Auto in MySQL zu speichern und auch zu laden...
    Das Problem was ich derzeitig habe, der Spieler hat ein Auto aber es werden 4 Autos gespawnt obwohl
    der Spieler nur ein Auto in der Datenbank hat...


    //Habe es versucht das auch das CarKey sofort geladen wird...

    forward LoadPrivatAuto(playerid);
    public LoadPrivatAuto(playerid)
    {
    new query[128],spielerautoname[MAX_PLAYER_NAME];
    GetPlayerName(playerid,spielerautoname,sizeof(spielerautoname));
    format(query,sizeof(query),"SELECT * FROM autos WHERE Name='%s'",Dtc_PlayerKey[playerid], spielerautoname);
    mysql_function_query(dbhandle,query,true,"OnPlayerCarLogin","i",playerid);
    return 1;
    }


    Auto laden:

    Function OnPlayerCarLogin(playerid)
    {
    for(new x = 0; x < MaxVeh; x++)
    {
    if(!Dtc_PlayerHaveCar[playerid][x])
    {
    Dtc_PlayerHaveCar[playerid][x] = 1;
    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++)
    if(num_rows == 1)
    {
    Dtc_PlayerKey[playerid] = cache_get_field_content_int(0,"CarKey",dbhandle);
    PlayerCar[playerid][x][CarId] = cache_get_field_content_int(0,"CarId",dbhandle);
    PlayerCar[playerid][x][CarModel] = cache_get_field_content_int(0,"CarModel",dbhandle);
    PlayerCar[playerid][x][CarPos_x] = cache_get_field_content_float(0,"CarPos_x",dbhandle);
    PlayerCar[playerid][x][CarPos_y] = cache_get_field_content_float(0,"CarPos_y",dbhandle);
    PlayerCar[playerid][x][CarPos_z] = cache_get_field_content_float(0,"CarPos_z",dbhandle);
    PlayerCar[playerid][x][CarRotate] = cache_get_field_content_float(0,"CarRotate",dbhandle);
    PlayerCar[playerid][x][CarNitro] = cache_get_field_content_int(0,"CarNitro",dbhandle);
    PlayerCar[playerid][x][CarHyd] = cache_get_field_content_int(0,"CarHyd",dbhandle);
    PlayerCar[playerid][x][CarAusp] = cache_get_field_content_int(0,"CarAusp",dbhandle);
    PlayerCar[playerid][x][CarSideL] = cache_get_field_content_int(0,"CarSideL",dbhandle);
    PlayerCar[playerid][x][CarSideR] = cache_get_field_content_int(0,"CarSideR",dbhandle);
    PlayerCar[playerid][x][CarFB] = cache_get_field_content_int(0,"CarFB",dbhandle);
    PlayerCar[playerid][x][CarRB] = cache_get_field_content_int(0,"CarRB",dbhandle);
    PlayerCar[playerid][x][CarSpoiler] = cache_get_field_content_int(0,"CarSpoiler",dbhandle);
    PlayerCar[playerid][x][CarRoof] = cache_get_field_content_int(0,"CarRoof",dbhandle);
    PlayerCar[playerid][x][CarHood] = cache_get_field_content_int(0,"CarHood",dbhandle);
    PlayerCar[playerid][x][CarVents] = cache_get_field_content_int(0,"CarVents",dbhandle);
    PlayerCar[playerid][x][CarLamps] = cache_get_field_content_int(0,"CarLamp",dbhandle);
    PlayerCar[playerid][x][CarPJ] = cache_get_field_content_int(0,"CarPJ",dbhandle);
    PlayerCar[playerid][x][CarC1] = cache_get_field_content_int(0,"CarC1",dbhandle);
    PlayerCar[playerid][x][CarC2] = cache_get_field_content_int(0,"CarC2",dbhandle);
    PlayerCar[playerid][x][CarArrest] = cache_get_field_content_int(0,"CarArrest",dbhandle);
    PlayerCarSpawn(playerid,x);
    }
    }
    }
    return 1;
    }


    Auto Spawn:

    Function PlayerCarSpawn(playerid,Slot)
    {
    if(IsPlayerConnected(playerid))
    {
    if(Dtc_PlayerHaveCar[playerid][Slot])
    {
    PlayerCar[playerid][Slot][CarId] = CreateVehicle(PlayerCar[playerid][Slot][CarModel],PlayerCar[playerid][Slot][CarPos_x],PlayerCar[playerid][Slot][CarPos_y],PlayerCar[playerid][Slot][CarPos_z],PlayerCar[playerid][Slot][CarRotate],PlayerCar[playerid][Slot][CarC1],PlayerCar[playerid][Slot][CarC2], 60000);/*vehicle spawn*/
    ChangeVehicleColor(PlayerCar[playerid][Slot][CarId],PlayerCar[playerid][Slot][CarC1],PlayerCar[playerid][Slot][CarC2]);
    if(PlayerCar[playerid][Slot][CarPJ] >= 0) {ChangeVehiclePaintjob(PlayerCar[playerid][Slot][CarId],PlayerCar[playerid][Slot][CarPJ]);}
    if(PlayerCar[playerid][Slot][CarNitro] != 0) {AddVehicleComponent(PlayerCar[playerid][Slot][CarId],PlayerCar[playerid][Slot][CarNitro]);}
    if(PlayerCar[playerid][Slot][CarHyd] != 0) {AddVehicleComponent(PlayerCar[playerid][Slot][CarId],PlayerCar[playerid][Slot][CarHyd]);}
    if(PlayerCar[playerid][Slot][CarWheel] != 0) {AddVehicleComponent(PlayerCar[playerid][Slot][CarId],PlayerCar[playerid][Slot][CarWheel]);}
    if(PlayerCar[playerid][Slot][CarAusp] != 0) {AddVehicleComponent(PlayerCar[playerid][Slot][CarId],PlayerCar[playerid][Slot][CarAusp]);}
    if(PlayerCar[playerid][Slot][CarSideL] != 0) {AddVehicleComponent(PlayerCar[playerid][Slot][CarId],PlayerCar[playerid][Slot][CarSideL]);}
    if(PlayerCar[playerid][Slot][CarSideR] != 0) {AddVehicleComponent(PlayerCar[playerid][Slot][CarId],PlayerCar[playerid][Slot][CarSideR]);}
    if(PlayerCar[playerid][Slot][CarFB] != 0) {AddVehicleComponent(PlayerCar[playerid][Slot][CarId],PlayerCar[playerid][Slot][CarFB]);}
    if(PlayerCar[playerid][Slot][CarRB] != 0) {AddVehicleComponent(PlayerCar[playerid][Slot][CarId],PlayerCar[playerid][Slot][CarRB]);}
    if(PlayerCar[playerid][Slot][CarSpoiler] != 0) {AddVehicleComponent(PlayerCar[playerid][Slot][CarId],PlayerCar[playerid][Slot][CarSpoiler]);}
    if(PlayerCar[playerid][Slot][CarRoof] != 0) {AddVehicleComponent(PlayerCar[playerid][Slot][CarId],PlayerCar[playerid][Slot][CarRoof]);}
    if(PlayerCar[playerid][Slot][CarHood] != 0) {AddVehicleComponent(PlayerCar[playerid][Slot][CarId],PlayerCar[playerid][Slot][CarHood]);}
    if(PlayerCar[playerid][Slot][CarVents] != 0) {AddVehicleComponent(PlayerCar[playerid][Slot][CarId],PlayerCar[playerid][Slot][CarVents]);}
    if(PlayerCar[playerid][Slot][CarLamps] != 0) {AddVehicleComponent(PlayerCar[playerid][Slot][CarId],PlayerCar[playerid][Slot][CarLamps]);}
    if(Dtc_LockOnSpawn)
    {
    Dtc_Carlock[PlayerCar[playerid][Slot][CarId]] = 1;
    Dtc_LockCar(PlayerCar[playerid][Slot][CarId]);
    SetVehicleToRespawn(PlayerCar[playerid][Slot][CarId]);
    }
    }
    }


    Auch in der Datenbank habe ich extra eine neue Spalte angelegt mit "CarKey" aber bei der Abfrage ging dann alles wieder schief...


    Ich hoffe ihr könnt mir weiterhelfen, denn ich weiß nicht wo der Fehler liegt...


    Vielen Dank im Vorraus!


    Lg
    J0a9

  • Versuche es so:
    Function OnPlayerCarLogin(playerid)
    {
    new num_fields,num_rows;
    cache_get_data(num_rows,num_fields,dbhandle);
    for(new x = 0; x < num_rows; x++)
    {
    if(!Dtc_PlayerHaveCar[playerid][x])
    {
    Dtc_PlayerHaveCar[playerid][x] = 1;
    Dtc_PlayerKey[playerid] = cache_get_field_content_int(x,"CarKey",dbhandle);
    PlayerCar[playerid][x][CarId] = cache_get_field_content_int(x,"CarId",dbhandle);
    PlayerCar[playerid][x][CarModel] = cache_get_field_content_int(x,"CarModel",dbhandle);
    PlayerCar[playerid][x][CarPos_x] = cache_get_field_content_float(x,"CarPos_x",dbhandle);
    PlayerCar[playerid][x][CarPos_y] = cache_get_field_content_float(x,"CarPos_y",dbhandle);
    PlayerCar[playerid][x][CarPos_z] = cache_get_field_content_float(x,"CarPos_z",dbhandle);
    PlayerCar[playerid][x][CarRotate] = cache_get_field_content_float(x,"CarRotate",dbhandle);
    PlayerCar[playerid][x][CarNitro] = cache_get_field_content_int(x,"CarNitro",dbhandle);
    PlayerCar[playerid][x][CarHyd] = cache_get_field_content_int(x,"CarHyd",dbhandle);
    PlayerCar[playerid][x][CarAusp] = cache_get_field_content_int(x,"CarAusp",dbhandle);
    PlayerCar[playerid][x][CarSideL] = cache_get_field_content_int(x,"CarSideL",dbhandle);
    PlayerCar[playerid][x][CarSideR] = cache_get_field_content_int(x,"CarSideR",dbhandle);
    PlayerCar[playerid][x][CarFB] = cache_get_field_content_int(x,"CarFB",dbhandle);
    PlayerCar[playerid][x][CarRB] = cache_get_field_content_int(x,"CarRB",dbhandle);
    PlayerCar[playerid][x][CarSpoiler] = cache_get_field_content_int(x,"CarSpoiler",dbhandle);
    PlayerCar[playerid][x][CarRoof] = cache_get_field_content_int(x,"CarRoof",dbhandle);
    PlayerCar[playerid][x][CarHood] = cache_get_field_content_int(x,"CarHood",dbhandle);
    PlayerCar[playerid][x][CarVents] = cache_get_field_content_int(x,"CarVents",dbhandle);
    PlayerCar[playerid][x][CarLamps] = cache_get_field_content_int(x,"CarLamp",dbhandle);
    PlayerCar[playerid][x][CarPJ] = cache_get_field_content_int(x,"CarPJ",dbhandle);
    PlayerCar[playerid][x][CarC1] = cache_get_field_content_int(x,"CarC1",dbhandle);
    PlayerCar[playerid][x][CarC2] = cache_get_field_content_int(x,"CarC2",dbhandle);
    PlayerCar[playerid][x][CarArrest] = cache_get_field_content_int(x,"CarArrest",dbhandle);
    PlayerCarSpawn(playerid,x);
    }
    }
    return 1;
    }


    EDIT:
    J0a9: Ich habe noch etwas ausgebessert, nutze die neue Version, sonst klappt es nicht, wenn du mehrere Fahrzeuge hast.

    3HZXdYd.png

    Einmal editiert, zuletzt von Jeffry ()

  • Hallo Jeffry,


    daaaaankeeee! :D:D


    Funktioniert jetzt ^^


    //Edit Jeffry, ich habe jetzt das mit der neuen Funktion getestet und funktioniert ^^


    Eine kleine Frage hätte ich denn noch wenn wir schon mal beim AutoSystem sind,
    wenn ein Spieler ein neues Auto kauft soll es in der Datenbank gespeichert werden
    ich habe dies so versucht aufzubauen:



    Function OnPlayerBuyCar(playerid,Model,Preis,Autohaus)
    {
    if(IsPlayerConnected(playerid) && !Dtc_PlayerHaveCar[playerid][Dtc_PlayerKey[playerid]])
    {
    CallRemoteFunction("M_GivePlayerMoney","id",playerid,-Preis);
    if(Autohaus == 2) //Billig Autohaus
    {
    SBizzInfo[1][sbTill] += Preis/4; //Billig Autohaus
    }
    if(Autohaus == 3) // luxus
    {
    SBizzInfo[0][sbTill] += Preis/4; // luxus
    }
    SendClientMessage(playerid, COLOR_LIGHTBLUE, "*Du hast dir ein Auto gekauft.");


    SendClientMessage(playerid, COLOR_LIGHTBLUE, "*Gehe zu der KFZ Stelle und hole dir ein Kennzeichen.");
    SendClientMessage(playerid, COLOR_LIGHTBLUE, "*Fahre vorsichtig..Und denk an die StraßenVerkehrsOrdnung!");
    SetPlayerCheckpoint(playerid, 3.0, 618.7498, -1458.5891, 14.0340);
    CreateBox(playerid,"","Route ~r~gesetzt~w~...");
    SetParkPlatz(playerid,Autohaus);
    new name[MAX_PLAYER_NAME],query[500];
    GetPlayerName(playerid, name, sizeof name);

    format(query,sizeof(query),"INSERT INTO autos SET (CarModel,CarPos_x,CarPos_y,CarPos_z,CarRotate,CarPreis) VALUES ('%d','%f','%f','%f','%f','%d')",
    Model,PlayerCar[playerid][Dtc_PlayerKey[playerid]][CarPos_x],PlayerCar[playerid][Dtc_PlayerKey[playerid]][CarPos_y],PlayerCar[playerid][Dtc_PlayerKey[playerid]]
    [CarPos_z],PlayerCar[playerid][Dtc_PlayerKey[playerid]][CarRotate],Preis);
    mysql_function_query(dbhandle,query,false,"","");
    OnPlayerCarLogin(playerid);
    }
    }

    Das Problem ist, es wird nicht gespeichert wo liegt der Fehler?
    Könntest du mir bitte dabei noch helfen?


    LG
    J0a9

  • Diese Meldunk kommt:

    [15:24:05] [WARNING] cache_get_data - no active cache
    [15:24:05] [ERROR] CMySQLQuery::Execute[] - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(CarModel,CarPos_x,CarPos_y,CarPos_z,CarRotate,CarPreis) VALUES ('467','2148.489' at line 1

  • format(query,sizeof(query),"INSERT INTO autos SET (CarModel,CarPos_x,CarPos_y,CarPos_z,CarRotate,CarPreis) VALUES ('%d','%f','%f','%f','%f','%d')",
    zu:
    format(query,sizeof(query),"INSERT INTO autos (CarModel,CarPos_x,CarPos_y,CarPos_z,CarRotate,CarPreis) VALUES ('%d','%f','%f','%f','%f','%d')",


    Das SET war da falsch.