pawn Код:
/*
Login / register system.
Saves Money, HP og score.
Remember to create a folder called "Users"
inside the "scriptfiles" folder on your server.
*/
// Includes
#include <a_samp>
#include <dini>
#include <dudb>
#include <dutils>
// Defines
#define UserFile "Users/%s.ini"
#define COLOR_YELLOW 0xFFFF00FF
#define COLOR_NORMALRED 0xAF0000FF
#define COLOR_SYSTEMRED 0xFF0000FF
#define COLOR_ORANGE 0xFF9900AA
#define COLOR_PINK 0xFF66FFAA
#define COLOR_VIOLET 0x9955DEEE
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_PURPLE 0xC2A2DAAA
#define COLOR_GREEN 0x009900FF
#define COLOR_GREY 0xAFAFAFFF
// Enums
enum pInfo
{
pMoney,
pHealth,
pScore,
pWantedLevel
}
// Variables
new gPlayerLogged[MAX_PLAYERS];
new PlayerInfo[MAX_PLAYERS][pInfo];
new OnceLogged[MAX_PLAYERS];
// Unused
#pragma unused ret_memcpy
// Callbacks
public OnFilterScriptInit()
{
print("Login/Register System by Sim_sima Loaded!");
return 1;
}
public OnPlayerConnect(playerid)
{
gPlayerLogged[playerid] = 0;
OnceLogged[playerid] = 0;
new name[MAX_PLAYER_NAME], file[128];
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), UserFile, name);
if(!dini_Exists(file))
{
new string[75 + MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
format(string, sizeof(string), "( ! ) The username '%s' is not registered. Please enter a password",name);
SendClientMessage(playerid, COLOR_GREEN, string);
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "{FFFF00}Account Management", "{009900}Register new account\n{FFFFFF}Enter a password", "Register", "Quit");
}
if(dini_Exists(file))
{
new string[80 + MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
format(string, sizeof(string), "( ! ) The username '%s' is already registered. Please enter your password",name);
SendClientMessage(playerid, COLOR_GREEN, string);
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "{FFFF00}Account Management", "{FFFFFF}Enter your password", "Login", "Quit");
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new name[MAX_PLAYER_NAME], file[128];
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), UserFile, name);
if(gPlayerLogged[playerid] == 1)
{
if(dini_Exists(file))
{
PlayerInfo[playerid][pMoney] = GetPlayerMoney(playerid);
PlayerInfo[playerid][pScore] = GetPlayerScore(playerid);
PlayerInfo[playerid][pWantedLevel] = GetPlayerWantedLevel(playerid);
dini_IntSet(file, "Money",PlayerInfo[playerid][pMoney]);
new Float:Health;
GetPlayerHealth(playerid, Health);
dini_FloatSet(file, "Health", floatround(Health));
dini_IntSet(file, "Score", PlayerInfo[playerid][pScore]);
dini_IntSet(file, "WantedLevel", PlayerInfo[playerid][pWantedLevel]);
}
}
gPlayerLogged[playerid] = 0;
OnceLogged[playerid] = 0;
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 1)
{
new name[MAX_PLAYER_NAME], file[128];
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), UserFile, name);
if(response)
{
if(strlen(inputtext) > 15)
{
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "{FFFF00}Account Management", "{AF0000}Password must be between 5-15 characters\n{FFFFFF}Enter a password", "Login", "Quit");
}
else if(strlen(inputtext) < 5)
{
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "{FFFF00}Account Management", "{AF0000}Password must be between 5-15 characters\n{FFFFFF}Enter a password", "Login", "Quit");
}
else
{
dini_Create(file);
dini_IntSet(file, "Password", udb_hash(inputtext));
dini_IntSet(file, "Money",PlayerInfo[playerid][pMoney] = 0);
dini_FloatSet(file, "Health",PlayerInfo[playerid][pHealth] = 100);
dini_IntSet(file, "Score",PlayerInfo[playerid][pScore] = 0);
dini_IntSet(file, "WantedLevel", PlayerInfo[playerid][pWantedLevel] = 0);
GameTextForPlayer(playerid, "Welcome", 3000, 5);
gPlayerLogged[playerid] = 1;
OnceLogged[playerid] = 1;
}
}
else
{
SendClientMessage(playerid, COLOR_SYSTEMRED, "( ! ) You need to log in to play on this server. Please come again soon");
Kick(playerid);
gPlayerLogged[playerid] = 0;
OnceLogged[playerid] = 0;
}
}
if(dialogid == 2)
{
new name[MAX_PLAYER_NAME], file[128];
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), UserFile, name);
if(!response)
{
SendClientMessage(playerid, COLOR_SYSTEMRED, "( ! ) You need to log in to play on this server. Please come again soon");
Kick(playerid);
}
new tmp;
tmp = dini_Int(file, "Password");
if(udb_hash(inputtext) != tmp)
{
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "{FFFF00}Account Management", "{AF0000}Wrong password\n{FFFFFF}Enter your password", "Login", "Quit");
}
else
{
gPlayerLogged[playerid] = 1;
OnceLogged[playerid] = 1;
GameTextForPlayer(playerid, "Welcome", 3000, 5);
// Give loaded stuff to player from file
GivePlayerMoney(playerid, dini_Int(file, "Money"));
SetPlayerHealth(playerid, dini_Float(file, "Health"));
SetPlayerScore(playerid, dini_Int(file, "Score"));
SetPlayerWantedLevel(playerid, dini_Int(file, "WantedLevel"));
}
}
return 1;
}
public OnPlayerRequestSpawn(playerid)
{
new name[MAX_PLAYER_NAME], file[128];
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), UserFile, name);
if(OnceLogged[playerid] == 1)
{
SetPlayerWantedLevel(playerid, dini_Int(file, "WantedLevel"));
OnceLogged[playerid] = 0;
}
if(gPlayerLogged[playerid] == 0)
{
SendClientMessage(playerid, COLOR_SYSTEMRED, "( ! ) Please log in first");
return 0;
}
return 1;
}
public OnFilterScriptExit()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
CallLocalFunction("OnPlayerDisconnect", "%d", i);
}
return 1;
}