05.10.2014, 16:20
Introduction
--> As title says, I will show you how to make a Login/Register system !You need:
--> To can start this filescript you need Dini, Dudb, Dutils :Dini.inc
Dudb.inc
Dutils.inc
Start:
--> After you downloaded 3 (Dini, Dudb, Dutils) we can start !1. --> So, firsts line add #includes, like :
Code:
#include <a_samp> #include <dini> #include <dudb>
Code:
enum pInfo
{
pAdmin, // will save player's Admin !
pVip, // will save player's Vip !
pCash, // will save player's Cash !
pScore, // will save player's Score !
pKills, // will save player's Kills !
pDeaths, // will save player's Deaths!
// here you can add more enums, wich saves what do you want
} // Closing Brackelet !
new PlayerInfo[MAX_PLAYERS][pInfo]; // Player Info
Code:
new gPlayerLogged[MAX_PLAYERS]; // If player it's logged ! If you get the errors: C:\Users\Tedi\Downloads\Desktop\samp03z_svr_R1_win32 (1)\filterscripts\H_System.pwn(58) : warning 203: symbol is never used: "PlayerInfo" C:\Users\Tedi\Downloads\Desktop\samp03z_svr_R1_win32 (1)\filterscripts\H_System.pwn(58) : warning 203: symbol is never used: "gPlayerLogged" Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase 2 Warnings. Don't worry, just says to you symbol it's never used, you will see at final will work !
Code:
#define PATH "/Users/%s.ini" // Stats will be saved in : "scriptfiles/users/"PlayerName.ini" *NOTE: Change "Users" to your Folder Name" *NOTE: You need to make folder with that name, else not, player's stats will be not saved !
[CODE]
Code:
public OnPlayerConnect(playerid);
{
Code:
public OnPlayerConnect(playerid) // OnPlayerConnect Public
{ // Open Brackelet !
gPlayerLogged[playerid] = 0; // if player isn't registered/logged !
new name[MAX_PLAYER_NAME], file[256]; // make variables (file--> users file); (new name --> New Player Name)
GetPlayerName(playerid, name, sizeof(name)); // Will get that player name !
format(file, sizeof(file), PATH, name); Will search about his .ini file !
if (!dini_Exists(file)) // If his file doesn't exists, then :
{ // open brackelet
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "-->{FF0000}Register {0066CC}Account", "{FF0000}Welcome, you are not registered!\n{0066CC}Enter your password below to can save your {FFFF00}Cash,Score {0066CC}Admin/Vip!", "Register", "Exit"); // Showin' Register Dialog
} // Closing Brackelet
if(fexist(file)) // If his .ini file exists then :
{ // Open brackelet !
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "-->{FF0000}Login {0066CC}Account", "{FF0000}Welcome back !\n{0066CC}Thank you because you are playing again on our server !\n{FFFF00}To can play, please input your{FF0000} password {FF0000}below!", "Login", "Exit"); // // Showin' Login Dialog !
} // Closing brackelet !
return 1; // to show we finished
} // Closing brackelet !
[CODE][CODE]
Code:
public OnPlayerDisconnect(playerid, reason)
{
Code:
new name[MAX_PLAYER_NAME], file[256]; // New name --> Player's name, file --> .ini player's file !
GetPlayerName(playerid, name, sizeof(name)); // Will get player's name !
format(file, sizeof(file), PATH, name); // Will search about his .ini file !
if(gPlayerLogged[playerid] == 1) // if player it's logged !
{ // Open brackelet !
dini_IntSet(file, "Score", PlayerInfo[playerid][pScore]); // His Score
dini_IntSet(file, "Money", PlayerInfo[playerid][pCash]); // His Cash
dini_IntSet(file, "Admin",PlayerInfo[playerid][pAdmin]); // His Admin
dini_IntSet(file, "pVip",PlayerInfo[playerid][pVip]); // His Vip
dini_IntSet(file, "Kills",PlayerInfo[playerid][pKills]); // His Kills
dini_IntSet(file, "Deaths",PlayerInfo[playerid][pDeaths]); // His Deaths
} // Closing brackelet
gPlayerLogged[playerid] = 0; // He aren't login = 0 !
return 1; // Finish OnPlayerDissconect
} // Closing Latest brackelet !
Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
--> So, we add:
--> FOR REGISTER DIALOG :
Code:
if (dialogid == 1) // First Dialog (Register Dialog)
{ // Open brackelet!
new name[MAX_PLAYER_NAME], file[256], string[128]; // his name, .ini file, string
GetPlayerName(playerid, name, sizeof(name)); // Will get player's name !
format(file, sizeof(file), PATH, name); // Search about .ini file name !
if(!response) return Kick(playerid); // If he hit Exit, will get kicked !
if (!strlen(inputtext)) return // What Password he will write in box !
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "-->{FF0000}Register {0066CC}Account", "{FF0000}Welcome, you are not registered!\n{0066CC}Enter your password below to can save your {FFFF00}Cash,Score {0066CC}Admin/Vip!", "Register", "Exit"); // Register Dialog !
dini_Create(file); // Dini will create .ini file for that player !
dini_IntSet(file, "Password", udb_hash(inputtext)); // Will save his password ! He can login again just with his password !
dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][pAdmin] = 0); // Will save his Admin (0 now)
dini_IntSet(file, "Money",PlayerInfo[playerid][pCash] = 500); // Will save his money, will be spawned with 500 $ !
dini_IntSet(file, "Score",PlayerInfo[playerid][pScore] = 1); // Will save his score, when he will be spawned with 1 Score !
dini_IntSet(file, "Kills",PlayerInfo[playerid][pKills] = 0);
dini_IntSet(file, "Deaths",PlayerInfo[playerid][pDeaths] = 0);
format(string, 128, "{FF0000}[--> Succesfully <--]: {FFFF00}%s {0066CC} you have been succesfully registered!", name, inputtext); // Chat Message !
SendClientMessage(playerid, -1, string); // Will put this message on registered player's chat!
gPlayerLogged[playerid] = 1; // Now, he is Auto-Logged (he don't need to put again his password, only if he exit and enter again on server !)
} // Closing Brackelet
Code:
if (dialogid == 2) // Dialog 2 (Login Dialog)
{ // Open brackelet
new name[MAX_PLAYER_NAME], file[256], string[128]; // player's name, .ini file, string
GetPlayerName(playerid, name, sizeof(name)); // Will get player's name !
format(file, sizeof(file), PATH, name); // Search about .ini file from that player !
if(!response) return Kick(playerid); // If he hit Exit he will be kicked !
if (!strlen(inputtext)) return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "-->{FF0000}Login {0066CC}Account", "{FF0000}Welcome back !\n{0066CC}Thank you because you are playing again on our server !\n{FFFF00}To can play, please input your{FF0000} password {FF0000}below!", "Login", "Exit"); // Our Login Dialog !
new tmp; // Variable !
tmp = dini_Int(file, "Password"); // Password !
if(udb_hash(inputtext) != tmp) // In that box if he don't put correct password from .ini file then :
{ // Open Brackelet
SendClientMessage(playerid, -1, "{FF0000}Wrong password! {0066CC}Try another one !"); // He will cannot login !
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "-->{FF0000}Login {0066CC}Account", "{FF0000}Welcome back !\n{0066CC}Thank you because you are playing again on our server !\n{FFFF00}To can player, please input your{FF0000}password {FF0000}below!", "Login", "Exit"); // And if his password it's wrong he will saw again our Login Dialog, to try again log in !
} // Closin brackelet !
else // Else
{ // Open brackelet !
gPlayerLogged[playerid] = 1; // 1 = He it's logged !
PlayerInfo[playerid][pAdmin] = dini_Int(file, "AdminLevel"); // If he have Admin, in .ini file will load his Admin before login !
SetPlayerScore(playerid, PlayerInfo[playerid][pScore]); // Will sets his score from last time , from .ini file !
GivePlayerMoney(playerid, dini_Int(file, "Money")-GetPlayerMoney(playerid)); // He will get money from last time, from .ini file !
SendClientMessage(playerid, -1, "{FF0000}[--> Succesfully <--]: {0066CC}You have been {FFFF00}successfully {0066CC}logged in!"); // This he will saw after Login !
} // Closing brackelet *1 !
} // Closing brackelet *2!
} // Closing latest brackele *2!
All Code:
Code:
#include <a_samp>
#include <dini>
#include <dudb>
enum pInfo
{
pAdmin,
pVip,
pCash,
pScore,
pKills,
pDeaths,
}
new PlayerInfo[MAX_PLAYERS][pInfo];
new gPlayerLogged[MAX_PLAYERS];
#define PATH "/Users/%s.ini"
#if defined FILTERSCRIPT
public OnFilterScriptInit()
{
print("\n--------------------------------------");
print(" *LOGIN/REGISTER SGYSTEM ");
print("--------------------------------------\n");
return 1;
}
#else
#endif
public OnGameModeInit()
{
SetGameModeText("H_System");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
return 1;
}
public OnGameModeExit()
{
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
return 1;
}
public OnPlayerConnect(playerid)
{
gPlayerLogged[playerid] = 0;
new name[MAX_PLAYER_NAME], file[256];
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), PATH, name);
if (!dini_Exists(file))
{
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "-->{FF0000}Register {0066CC}Account", "{FF0000}Welcome, you are not registered!\n{0066CC}Enter your password below to can save your {FFFF00}Cash,Score {0066CC}Admin/Vip!", "Register", "Exit");
}
if(fexist(file))
{
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "-->{FF0000}Login {0066CC}Account", "{FF0000}Welcome back !\n{0066CC}Thank you because you are playing again on our server !\n{FFFF00}To can play, please input your{FF0000} password {FF0000}below!", "Login", "Exit");
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new name[MAX_PLAYER_NAME], file[256];
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), PATH, name);
if(gPlayerLogged[playerid] == 1)
{
dini_IntSet(file, "Score", PlayerInfo[playerid][pScore]);
dini_IntSet(file, "Money", PlayerInfo[playerid][pCash]);
dini_IntSet(file, "Admin",PlayerInfo[playerid][pAdmin]);
dini_IntSet(file, "pVip",PlayerInfo[playerid][pVip]);
dini_IntSet(file, "Kills",PlayerInfo[playerid][pKills]);
dini_IntSet(file, "Deaths",PlayerInfo[playerid][pDeaths]);
}
gPlayerLogged[playerid] = 0;
return 1;
}
public OnPlayerText(playerid, text[])
{
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if (dialogid == 1)
{
new name[MAX_PLAYER_NAME], file[256], string[128];
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), PATH, name);
if(!response) return Kick(playerid);
if (!strlen(inputtext)) return
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "-->{FF0000}Register {0066CC}Account", "{FF0000}Welcome, you are not registered!\n{0066CC}Enter your password below to can save your {FFFF00}Cash,Score {0066CC}Admin/Vip!", "Register", "Exit");
dini_Create(file);
dini_IntSet(file, "Password", udb_hash(inputtext));
dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][pAdmin] = 0);
dini_IntSet(file, "Money",PlayerInfo[playerid][pCash] = 500);
dini_IntSet(file, "Score",PlayerInfo[playerid][pScore] = 0);
dini_IntSet(file, "Kills",PlayerInfo[playerid][pKills] = 0);
dini_IntSet(file, "Deaths",PlayerInfo[playerid][pDeaths] = 0);
format(string, 128, "{FF0000}[--> Succesfully <--]: {FFFF00}%s {0066CC} you have been succesfully registered!", name, inputtext);
SendClientMessage(playerid, -1, string);
ShowPlayerDialog(playerid, 3, DIALOG_STYLE_MSGBOX, "{FF0000}IMPORTANT!", "{FF0000}*NOTE:{0066CC}Thanks because you have registered on our server !\n{FFFF00}We hope you will enjoy him and our Staff wish you {0066CC}welcome ! :)","Exit", "");
gPlayerLogged[playerid] = 1;
}
if (dialogid == 2)
{
new name[MAX_PLAYER_NAME], file[256], string[128];
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), PATH, name);
if(!response) return Kick(playerid);
if (!strlen(inputtext)) return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Hi your registered", "Fucken awesome mate, your registered :D. Inpute your pw below", "Login", "Leave");
new tmp;
tmp = dini_Int(file, "Password");
if(udb_hash(inputtext) != tmp) {
SendClientMessage(playerid, -1, "{FF0000}Wrong password! {0066CC}Try another one !");
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "-->{FF0000}Login {0066CC}Account", "{FF0000}Welcome back !\n{0066CC}Thank you because you are playing again on our server !\n{FFFF00}To can player, please input your{FF0000}password {FF0000}below!", "Login", "Exit");
}
else
{
gPlayerLogged[playerid] = 1;
PlayerInfo[playerid][pAdmin] = dini_Int(file, "AdminLevel");
SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
GivePlayerMoney(playerid, dini_Int(file, "Money")-GetPlayerMoney(playerid));
SendClientMessage(playerid, -1, "{FF0000}[--> Succesfully <--]: {0066CC}You have been {FFFF00}successfully {0066CC}logged in!");
}
}
return 1;
}
Last Words:
--> I explained to all can understand !--> If I made a mistake, tell me !
--> Cheers! <--
Bugs:
*Tested Code:--> This code (Login/Register Dialog) was tested and no bugs, it's workin' fine !
--> If you find an bug, tell me, I will solve them !

Preview:



