Dini zu MYSQL

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 Community,


    ich bräuchte nunmal hilfe... ich bin neu beim lernen von MySQL, deshalb frage ich nun hier mal nach...


    ich habe ein DTC Autohaussystem und nun möchte ich das in MySQL umschreiben! Nur ich weiss nicht wie, bei den Usern war das irgendwie leichter


    Code:


    forward OnPlayerBuyCar(playerid,ModelA,autoo);
    public OnPlayerBuyCar(playerid,ModelA,autoo)//CARSYS
    {
    if(IsPlayerConnected(playerid) && !hatspielercar[playerid][Dtc_PlayerKey[playerid]])
    {
    SendClientMessage(playerid, Blau, "*Du hast dir ein Auto gekauft. Du kriegst für den anfang 10 Liter in dein Fahrzeug!");
    PlayerPlaySound(playerid, 1058, 0.0, 0.0, 0.0);
    SetParkPlatz(playerid,autoo);
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof name);
    format(str, sizeof str, "/Autos/%s%d.dtcar", name,Dtc_PlayerKey[playerid]);
    new File: hFile = fopen(str, io_write);
    for(new i = 0; i < sizeof(BuyCars);i++)
    {
    if(GetPlayerVehicleID(playerid) == KaufAutos[i])
    {
    if (hFile)
    {
    new var[32];
    format(var, 32, "CarId=0\n");fwrite(hFile, var);
    format(var, 32, "CarModel=%d\n",ModelA);fwrite(hFile, var);
    format(var, 32, "CarPos_x=%.3f\n",PlayerCar[playerid][Dtc_PlayerKey[playerid]][CarPos_x]);fwrite(hFile, var);
    format(var, 32, "CarPos_y=%.3f\n",PlayerCar[playerid][Dtc_PlayerKey[playerid]][CarPos_y]);fwrite(hFile, var);
    format(var, 32, "CarPos_z=%.3f\n",PlayerCar[playerid][Dtc_PlayerKey[playerid]][CarPos_z]);fwrite(hFile, var);
    format(var, 32, "CarRotate=%.3f\n",PlayerCar[playerid][Dtc_PlayerKey[playerid]][CarRotate]);fwrite(hFile, var);
    format(var, 32, "CarNitro=0\n");fwrite(hFile, var);
    format(var, 32, "CarHyd=0\n");fwrite(hFile, var);
    format(var, 32, "CarWheel=0\n");fwrite(hFile, var);
    format(var, 32, "CarAusp=0\n");fwrite(hFile, var);
    format(var, 32, "CarSideL=0\n");fwrite(hFile, var);
    format(var, 32, "CarSideR=0\n");fwrite(hFile, var);
    format(var, 32, "CarFB=0\n");fwrite(hFile, var);
    format(var, 32, "CarRB=0\n");fwrite(hFile, var);
    format(var, 32, "CarSpoiler=0\n");fwrite(hFile, var);
    format(var, 32, "CarRoof=0\n");fwrite(hFile, var);
    format(var, 32, "CarHood=0\n");fwrite(hFile, var);
    format(var, 32, "CarVents=0\n");fwrite(hFile, var);
    format(var, 32, "CarLamps=0\n");fwrite(hFile, var);
    format(var, 32, "CarPJ=-1\n");fwrite(hFile, var);
    format(var, 32, "CarC1=-1\n");fwrite(hFile, var);
    format(var, 32, "CarC2=-1\n");fwrite(hFile, var);
    format(var, 32, "Preis=%d\n",BuyCars[i][dtc_CarPreis]);fwrite(hFile, var);
    format(var, 32, "CarSperre=0\n");fwrite(hFile, var);
    format(var, 32, "Plate=%s\n",name);fwrite(hFile, var);//Plate=XXX\n
    format(var, 32, "CarTank=22\n");fwrite(hFile, var);
    format(var, 32, "CarHp=1000.00\n");fwrite(hFile, var);
    format(var, 32, "CarPreisk=%d\n",BuyCars[i][RepPreis]);fwrite(hFile, var);

    fclose(hFile);
    }
    }
    }
    OnPlayerCarLogin(playerid);
    }
    }
    forward OnPlayerCarLogin(playerid);
    public OnPlayerCarLogin(playerid)
    {
    for(new x = 0; x < MaxVeh; x++)
    {
    if(!hatspielercar[playerid][x])
    {
    new string2[128];
    new playername2[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playername2, sizeof(playername2));
    format(string2, sizeof(string2), "/Autos/%s%d.dtcar", playername2,x);
    new File: UserFile = fopen(string2, io_read);
    if (UserFile)
    {
    hatspielercar[playerid][x] = 1;
    new key[ 256 ] , val[ 256 ];
    new Data[ 256 ];
    while ( fread( UserFile , Data , sizeof( Data ) ) )
    {
    key = ini_GetKey( Data );
    if( strcmp( key , "CarId" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarId] = strval( val ); }
    if( strcmp( key , "CarModel" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarModel] = strval( val ); }
    if( strcmp( key , "CarPos_x" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarPos_x] = floatstr( val ); }
    if( strcmp( key , "CarPos_y" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarPos_y] = floatstr( val ); }
    if( strcmp( key , "CarPos_z" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarPos_z] = floatstr( val ); }
    if( strcmp( key , "CarRotate" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarRotate] = floatstr( val ); }
    if( strcmp( key , "CarNitro" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarNitro] = strval( val ); }
    if( strcmp( key , "CarHyd" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarHyd] = strval( val ); }
    if( strcmp( key , "CarWheel" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarWheel] = strval( val ); }
    if( strcmp( key , "CarAusp" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarAusp] = strval( val ); }
    if( strcmp( key , "CarSideL" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarSideL] = strval( val ); }
    if( strcmp( key , "CarSideR" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarSideR] = strval( val ); }
    if( strcmp( key , "CarFB" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarFB] = strval( val ); }
    if( strcmp( key , "CarRB" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarRB] = strval( val ); }
    if( strcmp( key , "CarSpoiler" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarSpoiler] = strval( val ); }
    if( strcmp( key , "CarRoof" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarRoof] = strval( val ); }
    if( strcmp( key , "CarHood" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarHood] = strval( val ); }
    if( strcmp( key , "CarVents" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarVents] = strval( val ); }
    if( strcmp( key , "CarLamps" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarLamps] = strval( val ); }
    if( strcmp( key , "CarPJ" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarPJ] = strval( val ); }
    if( strcmp( key , "CarC1" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarC1] = strval( val ); }
    if( strcmp( key , "CarC2" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarC2] = strval( val ); }
    if( strcmp( key , "Preis" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarPreis] = strval( val ); }
    if( strcmp( key , "Plate" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][Plate] = strval( val ); }
    if( strcmp( key , "CarSperre" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarGesperrt] = strval( val ); }
    if( strcmp( key , "CarKaputt" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarKaputt] = strval( val ); }
    if( strcmp( key , "CarTank" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarTank] = strval( val ); }
    if( strcmp( key , "CarKM" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarKM] = floatstr( val ); }
    if( strcmp( key , "CarHp" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarHp] = floatstr( val ); }
    if( strcmp( key , "CarClose" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarClose] = strval( val ); }
    if( strcmp( key , "CarPreisk" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerCar[playerid][x][CarPreisk] = strval( val ); }
    }
    //PlayerCar[playerid][x][CarId] = Spielerauto[x][playerid];
    fclose(UserFile);
    PlayerCarSpawn(playerid,x);
    }
    }
    }
    }
    forward PlayerCarSpawn(playerid,Slot);
    public PlayerCarSpawn(playerid,Slot)
    {
    if(IsPlayerConnected(playerid))
    {
    if(hatspielercar[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)
    {
    Carlockd[PlayerCar[playerid][Slot][CarId]] = 1;
    lockcard(PlayerCar[playerid][Slot][CarId]);
    }
    new strings[15];
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof name);
    format(str, sizeof str, "/Autos/%s%d.dtcar", name,Dtc_PlayerKey[playerid]);
    format(strings, sizeof(strings), "%s", dini_Get(str, "Plate"));
    SetVehicleNumberPlate(PlayerCar[playerid][Slot][CarId], strings);
    SetVehicleToRespawn(PlayerCar[playerid][Slot][CarId]);
    for(new x = 0; x < MaxVeh; x++)
    {
    PlayerCar[playerid][x][Plate] = strings;
    }
    }
    }
    }


    Wie schreibe ich DAS in MYSQL?


    Mit freundlichen Grüßen


    Teddy

  • for(new x = 0; x < MaxVeh; x++)
    {
    if(!hatspielercar[playerid][x])
    {
    new string2[128];
    new playername2[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playername2, sizeof(playername2));
    format(string2, sizeof(string2), "/Autos/%s%d.dtcar", playername2,x);
    new File: UserFile = fopen(string2, io_read);
    if (UserFile)
    {
    hatspielercar[playerid][x] = 1;
    new key[ 256 ] , val[ 256 ];
    new Data[ 256 ];
    while ( fread( UserFile , Data , sizeof( Data ) ) )
    {


    Das ist nun eher mein problem, wie ich das umschreibe...

  • Verstehe davon nichts... kann mir einer per skype oderso helfen?


    Du hast doch geschrieben "Nur ich weiss nicht wie, bei den Usern war das irgendwie leichter", da hast du doch auch alle Spielerdaten in einen Query gepackt, ist im komplett das gleiche. Wenn du nicht verstehst wie es geht, schau dir Mysql Tutorials an. Ich würde dir das Tutorial von Logan empfehlen. [ SCRIPTING ] MySQL R7(+) - Cachefunktionen & Threaded Querys [UPDATED]

  • Ich brauche nur:


    • Wie schreibe ich das Autohaussystem um in MYSQL
    • Wie funktioniert das am besten mit MYSQL

    Wie gesagt ich kann es nicht so gut... das mit den Spielern habe ich eher von Madin abgeguckt...
    stock CreateAccount(playerid, passwort[])
    {
    new query[256],Name4[MAX_PLAYER_NAME];
    GetPlayerName(playerid, Name4, MAX_PLAYER_NAME);
    mysql_real_escape_string(Name4,Name4);
    mysql_real_escape_string(passwort,passwort);
    format(query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Passwort`) VALUES ('%s', '%s','%d')", Name4, passwort);
    mysql_query(query);
    return true;
    }
    Das ist sicher gemeint....

  • Schau dir erstmal das Tutorial von Logan an, das Tutorial von Maddin sollte man eigentlich löschen, denn es ist nicht viel besser als dini, weil er für jede Variable ein Query benutzt. Du solltest am besten Mysql verstehen, bevor du es versuchst anzuwenden. Es macht kein unterschied zwischen Account speichern/laden/hinzufügen und Auto speichern/laden/hinzufügen, das komplett das selbe.


    Wie schreibe ich das Autohaussystem um in MYSQL
    -Die Frage ist sehr verallgemeinert, deswegen meine Antwort auch: Mit einem Query


    Wie funktioniert das am besten mit MYSQL
    Am besten benutzt du Threaded Querys und die BlueG R7 Version

  • So jetzt nochmal:


    Würde das bisjetzt so gehen?


    stock OnPlayerBuyCar(playerid, ModelA,autoo)
    {
    new query[256],Name4[MAX_PLAYER_NAME];
    GetPlayerName(playerid, Name4, MAX_PLAYER_NAME);
    mysql_real_escape_string(Name4,Name4);
    mysql_real_escape_string(passwort,passwort);
    format(query, sizeof(query), "INSERT INTO `autos` (`CarId`, `CarModel`, `CarPos_x`, `CarPos_y`, `Carpos_z`) VALUES ('%d', '%d','%f','%f','%f')", 0, ModelA,PlayerCar[playerid][Dtc_PlayerKey[playerid]][CarPos_x],PlayerCar[playerid][Dtc_PlayerKey[playerid]][CarPos_y],PlayerCar[playerid][Dtc_PlayerKey[playerid]][CarPos_z]);
    mysql_query(query);
    return true;
    }


    //e


    Metro ich weiss nicht wie ich damit mysql lernen soll.. was soll ich mit sowas anfangen ^^ ich check noch nichtmal wie das hier klappt

    4 Mal editiert, zuletzt von Teddybaer ()