Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Login And Register System
- Created for Olabvii
- Credit To Michael ***
- Olabvii Has Full Registeration Of This Script.
- Hope this is a helping hand.
- */
- #include <a_samp>
- #include <YSI/y_ini>
- #define DIALOG_REGISTER 1
- #define DIALOG_LOGIN 2
- #define DIALOG_SUCCESS_1 3
- #define DIALOG_SUCCESS_2 4 // dialogs.
- #define COL_WHITE "{FFFFFF}"
- #define COL_RED "{F81414}"
- #define COL_GREEN "{00FF22}"
- #define COL_LIGHTBLUE "{00CED1}" // You may or may not have seen this format before. break down below.
- /* COLOR Breakdown:
- COL_WHITE "{FFFFFF}" This cannot be used as a main color. But it is usefull to use on dialogs etc.
- Example:
- SendClientMessage(playerid,000000FF,"Hey, I cant use "COL_RED"Color"); this will print a message Hey, I cant use "Then in red" Color.
- basically you have changed the color mid script.
- */
- #define PATH "/Accounts/%s.ini" // Change the Users if you want it to save somewhere else explained below:
- /*
- PATH Breakdown:
- PATH "/Users/%.ini" This will create a file in the script file directory, in the sub directory of Users
- Examples:
- PATH "/Server/Users/%s.ini" This will create a file in scriptfile directory, sub directory of Server then Users
- PATH "/%s.ini" This can also be used, this will just save to your scriptfiles, i would recommend having some kind or directory though.
- */
- enum pInfo
- {
- pPassword,
- pScore,
- pMoney,
- pDeaths,
- pKills,
- pAdmin
- }
- new Logged[MAX_PLAYERS];
- new PlayerInfo[MAX_PLAYERS][pInfo]; // This users the set data above to create a varible
- /* Now we need to get some stock functions.*/
- /*Credits to Dracoblue*/
- stock udb_hash(buf[]) {
- new length=strlen(buf);
- new s1 = 1;
- new s2 = 0;
- new n;
- for (n=0; n<length; n++)
- {
- s1 = (s1 + buf[n]) % 65521;
- s2 = (s2 + s1) % 65521;
- }
- return (s2 << 16) + s1;
- } // Hashing the password, all good servers have this. Its not easy to be removed.
- stock UserPath(playerid)
- {
- new string[128],playername[MAX_PLAYER_NAME];
- GetPlayerName(playerid,playername,sizeof(playername));
- format(string,sizeof(string),PATH,playername);
- return string;
- }// This will be your path that will be saved notice PATH is on the format.
- stock SavePlayer(playerid)
- {
- new INI:File = INI_Open(UserPath(playerid));
- INI_WriteInt(File,"Score",PlayerInfo[playerid][pScore]);
- INI_WriteInt(File,"Money",PlayerInfo[playerid][pMoney]);
- INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
- INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
- INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]); // Saving Data
- }
- forward LoadUser_data(playerid,name[],value[]);
- public LoadUser_data(playerid,name[],value[])
- {
- INI_Int("Password",PlayerInfo[playerid][pPassword]); // Basically this is loading and then creating the saving process the now assigns "PlayerInfo[playerid][pPassword]" to Password
- INI_Int("Score",PlayerInfo[playerid][pScore]);
- INI_Int("Money",PlayerInfo[playerid][pMoney]);
- INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
- INI_Int("Kills",PlayerInfo[playerid][pKills]);
- INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
- return 1;
- }
- public OnPlayerDeath(playerid,killerid,reason)
- {
- SendDeathMessage(killerid,playerid,reason);
- PlayerInfo[playerid][pScore] --;
- PlayerInfo[playerid][pDeaths] ++;
- PlayerInfo[killerid][pScore] ++;
- PlayerInfo[killerid][pKills] ++;
- return 1;
- }
- public OnPlayerDisconnect(playerid,reason)
- {
- SavePlayer(playerid);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- if(fexist(UserPath(playerid))) // If the players path exists continue
- {
- INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
- }
- else // Register the player
- {
- ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,""COL_WHITE"Register",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- case DIALOG_REGISTER:
- {
- if(!response) return Kick(playerid); // This will kick the player if the hit "quit"
- if(response)
- {
- if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, ""COL_WHITE"Register",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
- new INI:File = INI_Open(UserPath(playerid));
- INI_SetTag(File,"Sexy Name");
- INI_WriteInt(File,"Password",udb_hash(inputtext));
- INI_WriteInt(File,"Score",0);
- INI_WriteInt(File,"Money",0);
- INI_WriteInt(File,"Deaths",0);
- INI_WriteInt(File,"Kills",0);
- INI_WriteInt(File,"Admin",0);
- SendClientMessage(playerid,0xFFFFFF,"Thank You For Registering.");
- Logged[playerid] = 1;
- }
- }
- case DIALOG_LOGIN:
- {
- if(!response) return Kick(playerid);
- if(response)
- {
- if(udb_hash(inputtext) == PlayerInfo[playerid][pPassword])
- {
- INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
- GivePlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
- SetPlayerScore(playerid,PlayerInfo[playerid][pScore]); // Loading the score.
- }
- else
- {
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
- }
- return 1;
- }
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement