Help me with this(to be read carefully)!!!
#1

I made a login system with dini,following a tutorial on *******:

pawn Код:
#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");
    }
   new pname[MAX_PLAYER_NAME],string[22+MAX_PLAYER_NAME];
   GetPlayerName(playerid,pname,sizeof(pname));
   format(string,sizeof(string),"%s has joined the server",pname);
   SendClientMessageToAll(COLOR_GREY,string);
    return 1;
}

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

            {
                SendClientMessage(playerid,COLOR_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);
                return 1;
            }
        }
    }
    if(dialogid==DIALOG_REGISTER)
    {
        if(response==0)
        {
            SendClientMessage(playerid,COLOR_RED,"You have been kicked for not registering in.");
            Kick(playerid);
            return 1;
        }
        if(response==1)
        {
            if(!strlen(inputtext))
            {
                SendClientMessage(playerid,COLOR_RED,"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,COLOR_GREEN,"Successfully registered");
    dini_IntSet(String,"Level",0);
    GivePlayerMoney(playerid,2000);
    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,COLOR_GREEN,"Successfully logged");
        PlayerPlaySound(playerid,1057,0,0,0);
        GivePlayerMoney(playerid,2000);
        return 1;
    }
    else
    {
        SendClientMessage(playerid,COLOR_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;
    }

}
Now here are the problems(no compiling errors):

1)In-game is working perfectly,there's a single problem,if someone types in a wrong password several times(as he's doing that the class selecton shows up),if he presses spawn he can spawn without logging in.How to make so that if he selects "Spawn",and he is not logged yet he can't spawn.

2)How to make a saving system(saves the score and money of a player,so when he logs in he spawns with the money and his score.

3)You may see somewhere at "stock Login" - GivePlayerMoney(playerid,2000) and I'm not sure if that's right,as I want to set 2000$ as start-in ammount money(every new player that joins will spawn with that start ammount of money)
WARNING!!!EVERY USER OF Y_INI IS ASKED NICELY NOT TO ANSWER THIS TOPIC IF HE CAN'T/NOT TELL ME SWITCH TO Y_INI BECAUSE IT'S EASIER!!!
Reply
#2

Anyone?
Reply
#3

Quote:
Originally Posted by Cjgogo
Посмотреть сообщение
I made a login system with dini,following a tutorial on *******:

pawn Код:
#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");
    }
   new pname[MAX_PLAYER_NAME],string[22+MAX_PLAYER_NAME];
   GetPlayerName(playerid,pname,sizeof(pname));
   format(string,sizeof(string),"%s has joined the server",pname);
   SendClientMessageToAll(COLOR_GREY,string);
    return 1;
}

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

            {
                SendClientMessage(playerid,COLOR_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);
                return 1;
            }
        }
    }
    if(dialogid==DIALOG_REGISTER)
    {
        if(response==0)
        {
            SendClientMessage(playerid,COLOR_RED,"You have been kicked for not registering in.");
            Kick(playerid);
            return 1;
        }
        if(response==1)
        {
            if(!strlen(inputtext))
            {
                SendClientMessage(playerid,COLOR_RED,"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,COLOR_GREEN,"Successfully registered");
    dini_IntSet(String,"Level",0);
    GivePlayerMoney(playerid,2000);
    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,COLOR_GREEN,"Successfully logged");
        PlayerPlaySound(playerid,1057,0,0,0);
        GivePlayerMoney(playerid,2000);
        return 1;
    }
    else
    {
        SendClientMessage(playerid,COLOR_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;
    }

}
Now here are the problems(no compiling errors):

1)In-game is working perfectly,there's a single problem,if someone types in a wrong password several times(as he's doing that the class selecton shows up),if he presses spawn he can spawn without logging in.How to make so that if he selects "Spawn",and he is not logged yet he can't spawn.

2)How to make a saving system(saves the score and money of a player,so when he logs in he spawns with the money and his score.

3)You may see somewhere at "stock Login" - GivePlayerMoney(playerid,2000) and I'm not sure if that's right,as I want to set 2000$ as start-in ammount money(every new player that joins will spawn with that start ammount of money)
WARNING!!!EVERY USER OF Y_INI IS ASKED NICELY NOT TO ANSWER THIS TOPIC IF HE CAN'T/NOT TELL ME SWITCH TO Y_INI BECAUSE IT'S EASIER!!!
Question Number 1


Create a variable on the top of your script .....

pawn Код:
new gPlayerLogged[MAX_PLAYERS];
As the player connecting , his gPlayerLogged value will be 0;
pawn Код:
public OnPlayerConnect(playerid)
{
    gPlayerLogged[playerid] = 0;
    return 1;
}
On the register and login stocks ....
Add gPlayerLogged[playerid] = 1;
pawn Код:
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,COLOR_GREEN,"Successfully registered");
    dini_IntSet(String,"Level",0);
    gPlayerLogged[playerid] = 1;
    GivePlayerMoney(playerid,2000);
    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,COLOR_GREEN,"Successfully logged");
        PlayerPlaySound(playerid,1057,0,0,0);
        GivePlayerMoney(playerid,2000);
        gPlayerLogged[playerid] = 1;
        return 1;
    }
    else
    {
        SendClientMessage(playerid,COLOR_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;
    }

}
Now ....
pawn Код:
public OnPlayerSpawn(playerid)
{
    if(gPlayerLogged[playerid] == 0) return Kick(playerid);//So we can kick that player
    return 1;
}
Question Number 2
Saving by using dini ....
pawn Код:
public OnPlayerDisconnect(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(String,sizeof(String),"/Accounts/PlNm.txt",name);
    dini_IntSet(string,"level",GetPlayerScore(playerid));//We took the player's score and saved it to "level"
    return 1;
}
Now, we gotta load his level when he connects....
So at the login stock , nvm. It should look like this :
pawn Код:
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"));//Get the value from "level" and set it as his score
        SendClientMessage(playerid,COLOR_GREEN,"Successfully logged");
        PlayerPlaySound(playerid,1057,0,0,0);
        GivePlayerMoney(playerid,2000);
        return 1;
    }
    else
    {
        SendClientMessage(playerid,COLOR_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;
    }

}
Question Number 3


The first step, Is deleting GivePlayerMoney(playerid,2000) from the login stock , Cuz then every time you login , you will get 2000 dollars even that your account already registered.

Then Remove GivePlayerMoney(playerid,2000) on the login stock . Leave it in the register stock .

By the way, I suggest you to save the money like you save the score , and load it with the login stock.

Reply
#4

ok thanks i'll try it,now I go and eat(thanks man)as i see you good at scripting so I would aprreciate if you tell em what's the problem on the alst topic psoted(WHAT THE **** IS WRONG)
Reply
#5

to fix the spawn do this

Код:
new spawned[MAX_PLAYERS];
then on playerconnect

Код:
spawned[playerid] = 0;
when they login put

Код:
spawned[playerid] = 1;
and on player request spawn

Код:
if(spawned[playerid] == 0) return SendClientMessage(playerid,0xFFFFFFFF,"You Must Login To Spawn!");
now when they click spawn if their not logged it the spawn button just says you must login
Reply
#6

thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)