Car wird in der Datenbank nicht erstellt

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 com ich habe ein Problem,wenn ich ein car Kaufe wird das nicht in die Tabelle eingetragen wie ? 8|
    das steht in der MysQl_Log

    SQL
    [12:10:00] [DEBUG] mysql_tquery - connection: 1, query: "INSERT INTO autos (besitzer,model,x,y,z,r) VALUES ('4','551','-0", callback: "carSavedToDB", format: "i"
    [12:10:00] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
    [12:10:00] [DEBUG] mysql_tquery - scheduling query "INSERT INTO autos (besitzer,model,x,y,z,r) VALUES ('4','551','-0.304600','-336.443603','5.322199','88.948898')"..
    [12:10:00] [DEBUG] CMySQLQuery::Execute[carSavedToDB(i)] - starting query execution
    [12:10:00] [ERROR] CMySQLQuery::Execute[carSavedToDB(i)] - (error #1062) Duplicate entry '4' for key 'besitzer'
    [12:10:00] [DEBUG] CMySQLQuery::Execute[carSavedToDB(i)] - error will be triggered in OnQueryError
    [12:10:00] [DEBUG] CMySQLQuery::Execute[carSavedToDB(i)] - data being passed to ProcessCallbacks()
    [12:10:00] [DEBUG] Calling callback "OnQueryError"..
    [12:10:00] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called


    new ahCars[][autohauscarEnum] = {
    {517,1778.3392,-1914.7708,13.1931,309.9724,12000},//Majestic
    {549,1778.7081,-1922.1168,13.0068,309.4838,10000},//Tampa
    {436,1779.7990,-1929.4340,13.1674,335.0039,8000},//Previon
    {547,1786.3859,-1931.0214,13.0707,358.4309,8000},//Primo
    {492,1794.5270,-1931.1763,13.1476,359.9832,8000},//Greenwood
    {479,1801.3038,-1929.5588,13.1304,24.9955,7000},//Regina
    {401,1802.7820,-1922.3101,13.2028,50.0128,7000},//Bravura
    {410,1802.8053,-1914.7458,13.0705,49.9958,5000},//Manana
    {536,2119.7083,-1125.3735,25.1035,220.0919,45000},//Blade
    {534,2119.0818,-1140.4009,24.7112,220.2495,50000},//Savanna
    {535,2120.2769,-1149.6525,24.0219,319.9047,35000},//Remington
    {576,2133.9116,-1145.5280,24.3744,69.9993,40000},//Slamvan
    {412,2134.6316,-1139.1819,25.2913,80.0036,15000},//Tornado
    {466,2135.1841,-1132.8958,25.3561,90.0562,40000},//Voodoo
    {467,2135.2693,-1127.2712,25.3126,94.9765,25000},//Glendale
    {567,2119.4092,-1132.7332,25.1540,220.2756,20000},//Oceanic
    {462,550.9005,-1292.7097,16.8590,29.9999,2000},//Faggio
    {509,553.6590,-1292.5516,16.7089,29.9997,500},//Bike
    {510,556.5526,-1292.9039,16.7889,29.9995,1200},//Mountain Bike
    {481,559.5067,-1292.9257,16.7457,29.9986,800},//BMX
    {551,549.3447,-1267.0093,17.0510,216.9986,40000},//Mert
    {458,545.2022,-1269.8716,17.1420,216.9990,16000},//Solair
    {445,541.1859,-1272.9104,17.0974,216.9984,20000},//Admiral
    {405,537.2215,-1275.8428,17.0564,217.3912,50000},//Sentinel
    {533,533.0996,-1279.0229,16.9669,217.0186,20000},//Feltzer
    {542,529.3826,-1282.3234,17.0169,217.0079,15000},//Clover
    {475,525.3351,-1285.3268,17.0026,216.9973,40000},//Sabre
    {439,521.2407,-1288.1873,17.0940,217.2220,30000},//Stallion
    {469,-1638.2010,-667.3042,14.1735,320.2324,800000},//Sparrow
    {563,-1652.1797,-655.0400,14.9072,325.0001,1200000},//Raindance
    {487,-1670.3180,-643.3762,14.3146,319.9983,1000000},//Maverik
    {593,-1664.6489,-609.4921,14.6010,199.9841,1100000},//Dodo
    {519,-1644.8362,-603.3583,15.0687,205.0012,1500000},//Shamal
    {463,-1989.3320,274.1434,34.7038,240.0000,200000},//Freeway
    {468,-1989.6099,270.2097,34.8558,240.0001,600000},//Sunchez
    {461,-1989.9058,266.1317,34.7729,239.9999,500000},//PCJ-600
    {521,-1990.3009,261.9583,34.7399,240.9074,600000},//FRC-900
    {522,-1990.6650,257.7109,34.7448,240.0001,2500000},//NRG-500
    {561,-1956.1478,301.6561,35.2476,109.9989,300000},//Stratum
    {565,-1955.6249,294.9202,35.0526,109.9922,300000},//Flash
    {560,-1947.8324,272.7213,35.1410,79.0297,600000},//Sultan
    {550,-1948.3179,267.3468,35.3150,79.9926,100000},//Sunrise
    {426,-1948.5752,261.8673,35.1658,80.1399,80000},//Premier
    {507,-1948.9185,256.3206,35.2193,80.2831,60000},//Elegant
    {559,-1948.3441,272.4749,40.6548,79.9965,450000},//Jester
    {558,-1948.6221,264.9835,40.6422,79.9920,150000},//Uranus
    {562,-1948.3993,258.2673,40.6999,78.1411,400000},//Elegy
    {429,-1954.5563,292.5934,40.7466,140.0730,900000},//Banshee
    {402,-1955.0973,302.4874,40.8754,139.9748,500000},//Buffalo
    {415,-1652.8722,1213.3792,7.0137,209.9856,800000},//Cheetah
    {477,-1671.4486,1206.2499,13.4503,279.9929,600000},//ZR-50
    {506,-1648.3962,1206.7548,13.3219,20.3122,500000},//Super-GT
    {495,-1665.6210,1223.1183,13.9860,210.1448,500000},//Sandking
    {541,-1663.7516,1221.6583,20.8167,224.9904,1200000},//Bullet
    {411,-1649.7714,1206.9974,20.7836,69.9973,1600000},//Infernus
    {451,-1666.5088,1206.4033,20.8095,294.9901,1000000},//Turismo
    {515,2129.4312,941.7939,11.8827,110.0144,250000},//Road Train
    {514,2129.5615,934.3322,11.4592,110.0001,200000},//Tanker
    {482,2103.3726,946.1735,10.8807,270.0109,40000},//Buritto
    {413,2103.4163,941.2428,10.9144,269.9996,20000},//Pony
    {418,2103.4595,930.9376,10.9341,269.9996,10000},//Moonbeam
    {483,2103.6689,925.7841,10.7828,270.0113,10000},//Camper
    {543,2103.5530,915.9024,10.5812,270.0947,15000},//Satler
    {478,2103.5466,910.8055,10.8157,269.5107,4000},//Walton
    {579,2127.8733,909.2474,10.7974,89.9947,150000},//Huntley
    {554,2127.6477,900.4788,10.9917,89.9994,40000},//Yosemit
    {500,2127.6274,891.6475,11.0174,89.9148,50000},//Mesa
    {489,2106.0315,891.0602,10.9885,269.9990,30000},//Rancher
    {400,2106.3501,899.7379,10.9761,269.9987,60000}//Landstalker
    };


    new Float:RandomSpawn[][4] = {
    {-31.5830,-276.6498,5.3175,269.5427},
    {-31.4291,-286.8210,5.3192,270.3276},
    {-31.5830,-276.6498,5.3175,269.5427},
    {-30.5126,-280.0215,5.3186,269.2653},
    {-31.2262,-283.4319,5.3170,269.3367},
    {-31.4291,-286.8210,5.3192,270.3276},
    {-30.6872,-290.2162,5.3215,270.0367},
    {-31.2113,-293.6188,5.3206,270.5205},
    {-30.9714,-296.9427,5.3215,269.7877},
    {-0.9785,-301.1555,5.3132,89.2128},
    {-0.3900,-304.6669,5.3173,90.0018},
    {-0.4273,-308.1667,5.3223,89.5486},
    {-0.0562,-311.6645,5.3220,90.0193},
    {-0.2071,-315.2568,5.3215,89.2483},
    {-0.6865,-318.7336,5.3232,89.6181},
    {-0.5670,-322.2784,5.3224,89.8154},
    {-0.7787,-325.8391,5.3220,88.6041},
    {-0.5788,-329.3296,5.3211,89.3954},
    {-0.8341,-332.8588,5.3224,89.2498},
    {-0.3046,-336.4436,5.3222,88.9489},
    {-0.7694,-339.8704,5.3236,89.9762},
    {-0.8461,-343.4076,5.3248,89.5425},
    {-0.5109,-346.9451,5.3220,89.8589},
    {-0.5799,-350.4830,5.3219,89.6116},
    {-0.2762,-354.0208,5.3204,89.5558},
    {-0.0255,-357.5459,5.3205,89.8315},
    {-0.6771,-361.0365,5.3217,88.9111},
    {-1.2926,-364.7119,5.3221,89.1589}
    };
    new cInfo[20][carEnum];


    enum carEnum{
    id_x,
    model,
    besitzer,
    Float:c_x,
    Float:c_y,
    Float:c_z,
    Float:c_r,
    db_id
    }


    enum autohausEnum{
    Float:s_x,
    Float:s_y,
    Float:s_z,
    Float:s_r
    }


    enum autohauscarEnum{
    model,
    Float:c_x,
    Float:c_y,
    Float:c_z,
    Float:c_r,
    c_preis,
    ah_id,
    id_x
    }
    forward carSavedToDB(carid);
    forward OnPlayerCarsLoad(playerid);

    public carSavedToDB(carid)
    {
    cInfo[carid][db_id]=cache_insert_id(dbhandle);
    return 1;
    }


    public OnPlayerCarsLoad(playerid)
    {
    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++)
    {
    new id=getFreeCarID();
    cInfo[id][model]=cache_get_field_content_int(i,"model",dbhandle);
    cInfo[id][besitzer]=cache_get_field_content_int(i,"besitzer",dbhandle);
    cInfo[id][c_x]=cache_get_field_content_float(i,"x",dbhandle);
    cInfo[id][c_y]=cache_get_field_content_float(i,"y",dbhandle);
    cInfo[id][c_z]=cache_get_field_content_float(i,"z",dbhandle);
    cInfo[id][c_r]=cache_get_field_content_float(i,"r",dbhandle);
    cInfo[id][db_id]=cache_get_field_content_int(i,"id",dbhandle);
    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);
    tank[cInfo[id][id_x]]=100;
    }
    return 1;
    }


    loadPlayerCars(playerid)
    {
    new query[128];
    format(query,sizeof(query),"SELECT * FROM autos WHERE besitzer='%i'",sInfo[playerid][db_id]);
    mysql_function_query(dbhandle,query,true,"OnPlayerCarsLoad","i",playerid);
    return 1;
    }


    saveCarToDB(playerid,carid)
    {
    new query[128];
    format(query,sizeof(query),"INSERT INTO autos (besitzer,model,x,y,z,r) VALUES ('%i','%i','%f','%f','%f','%f')",sInfo[playerid][db_id],cInfo[carid][model],cInfo[carid][c_x],cInfo[carid][c_y],cInfo[carid][c_z],cInfo[carid][c_r]);
    mysql_function_query(dbhandle,query,true,"carSavedToDB","i",carid);
    return 1;
    }


    createPlayerCar(playerid,modelid,Float:x,Float:y,Float:z,Float:r)
    {
    for(new i=0; i<sizeof(cInfo); i++)
    {
    new string[128];
    if(cInfo[i][id_x]!=0)continue;
    cInfo[i][besitzer]=sInfo[playerid][db_id];
    cInfo[i][c_x]=x;
    cInfo[i][c_y]=y;
    cInfo[i][c_z]=z;
    cInfo[i][c_r]=r;
    cInfo[i][model]=modelid;
    cInfo[i][id_x] = CreateVehicle(modelid,x,y,z,r,-1,-1,-1);
    SetVehicleParamsEx(cInfo[i][id_x],0,0,0,1,0,0,0);
    saveCarToDB(playerid,i);
    format(string,sizeof(string),"%s",getPlayerName(playerid));
    SetVehicleNumberPlate(cInfo[i][id_x],string);
    return 1;
    }
    return 1;
    }


    if(dialogid==DIALOG_AUTOHAUS)
    {
    if(response)
    {
    new id=GetPVarInt(playerid,"buyCarID");
    if(GetPlayerMoney(playerid)<ahCars[id][c_preis])
    {
    SendClientMessage(playerid,ROT,"Du hast nicht genügend Geld");
    RemovePlayerFromVehicle(playerid);
    printf("%s hat nicht Genügend Geld um sich das Auto Zu Kaufen!)",getPlayerName(playerid));
    return 1;
    }
    new rand = random(sizeof(RandomSpawn));
    GivePlayerMoney(playerid,-ahCars[id][c_preis]);
    createPlayerCar(playerid,ahCars[id][model],RandomSpawn[rand][0],RandomSpawn[rand][1],RandomSpawn[rand][2],RandomSpawn[rand][3]);
    SetPlayerCheckpoint(playerid, RandomSpawn[rand][0],RandomSpawn[rand][1],RandomSpawn[rand][2], 3.0);
    SendClientMessage(playerid,LEUCHTENDBLAU,"Herzlichen Glückwunsch zu ihren Kauf");
    SendClientMessage(playerid,LEUCHTENDBLAU,"Es wurde dir ein Marker auf der Map gesetzt");
    SendClientMessage(playerid,LEUCHTENDBLAU,"Du kannst nun dein Fahrzeug hinter der Truckerbase in Ls abholen");
    RemovePlayerFromVehicle(playerid);
    printf("%s hat sich ein Car Gekauft!)",getPlayerName(playerid));
    }
    else
    {
    RemovePlayerFromVehicle(playerid);
    SendClientMessage(playerid,ROT,"Dann eben nicht ...");
    printf("%s hat sich das Car nicht Gekauft!)",getPlayerName(playerid));
    }
    return 1;
    }

    Einmal editiert, zuletzt von seegras ()


  • versuch mal die query zu erhöhen:
    saveCarToDB(playerid,carid)
    {
    new query[280];
    format(query,sizeof(query),"INSERT INTO autos (besitzer,model,x,y,z,r) VALUES ('%i','%i','%f','%f','%f','%f')",sInfo[playerid][db_id],cInfo[carid][model],cInfo[carid][c_x],cInfo[carid][c_y],cInfo[carid][c_z],cInfo[carid][c_r]);
    mysql_function_query(dbhandle,query,true,"carSavedToDB","i",carid);
    return 1;
    }