sqllite login/register system

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
  • Tag freunde, schreib grad mein script von dini auf sqllite um und brauch mal hilfe.
    er erkennt alles bei onplayerconnect, doch wenn diese funktion aufgerufen wird crasht der server:
    @BlackAce:
    habe dein Tutorial genutzt, soweit funzt auch alles, nur dort crasht halt der server..


    stock Login(playerid,key[])
    {
    new query[128];
    format(query, sizeof(query), "SELECT * FROM `Accounts` WHERE `Name` = '%s' AND `Passwort` = '%s'",SpielerName(playerid),key);
    new DBResult:Result = db_query(Accounts, query);
    if(db_num_rows(Result)==1)
    {
    LoadAccount(playerid);
    SendClientMessage(playerid,BLAU,"Erfolgreich eingeloggt!");
    }
    else if(db_num_rows(Result)==0)
    {
    SendClientMessage(playerid,BLAU,"Falsches Passwort!");
    ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Bitte gebe dein Passwort ein!","Login","Abbrechen");
    }
    db_free_result(Result);
    return 1;
    }


  • stock LoadAccount(playerid)
    {
    new DBResult:Result, query[128]/*,waffe,ammox,form[32]*/;
    format(query, sizeof(query), "SELECT * FROM `Accounts` WHERE `Name` = '%s'",SpielerName(playerid));
    Result = db_query(Accounts,query);
    if(db_num_rows(Result) > 0)
    {
    db_get_field_assoc(Result,"Geld",query,sizeof(query));
    GivePlayerMoney(playerid,strval(query));
    db_get_field_assoc(Result,"Rang",query,sizeof(query));
    SetPVarInt(playerid,"Rang",strval(query));
    db_get_field_assoc(Result,"Banned",query,sizeof(query));
    SetPVarInt(playerid,"Banned",strval(query));
    db_get_field_assoc(Result,"Skin",query,sizeof(query));
    SetPVarInt(playerid,"Skin",strval(query));
    db_get_field_assoc(Result,"Kaempferskin",query,sizeof(query));
    SetPVarInt(playerid,"Kämpferskin",strval(query));
    db_get_field_assoc(Result,"Jail",query,sizeof(query));
    SetPVarInt(playerid,"Jail",strval(query));
    db_get_field_assoc(Result,"JailTime",query,sizeof(query));
    SetPVarInt(playerid,"JailTime",strval(query));
    db_get_field_assoc(Result,"Chef",query,sizeof(query));
    SetPVarInt(playerid,"Chef",strval(query));
    db_get_field_assoc(Result,"GangChef",query,sizeof(query));
    SetPVarInt(playerid,"GangChef",strval(query));
    db_get_field_assoc(Result,"Hoehenmessgeraet",query,sizeof(query));
    SetPVarInt(playerid,"Höhenmessgerät",strval(query));
    db_get_field_assoc(Result,"Job",query,sizeof(query));
    SetPVarInt(playerid,"Job",strval(query));
    db_get_field_assoc(Result,"Gang",query,sizeof(query));
    SetPVarInt(playerid,"Gang",strval(query));
    db_get_field_assoc(Result,"TimeOut",query,sizeof(query));
    SetPVarInt(playerid,"TimeOut",strval(query));
    db_get_field_assoc(Result,"Leben",query,sizeof(query));
    SetPlayerHealth(playerid, floatstr(query));
    db_get_field_assoc(Result,"Ruestung",query,sizeof(query));
    SetPlayerArmour(playerid, floatstr(query));
    db_get_field_assoc(Result,"Wanted",query,sizeof(query));
    SetPlayerWantedLevel(playerid,strval(query));
    db_get_field_assoc(Result,"FightStyle",query,sizeof(query));
    SetPlayerFightingStyle(playerid,strval(query));
    db_get_field_assoc(Result,"TimeOutInteriorID",query,sizeof(query));
    SetPVarInt(playerid,"TimeOutInteriorID",strval(query));
    db_get_field_assoc(Result,"TimeOutWorldID",query,sizeof(query));
    SetPVarInt(playerid,"TimeOutWorldID",strval(query));
    db_get_field_assoc(Result,"TimeOutPosX",query,sizeof(query));
    SetPVarFloat(playerid,"TimeOutPosX",floatstr(query));
    db_get_field_assoc(Result,"TimeOutPosY",query,sizeof(query));
    SetPVarFloat(playerid,"TimeOutPosY",floatstr(query));
    db_get_field_assoc(Result,"TimeOutPosZ",query,sizeof(query));
    SetPVarFloat(playerid,"TimeOutPosZ",floatstr(query));
    db_get_field_assoc(Result,"TimeOutPosA",query,sizeof(query));
    SetPVarFloat(playerid,"TimeOutPosA",floatstr(query));
    }
    db_free_result(Result);
    return 1;
    }


    PS: Danke schonmal für deine Hilfe

  • oh, also muss ich jeder spalte, beim erstellen nen wert zuweisen? :SS


    Wenn du schlau bist, speicherst du beim erstellen einfach den User dann hast du alle Werte vorhanden..
    Ich mach das nicht anders
    Ich Inserte den Namen
    Speicher den User
    Lade den User


    Das ist das einfachste was man machen kann ;)

    All in all it's just another brick in the wall

  • so, er speichert nichts mehr, selbst den namen nicht.er lädt es aber, da wenn ich von hand in der datenbank nen wert eintrage und mein namen etc. geht alles.
    kann mal einer drüber schuen?

    stock Register(playerid,key[])
    {
    new query[1024];
    SendClientMessage(playerid,BLAU,"Erfolgreich registriert.");
    SetPlayerSkin(playerid,79);
    SetPVarInt(playerid,"Skin",79);
    SetPlayerScore(playerid,0);
    GivePlayerMoney(playerid,30000);
    SetPVarInt(playerid,"loggedin",1);
    format(query,sizeof(query),"INSERT INTO `Accounts` (`Name`,`Passwort`,`Geld`,`Rang`,`Banned`,`Handy`,`Skin`,`KaempferSkin`,`Jail`,`JailTime`,`Chef`,`GangChef`,`Hoehenmessgeraet`,`Job`,`Gang`,`TimeOut`,`Leben`,`Ruestung`,`Wanted`,`FightStyle`,`TimeOutInteriorID`,`TimeOutWorldID`,`TimeOutPosX`,`TimeOutPosY`,`TimeOutPosZ`,`TimeOutPosA`) VALUES ('%s','%s','%d','0','0','0','0','0','0','0','0','0','0','0','0','0','100.0000','100.0000','0','0','0','0','0.0000','0.0000','0.0000','0.0000')",
    SpielerName(playerid),key,GetPlayerMoney(playerid));
    db_query(Accounts,query);
    return 1;
    }


    stock Login(playerid,key[])
    {
    new query[128];
    format(query, sizeof(query), "SELECT * FROM `Accounts` WHERE `Name` = '%s' AND `Passwort` = '%s'",SpielerName(playerid),key);
    new DBResult:Result = db_query(Accounts, query);
    if(db_num_rows(Result)!=0)
    {
    LoadAccount(playerid);
    SendClientMessage(playerid,BLAU,"Erfolgreich eingeloggt!");
    }
    else
    {
    SendClientMessage(playerid,BLAU,"Falsches Passwort!");
    ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Bitte gebe dein Passwort ein!","Login","Abbrechen");
    }
    db_free_result(Result);
    return 1;
    }


    stock LoadAccount(playerid)
    {
    new DBResult:Result, query[128];
    format(query, sizeof(query), "SELECT * FROM `Accounts` WHERE `Name` = '%s'",SpielerName(playerid));
    Result = db_query(Accounts,query);
    if(db_num_rows(Result) > 0)
    {
    db_get_field_assoc(Result,"Geld",query,sizeof(query));
    GivePlayerMoney(playerid,strval(query));
    db_get_field_assoc(Result,"Rang",query,sizeof(query));
    SetPVarInt(playerid,"Rang",strval(query));
    db_get_field_assoc(Result,"Banned",query,sizeof(query));
    SetPVarInt(playerid,"Banned",strval(query));
    db_get_field_assoc(Result,"Handy",query,sizeof(query));
    SetPVarInt(playerid,"Handy",strval(query));
    db_get_field_assoc(Result,"Skin",query,sizeof(query));
    SetPVarInt(playerid,"Skin",strval(query));
    db_get_field_assoc(Result,"Kaempferskin",query,sizeof(query));
    SetPVarInt(playerid,"Kämpferskin",strval(query));
    db_get_field_assoc(Result,"Jail",query,sizeof(query));
    SetPVarInt(playerid,"Jail",strval(query));
    db_get_field_assoc(Result,"JailTime",query,sizeof(query));
    SetPVarInt(playerid,"JailTime",strval(query));
    db_get_field_assoc(Result,"Chef",query,sizeof(query));
    SetPVarInt(playerid,"Chef",strval(query));
    db_get_field_assoc(Result,"GangChef",query,sizeof(query));
    SetPVarInt(playerid,"GangChef",strval(query));
    db_get_field_assoc(Result,"Hoehenmessgeraet",query,sizeof(query));
    SetPVarInt(playerid,"Höhenmessgerät",strval(query));
    db_get_field_assoc(Result,"Job",query,sizeof(query));
    SetPVarInt(playerid,"Job",strval(query));
    db_get_field_assoc(Result,"Gang",query,sizeof(query));
    SetPVarInt(playerid,"Gang",strval(query));
    db_get_field_assoc(Result,"TimeOut",query,sizeof(query));
    SetPVarInt(playerid,"TimeOut",strval(query));
    db_get_field_assoc(Result,"Leben",query,sizeof(query));
    SetPlayerHealth(playerid, floatstr(query));
    db_get_field_assoc(Result,"Ruestung",query,sizeof(query));
    SetPlayerArmour(playerid, floatstr(query));
    db_get_field_assoc(Result,"Wanted",query,sizeof(query));
    SetPlayerWantedLevel(playerid,strval(query));
    db_get_field_assoc(Result,"FightStyle",query,sizeof(query));
    SetPlayerFightingStyle(playerid,strval(query));
    db_get_field_assoc(Result,"TimeOutInteriorID",query,sizeof(query));
    SetPVarInt(playerid,"TimeOutInteriorID",strval(query));
    db_get_field_assoc(Result,"TimeOutWorldID",query,sizeof(query));
    SetPVarInt(playerid,"TimeOutWorldID",strval(query));
    db_get_field_assoc(Result,"TimeOutPosX",query,sizeof(query));
    SetPVarFloat(playerid,"TimeOutPosX",floatstr(query));
    db_get_field_assoc(Result,"TimeOutPosY",query,sizeof(query));
    SetPVarFloat(playerid,"TimeOutPosY",floatstr(query));
    db_get_field_assoc(Result,"TimeOutPosZ",query,sizeof(query));
    SetPVarFloat(playerid,"TimeOutPosZ",floatstr(query));
    db_get_field_assoc(Result,"TimeOutPosA",query,sizeof(query));
    SetPVarFloat(playerid,"TimeOutPosA",floatstr(query));
    }
    db_free_result(Result);
    return 1;
    }
    stock SpielerSpeichern(playerid)
    {
    if(GetPVarInt(playerid,"loggedin")!=1) return 1;
    new query[1024],Float:health, Float:ruestung;
    GetPlayerHealth(playerid,health);
    GetPlayerArmour(playerid,ruestung);
    format(query,sizeof(query), "UPDATE `Accounts` SET `Geld` = '%d', `Rang` = '%d', `Banned` = '%d',`Handy` = '%d', `Skin` = '%d', `Kaempferskin` = '%d', `Jail` = '%d',`JailTime` = '%d', `Chef` = '%d',`GangChef` = '%d',`Hoehenmessgeraet` = '%d',`Job` = '%d',`Gang` = '%d',`FightStyle` = '%d',`Wanted` = '%d',`Leben` = '%f',`Ruestung` = '%f',`TimeOutInteriorID` = '%d',`TimeOutWorldID` = '%d',`TimeOutPosX` = '%f',`TimeOutPosY` = '%f',`TimeOutPosZ` = '%f',`TimeOutPosA` = '%f' WHERE `NAME` = '%s'",
    GetPlayerMoney(playerid),GetPVarInt(playerid,"Rang"),GetPVarInt(playerid,"Banned"),GetPVarInt(playerid,"Handy"),GetPVarInt(playerid,"Skin"),GetPVarInt(playerid,"Kämpferskin"),GetPVarInt(playerid,"Jail"),GetPVarInt(playerid,"JailTime"),
    GetPVarInt(playerid,"Chef"),GetPVarInt(playerid,"GangChef"),GetPVarInt(playerid,"Höhenmessgerät"),GetPVarInt(playerid,"Job"),GetPVarInt(playerid,"Gang"),GetPVarInt(playerid,"TimeOut"),GetPlayerWantedLevel(playerid),health,ruestung,
    GetPlayerFightingStyle(playerid),GetPVarInt(playerid,"TimeOutInteriorID"),GetPVarInt(playerid,"TimeOutWorldID"),GetPVarFloat(playerid,"TimeOutPosX"),GetPVarFloat(playerid,"TimeOutPosY"),GetPVarFloat(playerid,"TimeOutPosZ"),GetPVarFloat(playerid,"TimeOutPosA"),SpielerName(playerid));
    db_query(Accounts,query);
    return 1;
    }

    2 Mal editiert, zuletzt von firestormZ ()