SA-MP Forums Archive
[Looking For] DINI Register/Login - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [Looking For] DINI Register/Login (/showthread.php?tid=115700)



[Looking For] DINI Register/Login - Niixie - 25.12.2009

Hello, im looking for a tutorial where i can learn how to make Register / Login scripts.
I've searched around and found alot of tutorials, but they didnt work?
I've also looked in other scripts to see how they did it, but i couldnt find out?
I would like one with DCMD and sscanf


Re: [Looking For] DINI Register/Login - DeathOnaStick - 25.12.2009

It's not a Tuturial, but i fixed the code from this one(CLICK)

For explaination just read the Tuturial.

_________________________________________________
Over script:

pawn Code:
enum pInfo
{
    Cash
}

new PlayerInfo[MAX_PLAYERS][pInfo];
new IsPlayerLogged[MAX_PLAYERS];
OnPlayerCommandText:

pawn Code:
dcmd(register, 8, cmdtext);
dcmd(login, 5, cmdtext);
Somewhere else:

pawn Code:
dcmd_register(playerid, params[])
{
    new file[MAX_PLAYER_NAME+4];
        new PName[MAX_PLAYER_NAME];
        new Pass[50];

      if(sscanf(params, "s", Pass))return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /register [Password] (maximum: 50 cells)");
      if(IsPlayerLogged[playerid]==1)return SendClientMessage(playerid, COLOR_SYSTEM, "You're already logged in!");

      GetPlayerName(playerid, PName, sizeof(PName));
      format(file,sizeof(file),"D-Admin/Players/%s.ini",PName);

      if(!fexist(file))
            {
              dini_Create(file);
              dini_IntSet(file,"Password", udb_hash(Pass));
              dini_IntSet(file,"Cash", 0);
              SendClientMessage(playerid, COLOR_SYSTEM, "[System]: Account Created! Please log in with /login.");
              PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
              printf("[Register]%s has created an account!", PName);
            }
            else
            {
              SendClientMessage(playerid, COLOR_SYSTEM, "[System]: Account Already Found In Database");
        PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
            }
        return 1;
}
pawn Code:
dcmd_login(playerid, params[])
{
  new file[MAX_PLAYER_NAME+4];
  new PlayerName[MAX_PLAYER_NAME];
    new LogPass[50];
    if(sscanf(params, "s", LogPass))return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /login [password]");

    if(IsPlayerLogged[playerid] == 1)
    {
        SendClientMessage(playerid, COLOR_GREEN, "You already are logged in!");
        return 1;
    }
    else
    {
        GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
        format(file,sizeof(file),"D-Admin/Players/%s.ini",PlayerName);
        if(fexist(file))
        {
          new FilePass[256];
        FilePass = dini_Get(file, "Password");
            if(udb_hash(LogPass) != strval(FilePass))
            {
              SendClientMessage(playerid, COLOR_RED, "Login Failed!");
              printf("%s has failed logging in!", PlayerName);
            }
            else
            {
                IsPlayerLogged[playerid] = 1;
                SetPlayerMoney(playerid, dini_Int(file, "Cash"));
                PlayerInfo[playerid][Cash] = dini_Int(file, "Cash");
                SendClientMessage(playerid, COLOR_GREEN, "[System]: You logged in!");
                PlayerPlaySound(playerid,1058,0.0,0.0,0.0);
            }
        }
    }
    return 1;
}
_________________________________________________


Cheers.




Re: [Looking For] DINI Register/Login - Niixie - 25.12.2009

Thank you, Another question?

Shouldn't there be somesort of saving when the user disconnect?


Re: [Looking For] DINI Register/Login - DeathOnaStick - 25.12.2009

Quote:
Originally Posted by Niixie
Thank you, Another question?

Shouldn't there be somesort of saving when the user disconnect?
Yes, it should. Use there, e.g. for saving money/cash:

OnPlayerDisconnect:
pawn Code:
dini_IntSet(file,"Cash", GetPlayerMoney(playerid));



Re: [Looking For] DINI Register/Login - Niixie - 25.12.2009

I get this error
Code:
error 017: undefined symbol "file"



Re: [Looking For] DINI Register/Login - Adam199 - 25.12.2009

Write in top of the script:
#define <file>


Re: [Looking For] DINI Register/Login - Niixie - 25.12.2009

Then i get these

Code:
error 074: #define pattern must start with an alphabetic character
error 017: undefined symbol "file"



Re: [Looking For] DINI Register/Login - SpiderPork - 25.12.2009

Quote:
Originally Posted by Adam199
Write in top of the script:
#define <file>
Oh god, now that's the most stupid answer I could ever thought of.

Niixie, don't just copy paste the code, you should edit it to suit your needs. It's most probably the file's directory, so you should get the player's name and edit the script to put the file in the folder you use to save accounts.

pawn Code:
new

   PlayerName[MAX_PLAYER_NAME];
   string[128];

GetPlayerName(playerid, PlayerName, sizeof(PlayerName));

format(string, sizeof(string), "Your directory for saving users/%s", PlayerName);
dini_IntSet(string, "Cash", GetPlayerMoney(playerid));



Re: [Looking For] DINI Register/Login - Niixie - 25.12.2009

Already did that ... I know that much

I just need to get rid of that file error thing? and i know that "#define file" is a VERY bad idea.


Re: [Looking For] DINI Register/Login - DeathOnaStick - 25.12.2009

Quote:
Originally Posted by Niixie
I get this error
Code:
error 017: undefined symbol "file"
Post line please.

#EDIT#: Figured it out by myself =P. Fix:

Add this to OnPlayerDisconnect:

pawn Code:
new file[MAX_PLAYER_NAME+4], PlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
format(file,sizeof(file),"D-Admin/Players/%s.ini",PlayerName);
(By the way: You need to create the directory "D-Admin/Players" into scriptfiles, because i took those codes out of my Admin script)

Cheers.