Vice Underdogs
Scripting => Script Showroom => Topic started by: GiTo on November 15, 2022, 12:38:12 pm
-
CLASS.
class PlayerStats
{
Reg = false;
Log = false;
Password = null;
Kills = 0;
Deaths = 0;
Money = 0;
Bank = 0;
Level = 0;
IP = null;
UID = null;
AutoLog = false;
}
onScriptLoad.
stats <- array(GetMaxPlayers(), null);
db <- ConnectSQL("dataBase.db");
QuerySQL(db, "CREATE TABLE IF NOT EXISTS Account( Name TEXT, IP VARCHAR(15), Pass VARCHAR(255), Level NUMERIC DEFAULT 1, TimeReg VARCHAR(255) )");
QuerySQL(db, "CREATE TABLE IF NOT EXISTS Stats( Name TEXT, Money NUMERIC, Bank NUMERIC, Kills NUMERIC, Deaths NUMERIC ) ");
[/noae][/noae][/noae]
onPlayerJoin.
stats[player.ID] = PlayerStats();
accInfo(player);
onPlayerPart.
if(stats[player.ID].Reg) {
QuerySQL( db, "UPDATE Account SET Level='"+stats[ player.ID ].Level+"'WHERE Name LIKE '" + player.Name + "'" );
QuerySQL( db, "UPDATE Stats SET Money='"+stats[ player.ID ].Money+"', Bank='"+stats[ player.ID ].Bank+"', Kills='"+stats[ player.ID ].Kills+"', Deaths='"+stats[ player.ID ].Deaths+"' WHERE Name LIKE '" + player.Name + "'" );
}
accInfo function.
function accInfo(player)
{
local q = QuerySQL(db, "SELECT * FROM Account WHERE Name = '" + escapeSQLString(player.Name) + "'");
if(q)
{
stats[ player.ID ].IP = GetSQLColumnData(q, 1);
stats[ player.ID ].Password = GetSQLColumnData(q, 2);
stats[ player.ID ].Level = GetSQLColumnData(q, 3);
}
local q = QuerySQL(db, "SELECT * FROM Stats WHERE Name = '" + escapeSQLString(player.Name) + "'");
if(q) {
stats[ player.ID ].Money = GetSQLColumnData(q, 1);
stats[ player.ID ].Bank = GetSQLColumnData(q, 2);
stats[ player.ID ].Kills = GetSQLColumnData(q, 3);
stats[ player.ID ].Deaths = GetSQLColumnData(q, 4);
stats[ player.ID ].Reg = true;
}
if (player.IP == stats[ player.ID ].IP)
{
MessagePlayer("[#ffffff]"+player.Name+" [#1ABC9C]has auto-logged into the server.", player);
player.Cash = stats[ player.ID ].Money;
stats[ player.ID ].Log = true;
}
if (stats[player.ID].Reg == true && !stats[player.ID].Log)
{
stats[ player.ID ].Log = false;
stats[ player.ID ].AutoLog = false;
MessagePlayer("[#E74C3C]Your account is not logged-in, please type [#ffffff]/login <password> [#E74C3C]to access the account.",player);
}
if (stats[player.ID].Reg == false && stats[player.ID].Log == false)
{
MessagePlayer("[#E74C3C]Your account is not registered. please type [#ffffff]/register <password>[#E74C3C] to access the server.",player);
}
}
Commands.
if (cmd =="register")
{
if(!text) MessagePlayer("[#1ABC9C]/register <your password>",player);
else if (stats[player.ID].Reg == true) MessagePlayer("[#E74C3C]Your account is already registered.",player);
else {
local password = SHA256(text);
local now = date();
QuerySQL(db,"INSERT INTO Account(Name, IP, Pass, Level, TimeReg) VALUES('"+escapeSQLString(player.Name)+"', '"+player.IP+"', '"+password+"', '"+0+"', '"+now.year+"-"+now.month+"-"+now.day+"' ) ");
QuerySQL(db,"INSERT INTO Stats(Name, Money, Bank, Kills, Deaths) VALUES('"+escapeSQLString(player.Name)+"','"+0+"','"+0+"','"+0+"', '"+0+"') ");
{
stats[player.ID].Reg = true;
stats[player.ID].Log = true;
stats[player.ID].Level = 1;
stats[player.ID].Money = 0;
stats[player.ID].Bank = 0;
stats[player.ID].Kills = 0;
stats[player.ID].Deaths = 0;
stats[player.ID].AutoLog = true;
accInfo(player);
Message(""+player.Name+" [#1ABC9C]has registered in the server.");
}
}
}
else if (cmd == "login")
{
if(!text) MessagePlayer("[#1ABC9C]/login <your password>",player);
else if (stats[player.ID].Reg == false) MessagePlayer("[#E74C3C]Your account is not registered.",player);
else if (stats[player.ID].Log == true) MessagePlayer("[#E74C3C]Your account is already logged-in.",player);
else {
local q = QuerySQL(db, "SELECT * FROM Account WHERE Name = '" + escapeSQLString(player.Name) + "'");
if (q)
{
if ( SHA256(text) != GetSQLColumnData(q, 2)) MessagePlayer( "The password you entered is invalid.", player );
else {
stats[player.ID].Log = true;
Message(""+player.Name+" [#1ABC9C]has logged-in to the server.");
}
}
}
}
else if (cmd == "stats")
{
if (stats[player.ID].Reg == false) MessagePlayer("[#E74C3C]Your account is not registered.",player);
else if (stats[player.ID].Reg == true && stats[player.ID].Log == false) MessagePlayer("[#E74C3C]Your account is not logged-in.",player);
else {
MessagePlayer("[#1ABC9C]Kills: "+stats[player.ID].Kills+" | Deaths: "+stats[player.ID].Deaths+" | Money: $"+stats[player.ID].Money+" | Bank: $"+stats[player.ID].Bank+" | Level: "+stats[player.ID].Level+" ",player);
}
}
else if (cmd == "changepass")
{
if(!text) MessagePlayer("[#1ABC9C]/changepass <new password>",player);
else if (stats[player.ID].Reg == false) MessagePlayer("[#E74C3C]Your account is not registered.",player);
else if (stats[player.ID].Reg == true && stats[player.ID].Log == false) MessagePlayer("[#E74C3C]Your account is not logged-in.",player);
else {
local password = SHA256(text);
QuerySQL(db, "UPDATE Account SET Pass = '" + password + "' WHERE Name = '" + escapeSQLString(player.Name) + "'");
MessagePlayer("[#1ABC9C]Your password has been changed to: [#ffffff]"+text+"[#1ABC9C] (DO NOT FORGET IT)",player);
}
}
Commands - (4): /register | /login | /changepass | /stats
onPlayerDeath.
stats[player.ID].Deaths++;
onPlayerKill.
stats[player.ID].Deaths++;
stats[killer.ID].Kills++;
onPlayerRequestSpawn.
if(!stats[player.ID].Reg) { MessagePlayer([#E74C3C]Your account is not registered. please type [#ffffff]/register <password>[#E74C3C] to access the server.",player); return 0; }
if(stats[player.ID].Reg && stats[player.ID].Log == false) { MessagePlayer("[#E74C3C]Your account is not logged-in, please type [#ffffff]/login <password> [#E74C3C]to access the account.",player); return 0; }
Hello guys so it's me again ;D first time trying to make my own account system it might have alot of bugs if you encounter any so please let me know. The script is tested btw.