Schaden vom Auto Speichern

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 ich bräuchte mal eure Hilfe undzwar wie ich Schaden vom Fahrzeug Privat Car Speichere und Lade?


    Ich denke das Ganze Funktioniert mit GetVehicleHealth aber ich bin mir grad nicht sicher wie genau?



    Speicherung


    format(dateiname, sizeof(dateiname), "%s.car", playername);
    new File: CarFile = fopen(dateiname, io_write);
    format(var, 256, "AH_Typ=%i\n", Carlist[playerid][Typ]); fwrite(CarFile, var);
    format(var, 256, "AH_X=%f\n", Carlist[playerid][XX]); fwrite(CarFile, var);
    format(var, 256, "AH_Y=%f\n", Carlist[playerid][YY]); fwrite(CarFile, var);
    format(var, 256, "AH_Z=%f\n", Carlist[playerid][ZZ]); fwrite(CarFile, var);
    format(var, 256, "AH_Rot=%f\n", Carlist[playerid][Rotation]); fwrite(CarFile, var);
    format(var, 256, "AH_Status=%i\n", Carlist[playerid][Status]); fwrite(CarFile, var);
    format(var, 256, "AH_Lock=%i\n", Carlist[playerid][Lock]); fwrite(CarFile, var);
    format(var, 256, "AH_Paintjob=%i\n", Carlist[playerid][Paintjob]); fwrite(CarFile, var);
    format(var, 256, "AH_Farbe1=%i\n", Carlist[playerid][Farbe1]); fwrite(CarFile, var);
    format(var, 256, "AH_Farbe2=%i\n", Carlist[playerid][Farbe2]); fwrite(CarFile, var);
    format(var, 256, "AH_mod1=%i\n", Carlist[playerid][mod1]); fwrite(CarFile, var);
    format(var, 256, "AH_mod2=%i\n", Carlist[playerid][mod2]); fwrite(CarFile, var);
    format(var, 256, "AH_mod3=%i\n", Carlist[playerid][mod3]); fwrite(CarFile, var);
    format(var, 256, "AH_mod4=%i\n", Carlist[playerid][mod4]); fwrite(CarFile, var);
    format(var, 256, "AH_mod5=%i\n", Carlist[playerid][mod5]); fwrite(CarFile, var);
    format(var, 256, "AH_mod6=%i\n", Carlist[playerid][mod6]); fwrite(CarFile, var);
    format(var, 256, "AH_mod7=%i\n", Carlist[playerid][mod7]); fwrite(CarFile, var);
    format(var, 256, "AH_mod8=%i\n", Carlist[playerid][mod8]); fwrite(CarFile, var);
    format(var, 256, "AH_mod9=%i\n", Carlist[playerid][mod9]); fwrite(CarFile, var);
    format(var, 256, "AH_mod10=%i\n", Carlist[playerid][mod10]); fwrite(CarFile, var);
    format(var, 256, "AH_mod11=%i\n", Carlist[playerid][mod11]); fwrite(CarFile, var);
    format(var, 256, "AH_mod12=%i\n", Carlist[playerid][mod12]); fwrite(CarFile, var);
    format(var, 256, "AH_mod13=%i\n", Carlist[playerid][mod13]); fwrite(CarFile, var);
    format(var, 256, "AH_mod14=%i\n", Carlist[playerid][mod14]); fwrite(CarFile, var);
    format(var, 256, "AH_mod15=%i\n", Carlist[playerid][mod15]); fwrite(CarFile, var);
    format(var, 256, "AH_mod16=%i\n", Carlist[playerid][mod16]); fwrite(CarFile, var);
    format(var, 256, "AH_mod17=%i\n", Carlist[playerid][mod17]); fwrite(CarFile, var);



    Wird Geladen


    while ( fread( CarFile , Data , sizeof( Data ) ) )
    {
    key = ini_GetKey(Data);
    if(strcmp(key,"AH_Typ",true)==0) { Carlist[playerid][Typ]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_X",true)==0) { Carlist[playerid][XX]=floatstr(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_Y",true)==0) { Carlist[playerid][YY]=floatstr(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_Z",true)==0) { Carlist[playerid][ZZ]=floatstr(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_Rot",true)==0) { Carlist[playerid][Rotation]=floatstr(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_Status",true)==0) { Carlist[playerid][Status]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_Lock",true)==0) { Carlist[playerid][Lock]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_Paintjob",true)==0) { Carlist[playerid][Paintjob]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_Farbe1",true)==0) { Carlist[playerid][Farbe1]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_Farbe2",true)==0) { Carlist[playerid][Farbe2]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod1",true)==0) { Carlist[playerid][mod1]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod2",true)==0) { Carlist[playerid][mod2]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod3",true)==0) { Carlist[playerid][mod3]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod4",true)==0) { Carlist[playerid][mod4]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod5",true)==0) { Carlist[playerid][mod5]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod6",true)==0) { Carlist[playerid][mod6]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod7",true)==0) { Carlist[playerid][mod7]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod8",true)==0) { Carlist[playerid][mod8]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod9",true)==0) { Carlist[playerid][mod9]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod10",true)==0) { Carlist[playerid][mod10]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod11",true)==0) { Carlist[playerid][mod11]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod12",true)==0) { Carlist[playerid][mod12]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod13",true)==0) { Carlist[playerid][mod13]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod14",true)==0) { Carlist[playerid][mod14]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod15",true)==0) { Carlist[playerid][mod15]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod16",true)==0) { Carlist[playerid][mod16]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod17",true)==0) { Carlist[playerid][mod17]=strval(ini_GetValue(Data)); }
    }

  • Naja...so:


    //Oben einfügen:
    new Float:h;
    GetVehicleHealth(vehicleid,h);
    format(var, 256, "CarHealth=%f\n", h); fwrite(CarFile, var);


    //Unten einfügen:
    else if(strcmp(key,"CarHealth",true)==0) { SetVehicleHealth(vehicleid,floatstr(ini_GetValue(Data))); }


    oder speichere die Werte noch zwischen ;)


    mfg. :thumbup:

    ast2ufdyxkb1.png


    Leute, lernt scripten und versucht mal lieber etwas selber zu schreiben, als es aus einem GF zu kopieren. :S



  • Danke aber Es Speichert nicht?


  • ...wie hast du es denn eingefügt? :huh:





    Wenn es geladen wird



    if (fexist(dateiname))
    {
    new File: CarFile = fopen(dateiname, io_read);
    if ( CarFile )
    {
    new key[ 256 ];
    new Data[ 256 ];
    while ( fread( CarFile , Data , sizeof( Data ) ) )
    {
    new vehicleid = GetPlayerVehicleID(playerid);

    key = ini_GetKey(Data);
    if(strcmp(key,"AH_Typ",true)==0) { Carlist[playerid][Typ]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_X",true)==0) { Carlist[playerid][XX]=floatstr(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_Y",true)==0) { Carlist[playerid][YY]=floatstr(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_Z",true)==0) { Carlist[playerid][ZZ]=floatstr(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_Rot",true)==0) { Carlist[playerid][Rotation]=floatstr(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_Status",true)==0) { Carlist[playerid][Status]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_Lock",true)==0) { Carlist[playerid][Lock]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_Paintjob",true)==0) { Carlist[playerid][Paintjob]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_Farbe1",true)==0) { Carlist[playerid][Farbe1]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_Farbe2",true)==0) { Carlist[playerid][Farbe2]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod1",true)==0) { Carlist[playerid][mod1]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod2",true)==0) { Carlist[playerid][mod2]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod3",true)==0) { Carlist[playerid][mod3]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod4",true)==0) { Carlist[playerid][mod4]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod5",true)==0) { Carlist[playerid][mod5]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod6",true)==0) { Carlist[playerid][mod6]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod7",true)==0) { Carlist[playerid][mod7]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod8",true)==0) { Carlist[playerid][mod8]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod9",true)==0) { Carlist[playerid][mod9]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod10",true)==0) { Carlist[playerid][mod10]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod11",true)==0) { Carlist[playerid][mod11]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod12",true)==0) { Carlist[playerid][mod12]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod13",true)==0) { Carlist[playerid][mod13]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod14",true)==0) { Carlist[playerid][mod14]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod15",true)==0) { Carlist[playerid][mod15]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod16",true)==0) { Carlist[playerid][mod16]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"AH_mod17",true)==0) { Carlist[playerid][mod17]=strval(ini_GetValue(Data)); }
    else if(strcmp(key,"CarHealth",true)==0) { SetVehicleHealth(vehicleid,floatstr(ini_GetValue(Data))); }
    }
    }




    Wenn es gespeichert wird



    new File: CarFile = fopen(dateiname, io_write);
    format(var, 256, "AH_Typ=%i\n", Carlist[playerid][Typ]); fwrite(CarFile, var);
    format(var, 256, "AH_X=%f\n", Carlist[playerid][XX]); fwrite(CarFile, var);
    format(var, 256, "AH_Y=%f\n", Carlist[playerid][YY]); fwrite(CarFile, var);
    format(var, 256, "AH_Z=%f\n", Carlist[playerid][ZZ]); fwrite(CarFile, var);
    format(var, 256, "AH_Rot=%f\n", Carlist[playerid][Rotation]); fwrite(CarFile, var);
    format(var, 256, "AH_Status=%i\n", Carlist[playerid][Status]); fwrite(CarFile, var);
    format(var, 256, "AH_Lock=%i\n", Carlist[playerid][Lock]); fwrite(CarFile, var);
    format(var, 256, "AH_Paintjob=%i\n", Carlist[playerid][Paintjob]); fwrite(CarFile, var);
    format(var, 256, "AH_Farbe1=%i\n", Carlist[playerid][Farbe1]); fwrite(CarFile, var);
    format(var, 256, "AH_Farbe2=%i\n", Carlist[playerid][Farbe2]); fwrite(CarFile, var);
    format(var, 256, "AH_mod1=%i\n", Carlist[playerid][mod1]); fwrite(CarFile, var);
    format(var, 256, "AH_mod2=%i\n", Carlist[playerid][mod2]); fwrite(CarFile, var);
    format(var, 256, "AH_mod3=%i\n", Carlist[playerid][mod3]); fwrite(CarFile, var);
    format(var, 256, "AH_mod4=%i\n", Carlist[playerid][mod4]); fwrite(CarFile, var);
    format(var, 256, "AH_mod5=%i\n", Carlist[playerid][mod5]); fwrite(CarFile, var);
    format(var, 256, "AH_mod6=%i\n", Carlist[playerid][mod6]); fwrite(CarFile, var);
    format(var, 256, "AH_mod7=%i\n", Carlist[playerid][mod7]); fwrite(CarFile, var);
    format(var, 256, "AH_mod8=%i\n", Carlist[playerid][mod8]); fwrite(CarFile, var);
    format(var, 256, "AH_mod9=%i\n", Carlist[playerid][mod9]); fwrite(CarFile, var);
    format(var, 256, "AH_mod10=%i\n", Carlist[playerid][mod10]); fwrite(CarFile, var);
    format(var, 256, "AH_mod11=%i\n", Carlist[playerid][mod11]); fwrite(CarFile, var);
    format(var, 256, "AH_mod12=%i\n", Carlist[playerid][mod12]); fwrite(CarFile, var);
    format(var, 256, "AH_mod13=%i\n", Carlist[playerid][mod13]); fwrite(CarFile, var);
    format(var, 256, "AH_mod14=%i\n", Carlist[playerid][mod14]); fwrite(CarFile, var);
    format(var, 256, "AH_mod15=%i\n", Carlist[playerid][mod15]); fwrite(CarFile, var);
    format(var, 256, "AH_mod16=%i\n", Carlist[playerid][mod16]); fwrite(CarFile, var);
    format(var, 256, "AH_mod17=%i\n", Carlist[playerid][mod17]); fwrite(CarFile, var);
    format(var, 256, "CarHealth=%f\n", h); fwrite(CarFile, var);


    //EDIT was vergessen