Dini question (Maybe...)
#5

look here :

pawn Код:
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2

#include <a_samp>
#include <dini>

public OnPlayerConnect(playerid)
{
    new String[64];
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(String,sizeof(String),"/Accounts/PlNm.txt",name);
    if(dini_Exists(String))
    {
        ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Logging in","This account was found in data base,please type in your password to log in.","Login","Cancel");
    }
    else
    {
        ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Registration","Type in your password","Register","Cancel");
    }
        return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
            if(dialogid==DIALOG_LOGIN)
    {
        if(response==0)
        {
            SendClientMessage(playerid,BLUE,"You have been kicked for not loging in.");
            Kick(playerid);
            return 1;
        }
        if(response==1)
        {
            if(!strlen(inputtext))

            {
                SendClientMessage(playerid,RED,"This password is too short");
                ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Logging in","This account was found in data base,please type in your password to log in.","Login","Cancel");
                return 1;
            }
            else
            {
                Login(playerid,inputtext);
                PlayerPlaySound(playerid,1057,0,0,0);
                return 1;
            }
        }
    }
    if(dialogid==DIALOG_REGISTER)
    {
        if(response==0)
        {
            SendClientMessage(playerid,BLUE,"You have been kicked for not registering in.");
            Kick(playerid);
            return 1;
        }
        if(response==1)
        {
            if(!strlen(inputtext))
            {
                SendClientMessage(playerid,BLUE,"This password is too short");
                ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Registration","Type in your password","Register","Cancel");
                return 1;
            }
            else
            {
                Register(playerid,inputtext);
                return 1;
            }
        }
    }
        return 1;
}

stock Register(playerid,key[])
{
    new String[64];
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(String,sizeof(String),"/Accounts/PlNm.txt",name);
    dini_Create(String);
    dini_Set(String,"Password",key);
    SendClientMessage(playerid,BLUE,"Successfully registered");
    dini_IntSet(String,"Level",0);
    return 1;
}

stock Login(playerid,key[])
{
    new String[64];
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(String,sizeof(String),"/Accounts/PlNm.txt",name);
    if(!strcmp(key,dini_Get(String,"Password"),false))
    {
        SetPlayerScore(playerid,dini_Int(String,"Level"));
        SendClientMessage(playerid,BLUE,"Successfully logged");
        return 1;
    }
    else
    {
        SendClientMessage(playerid,RED,"Wrong password.");
        PlayerPlaySound(playerid,1055,0,0,0);
        ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Logging in","This account was found in data base,please type in your password to log in.","Login","Cancel");
        return 1;
    }
   
}
I hope this helped you a lot :P
Reply


Messages In This Thread
Dini question (Maybe...) - by sim_sima - 26.04.2011, 16:21
Re: Dini question (Maybe...) - by MadeMan - 26.04.2011, 16:28
Re: Dini question (Maybe...) - by sim_sima - 26.04.2011, 16:35
Re: Dini question (Maybe...) - by MadeMan - 26.04.2011, 16:40
Re: Dini question (Maybe...) - by Cjgogo - 26.04.2011, 16:40
Re: Dini question (Maybe...) - by xDeadlyBoy - 26.04.2011, 16:42
Re: Dini question (Maybe...) - by sim_sima - 26.04.2011, 16:52
Re: Dini question (Maybe...) - by sim_sima - 26.04.2011, 16:56
Re: Dini question (Maybe...) - by Sinner - 26.04.2011, 17:00
Re: Dini question (Maybe...) - by MadeMan - 26.04.2011, 17:01

Forum Jump:


Users browsing this thread: 1 Guest(s)