Snoowy Posted January 14, 2018 Share Posted January 14, 2018 Hello! I started making a account system, however, I missed the registration. How do I do it just to register once? Thank you for help! MySQL Script local connection = nil addEventHandler("onResourceStart",resourceRoot,function(resource) connection = dbConnect("mysql","dbname=ig_mta;host=localhost;port=3306;","root","martinka02") if connection then outputDebugString(getResourceName(resource) .. " : connected to database.") return true else outputDebugString(getResourceName(resource) .. " : Unable to connect with database. Please contact Developer.") return false end end ) function _Query( ... ) if connection then local query = dbQuery(connection, ... ) local result = dbPoll(query,-1) return result else return false end end function _QuerySingle(str,...) if connection then local result = _Query(str,...) if type(result) == 'table' then return result[1] end else return false end end function _Exec(str,...) if connection then local query = dbExec(connection,str,...) return query else return false end end Account System - Server Side addEvent("loginPlayer", true) function loginPlayer(player, username, password, serial) local check = exports.mta_connection:_QuerySingle("SELECT * FROM accounts WHERE username = ?",username) if check then local serial = getPlayerSerial(player) local checkPass = check.password local checkSerial = check.serial if ( checkSerial == serial ) then if (checkPass == password) then logIn(player,tostring(username),tostring(password)) outputDebugString("User is loggined!") triggerClientEvent(player,"showHide",getRootElement()) else exports["notices"]:addNotification(root,"Hibás felhasználónév/jelszó!",'error') end else exports["notices"]:addNotification(root,"Ez a felhasználó nem ehhez a számítógéphez van társítva!",'error') end else exports["notices"]:addNotification(root,"Hibás felhasználónév/jelszó!",'error') end end addEventHandler("loginPlayer", getRootElement(),loginPlayer) addEvent("registerPlayer", true) function registerPlayer(player, username, password, email, serial, ip, money) if ( checkSerial ~= serial ) then local account = getAccount(username) if account == false then local ip = getPlayerIP(player) local money = 100 exports.mta_connection:_Exec("INSERT INTO accounts(username,password,email,serial,ip,money) values (?,?,?,?,?,?)",username,password,email,serial,ip,money) local addAccount = addAccount(tostring(username), tostring(password)) if addAccount then exports["notices"]:addNotification(root,"A felhasználó sikeresen létrehozva!",'succes') else exports["notices"]:addNotification(root,"Hiba történt! Keress fel egy fejlesztőt a problémával kapcsolatban!",'error') end else exports["notices"]:addNotification(root,"Ez a felhasználónév már foglalt! Válassz másikat!",'error') end else exports["notices"]:addNotification(root,"Ehhez a számítógéphez van felhasználó társítva!",'error') end end addEventHandler("registerPlayer", getRootElement(), registerPlayer) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now