MySQL Autos 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 liebe com,
    ich finde einfach den fehler nicht... die Autos laden nicht. Könnt ihr mir villt helfen??


    getFreeCarID()
    {
    for(new i=0; i<sizeof(cInfo); i++)
    {
    if(cInfo[i][id_x]==0)return i;
    }
    return 0;
    }


    forward onPlayerCarLoad(playerid);
    public onPlayerCarLoad(playerid)
    {
    new num_fields, num_rows;
    cache_get_data(num_rows,num_fields,dbhandle);
    if(!num_rows)return print("keine autos");
    for(new i=0; i<num_rows; i++)
    {
    new c_id = getFreeCarID();
    cInfo[c_id][c_model]=cache_get_field_content_int(i,"model",dbhandle);
    cInfo[c_id][besitzer]=cache_get_field_content_int(i,"besitzer",dbhandle);
    cInfo[c_id][c_x]=cache_get_field_content_float(i,"x",dbhandle);
    cInfo[c_id][c_y]=cache_get_field_content_float(i,"y",dbhandle);
    cInfo[c_id][c_z]=cache_get_field_content_float(i,"z",dbhandle);
    cInfo[c_id][c_r]=cache_get_field_content_float(i,"r",dbhandle);
    cInfo[c_id][db_id]=cache_get_field_content_int(i,"id",dbhandle);
    cInfo[c_id][id_x]=CreateVehicle(cInfo[c_id][c_model],cInfo[c_id][c_x],cInfo[c_id][c_y],cInfo[c_id][c_z],cInfo[c_id][c_r],-1,-1,0);
    }
    return 1;
    }


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

  • forward onPlayerCarLoad(playerid);
    public onPlayerCarLoad(playerid)
    {
    printf("Called onPlayerCarLoad (%d)", playerid);
    new num_fields, num_rows;
    cache_get_data(num_rows,num_fields,dbhandle);
    if(!num_rows)return print("keine autos");
    printf("%d Autos gefunden", num_rows);
    for(new i=0; i<num_rows; i++)
    {
    new c_id = getFreeCarID();
    printf("Lade id: %d", c_id);
    cInfo[c_id][c_model]=cache_get_field_content_int(i,"model",dbhandle);
    cInfo[c_id][besitzer]=cache_get_field_content_int(i,"besitzer",dbhandle);
    cInfo[c_id][c_x]=cache_get_field_content_float(i,"x",dbhandle);
    cInfo[c_id][c_y]=cache_get_field_content_float(i,"y",dbhandle);
    cInfo[c_id][c_z]=cache_get_field_content_float(i,"z",dbhandle);
    cInfo[c_id][c_r]=cache_get_field_content_float(i,"r",dbhandle);
    cInfo[c_id][db_id]=cache_get_field_content_int(i,"id",dbhandle);
    cInfo[c_id][id_x]=CreateVehicle(cInfo[c_id][c_model],cInfo[c_id][c_x],cInfo[c_id][c_y],cInfo[c_id][c_z],cInfo[c_id][c_r],-1,-1,0);
    }
    return 1;
    }


    Debugge die Sache doch einfach mal, dann siehste wo er hängt.


    Wenn du die Autos für den Spieler geladen hast, schau was im Server-Log steht.

  • Ehm dort sehe ich keinen Fehler, schick uns mal den code von OnGameModelInit


    public OnGameModeInit()
    {
    //mysql
    dbhandle = mysql_connect(db_host,db_user,db_db,db_pass);


    SetGameModeText("Blank Script");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    return 1;
    }


    Wo lässt du loadPlayerCars(playerid); aufrufen?


    public OnPasswortResponse(playerid)
    {
    new num_rows, num_fields;
    cache_get_data(num_rows,num_fields,dbhandle);
    if(num_rows==1)
    {
    //Richtig
    loadPlayerCars(playerid);
    sInfo[playerid][eingellogt]=1;
    sInfo[playerid][level] = cache_get_field_content_int(0,"level",dbhandle);
    SetPlayerScore(playerid,sInfo[playerid][level]);
    sInfo[playerid][id] = cache_get_field_content_int(0,"id",dbhandle);
    sInfo[playerid][Adminlevel] = cache_get_field_content_int(0,"adminlevel",dbhandle);
    SetPlayerMoney(playerid,cache_get_field_content_int(0,"geld",dbhandle));
    }
    else
    {
    //Falsch
    SendClientMessage(playerid,rot,"Falsches Passwort!");
    ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Gib bitte dein Passwort ein","Login","Abbrechen");
    }
    return 1;
    }


    Debugge die Sache doch einfach mal, dann siehste wo er hängt.


    Wenn du die Autos für den Spieler geladen hast, schau was im Server-Log steht.


    Habe ich gerade es kommt "Keine autos"

  • (Nur wenn du den Server (neu) startest, sonst werden sie nicht geladen )


    Da liegst du aber falsch. Der Spieler muss sich, wenn der Server neustartet, doch auch neu einloggen, somit laden die Fahrzeuge ebenfalls aus der Datenbank. :D


  • In callback "OnPasswortResponse"
    In callback "onPlayerCarLoad" <~~~ Das steht dann in der log


  • do.de - Domain-Offensive - Domains für alle und zu super Preisen
  • Sry bin auf die http gegangen



    [18:34:24] [DEBUG] mysql_connect - host: "127.0.0.1", user: "root", database: "samp", password: "****", port: 3306, autoreconnect: true
    [18:34:24] [DEBUG] CMySQLHandle::Create - creating new connection..
    [18:34:24] [DEBUG] CMySQLHandle::CMySQLHandle - constructor called
    [18:34:24] [DEBUG] CMySQLHandle::Create - connection created with ID = 1
    [18:34:24] [DEBUG] CMySQLConnection::Connect - connection was successful
    [18:34:24] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
    [18:34:24] [DEBUG] CMySQLConnection::Connect - connection was successful
    [18:34:24] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
    [18:34:44] [DEBUG] mysql_tquery - connection: 1, query: "SELECT id FROM user WHERE username='MrMultiGamer'", callback: "OnUserCheck", format: "i"
    [18:34:44] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
    [18:34:44] [DEBUG] mysql_tquery - scheduling query "SELECT id FROM user WHERE username='MrMultiGamer'"..
    [18:34:44] [DEBUG] CMySQLQuery::Execute[OnUserCheck(i)] - starting query execution
    [18:34:44] [DEBUG] CMySQLQuery::Execute[OnUserCheck(i)] - query was successful
    [18:34:44] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
    [18:34:44] [DEBUG] CMySQLQuery::Execute[OnUserCheck(i)] - data being passed to ProcessCallbacks()
    [18:34:44] [DEBUG] Calling callback "OnUserCheck"..
    [18:34:44] [DEBUG] cache_get_data - connection: 1
    [18:34:44] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
    [18:34:44] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
    [18:34:47] [DEBUG] mysql_escape_string - source: "20154040", connection: 1, max_len: 35
    [18:34:47] [DEBUG] mysql_tquery - connection: 1, query: "SELECT * FROM user WHERE username='MrMultiGamer' AND passwort='2", callback: "OnPasswortResponse", format: "i"
    [18:34:47] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
    [18:34:47] [DEBUG] mysql_tquery - scheduling query "SELECT * FROM user WHERE username='MrMultiGamer' AND passwort='20154040'"..
    [18:34:47] [DEBUG] CMySQLQuery::Execute[OnPasswortResponse(i)] - starting query execution
    [18:34:47] [DEBUG] CMySQLQuery::Execute[OnPasswortResponse(i)] - query was successful
    [18:34:47] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
    [18:34:47] [DEBUG] CMySQLQuery::Execute[OnPasswortResponse(i)] - data being passed to ProcessCallbacks()
    [18:34:47] [DEBUG] Calling callback "OnPasswortResponse"..
    [18:34:47] [DEBUG] cache_get_data - connection: 1
    [18:34:47] [DEBUG] mysql_tquery - connection: 1, query: "SELECT * FROM autos WHERE besitzer='0'", callback: "onPlayerCarLoad", format: "i"
    [18:34:47] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
    [18:34:47] [DEBUG] mysql_tquery - scheduling query "SELECT * FROM autos WHERE besitzer='0'"..
    [18:34:47] [DEBUG] cache_get_field_content_int - row: 0, field_name: "level", connection: 1
    [18:34:47] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "level", data: "2"
    [18:34:47] [DEBUG] cache_get_field_content_int - row: 0, field_name: "id", connection: 1
    [18:34:47] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "id", data: "1"
    [18:34:47] [DEBUG] cache_get_field_content_int - row: 0, field_name: "adminlevel", connection: 1
    [18:34:47] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "adminlevel", data: "1339"
    [18:34:47] [DEBUG] cache_get_field_content_int - row: 0, field_name: "geld", connection: 1
    [18:34:47] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "geld", data: "1500"
    [18:34:47] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
    [18:34:47] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
    [18:34:47] [DEBUG] CMySQLQuery::Execute[onPlayerCarLoad(i)] - starting query execution
    [18:34:47] [DEBUG] CMySQLQuery::Execute[onPlayerCarLoad(i)] - query was successful
    [18:34:47] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
    [18:34:47] [DEBUG] CMySQLQuery::Execute[onPlayerCarLoad(i)] - data being passed to ProcessCallbacks()
    [18:34:47] [DEBUG] Calling callback "onPlayerCarLoad"..
    [18:34:47] [DEBUG] cache_get_data - connection: 1
    [18:34:47] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
    [18:34:47] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
    [18:34:52] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE user SET level='2',geld='1500',adminlevel='1339' WHERE id", callback: "(null)", format: "(null)"
    [18:34:52] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
    [18:34:52] [DEBUG] mysql_tquery - scheduling query "UPDATE user SET level='2',geld='1500',adminlevel='1339' WHERE id='1'"..
    [18:34:52] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
    [18:34:52] [DEBUG] CMySQLQuery::Execute[()] - query was successful
    [18:34:52] [DEBUG] CMySQLQuery::Execute[()] - no callback specified, skipping result saving
    [18:34:52] [DEBUG] CMySQLQuery::Execute[()] - data being passed to ProcessCallbacks()
    [18:34:52] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called

  • Zitat

    [18:34:47] [DEBUG] mysql_tquery - connection: 1, query: "SELECT * FROM autos WHERE besitzer='0'", callback: "onPlayerCarLoad", format: "i"


    Du hast das Auto mit Besitzer = 1 angelegt in der Datenbank. Somit wird es nicht gefunden.




    EDIT:
    Code:
    public OnPasswortResponse(playerid)
    {
    new num_rows, num_fields;
    cache_get_data(num_rows,num_fields,dbhandle);
    if(num_rows==1)
    {
    //Richtig
    sInfo[playerid][eingellogt]=1;
    sInfo[playerid][level] = cache_get_field_content_int(0,"level",dbhandle);
    SetPlayerScore(playerid,sInfo[playerid][level]);
    sInfo[playerid][id] = cache_get_field_content_int(0,"id",dbhandle);
    sInfo[playerid][Adminlevel] = cache_get_field_content_int(0,"adminlevel",dbhandle);
    SetPlayerMoney(playerid,cache_get_field_content_int(0,"geld",dbhandle));
    loadPlayerCars(playerid);
    }
    else
    {
    //Falsch
    SendClientMessage(playerid,rot,"Falsches Passwort!");
    ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Gib bitte dein Passwort ein","Login","Abbrechen");
    }
    return 1;
    }


    So ist es richtig.