These are my register/login commands, but you can some kind of transform them tou your scripts or i don't know. They're in latvian language, so try to translate yourself. I added comentars for easier translating. And these functions are just dini but renamed for easier use for me. Maybe they're useful for you:
Код:
if(strcmp(cmd, "/register", true) == 0)
{
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), "/users/%s.save", udb_encode(name));
if(FileExist(file))
{
if(NumberFromFile(file,"login")==0)
{
SendClientMessage(playerid, COLOR_LIGHTBLUE, "SERVER: Sis lietotajs jau ir registrets, ielogojaties ar /login."); //if already is registered
return 1;
}
else if(NumberFromFile(file,"login")==1)
{
SendClientMessage(playerid, COLOR_LIGHTBLUE, "SERVER: Sis lietotajs jau ir registrets, un jus jau esat ielogojies."); /if already logged in
return 1;
}
}
else if(!FileExist(file))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_LIGHTBLUE, "SERVER: Jus neesat ievadijis paroli."); //not written a password
return 1;
}
else if(strlen(tmp))
{
new ip[16];
new date[128], year, month, day;
getdate(year, month, day);
format(date, sizeof(date), "%d.%d.%d", day, month, year);
GetPlayerIp(playerid, ip, sizeof(ip));
CreateFile(file);
StringToFile(file, "password", tmp);
StringToFile(file, "ip", ip);
StringToFile(file, "regdate", date);
StringToFile(file, "logdate", date);
NumberToFile(file, "login", 1);
NumberToFile(file, "admin", 0);
NumberToFile(file, "mute", 0);
NumberToFile(file, "ban", 0);
NumberToFile(file, "money", 0);
NumberToFile(file, "score", 0);
NumberToFile(file, "kills", 0);
NumberToFile(file, "deaths", 0);
NumberToFile(file, "hours", 0);
NumberToFile(file, "minutes", 0);
NumberToFile(file, "seconds", 0);
NumberToFile(file, "rank", 0);
SendClientMessage(playerid, COLOR_LIGHTBLUE, "SERVER: Jus esat veiksmigi registrejies un esat automatiski ielogots."); //registered
format(string, sizeof(string), "[user] %s registered", name);
print(string);
return 1;
}
}
return 1;
}
if(strcmp(cmd, "/login", true) == 0)
{
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), "/users/%s.save", udb_encode(name));
if(!FileExist(file))
{
SendClientMessage(playerid, COLOR_LIGHTBLUE, "SERVER: Sis lietotajs nepastav, registrejaties ar /register."); //user does not exist use register
return 1;
}
else if(FileExist(file))
{
tmp=strtok(cmdtext, idx);
if(NumberFromFile(file,"login")==1)
{
SendClientMessage(playerid, COLOR_LIGHTBLUE, "SERVER: Tu jau esi ielogojies."); //already logged in
return 1;
}
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_LIGHTBLUE, "SERVER: Jus neesat ievadijis paroli."); //no password written
return 1;
}
else if(strlen(tmp))
{
if(strcmp(StringFromFile(file,"password"),tmp))
{
SendClientMessage(playerid, COLOR_LIGHTBLUE, "SERVER: Jus esat ievadijis nepareizu paroli."); //wrong password
return 1;
}
else if(!strcmp(StringFromFile(file,"password"),tmp))
{
if(NumberFromFile(file, "ban")==1)
{
format(string, sizeof(string), "SERVER: %s ir blokets par: blokets niks", name);
SendClientMessage(playerid, COLOR_LIGHTBLUE, "SERVER: Sis niks ir banots.");
SendClientMessageToAll(COLOR_LIGHTBLUE, string);
BanEx(playerid, "Banned nick");
return 1;
}
new ip[16];
new date[128], year, month, day;
getdate(year, month, day);
format(date, sizeof(date), "%d.%d.%d", day, month, year);
GetPlayerIp(playerid, ip, sizeof(ip));
StringToFile(file, "ip", ip);
StringToFile(file, "lastlog", date);
NumberToFile(file, "login", 1);
GivePlayerMoney(playerid, NumberFromFile(file, "money"));
SetPlayerScore(playerid, NumberFromFile(file, "score"));
SetPlayerRank(playerid, NumberFromFile(file, "rank"));
SendClientMessage(playerid, COLOR_LIGHTBLUE, "SERVER: Jus esat veiksmigi ielogojies."); //logged in
format(string, sizeof(string), "[user] %s logged in", name);
print(string);
return 1;
}
return 1;
}
}
return 1;
}