Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.SCmysql:exec("CREATE TABLE IF NOT EXISTS accounts (id INT, username TEXT, password LONGTEXT, pin TEXT, email TEXT, serial TEXT, dateJoined TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)")
- exports.SCmysql:exec("CREATE TABLE IF NOT EXISTS accountsData (username TEXT, data LONGTEXT)")
- function register (plr, user, pass, email, pin)
- local hashedPass = sha256(pass)
- local query = exports.SCmysql:query("SELECT * FROM accounts")
- local accQuery = exports.SCmysql:query("SELECT * FROM accounts WHERE username=?", user)
- local serQuery = exports.SCmysql:query("SELECT * FROM accounts WHERE serial=?", getPlayerSerial(plr))
- if (#accQuery > 0) then return triggerClientEvent(plr, "SCaccounting:fail", plr, "Registration has failed, Account Already Exists!") end
- if (#accQuery > 1) then return triggerClientEvent(plr, "SCaccounting:fail", plr, "Registration has failed, You can only register 2 accounts per serial!") end
- local exec = exports.SCmysql:exec("INSERT INTO accounts (id, username, password, pin, email, serial) VALUES (?,?,?,?,?,?)", #query+1, user, hashedPass, pin, email, getPlayerSerial(plr))
- local data = {
- ['cash'] = 50000,
- ['health'] = 100,
- ['armor'] = 100,
- ['location'] = toJSON({1480.9766845703, -1770.2244873047, 18.795755386353}),
- ['team'] = "Citizens",
- ['occupation'] = "New Citizen",
- ['skin'] = 0,
- ['rotation'] = 0,
- ['interior'] = 0,
- ['dimension'] = 0,
- }
- local exec2 = exports.SCmysql:exec("INSERT INTO accountsData (username, data) VALUES (?,?)", user, toJSON(data))
- if (exec) then
- triggerClientEvent(plr, "SCaccounting:success", plr)
- else
- triggerClientEvent(plr, "SCaccounting:fail", plr, "Registration has failed, try contacting any developer or report on forums !")
- end
- end
- addEvent("SCaccounting:RegisterPlayer", true)
- addEventHandler("SCaccounting:RegisterPlayer", root, register)
- function login (plr, user, pass)
- local hashedPass = sha256(pass)
- local accQuery = exports.SCmysql:query("SELECT * FROM accounts WHERE username=?", user)
- local emailQuery = exports.SCmysql:query("SELECT * FROM accounts WHERE email=?", user)
- if (#accQuery > 0) then
- accPass = accQuery[1].password
- accUser = user
- elseif (#emailQuery > 0) then
- accPass = emailQuery[1].password
- accUser = emailQuery[1].username
- else
- triggerClientEvent(plr, "SCaccounting:fail", plr, "Signing in has failed, Account not found !")
- end
- iprint(hashedPass, accUser, accPass)
- if (hashedPass == accPass) then
- local data = exports.SCmysql:query("SELECT * FROM accountsData WHERE username=?", accUser)
- local dataTable = fromJSON(data[1].data)
- local x,y,z = unpack(fromJSON(dataTable['location']))
- spawnPlayer(plr, x,y,z, dataTable.rotation, dataTable.skin, dataTable.interior or 0, dataTable.dimension or 0, getTeamFromName(dataTable.team))
- setElementData(plr, "Occupation", dataTable.occupation)
- setElementHealth(plr, dataTable.health)
- setPlayerArmor(plr, dataTable.armor)
- givePlayerMoney(plr, dataTable.cash)
- setElementData(plr, "logged in", true)
- setElementData(plr, "accName", accUser)
- iprint("logged in")
- fadeCamera(plr, true)
- setCameraTarget(plr, plr)
- else
- triggerClientEvent(plr, "SCaccounting:fail", plr, "Signing in has failed, Wrong Password !")
- end
- end
- addEvent("SCaccounting:LoginPlayer", true)
- addEventHandler("SCaccounting:LoginPlayer", root, login)
- function saveDataWhenQuit ()
- local user = getElementData(source, "accName")
- if (user == false) then return false end
- local money = getPlayerMoney(source)
- local team = getTeamName(getPlayerTeam(source))
- local x,y,z = getElementPosition(source)
- local rot = getElementRotation(source)
- local dim = getElementDimension(source)
- local int = getElementInterior(source)
- local skin = getElementModel(source)
- local health = getElementHealth(source)
- local armor = getPlayerArmor(source)
- local occupation = getElementData(source, "Occupation")
- exports.SCaccounting:setPlayerData(source, "cash", money)
- exports.SCaccounting:setPlayerData(source, "health", health)
- exports.SCaccounting:setPlayerData(source, "team", team)
- exports.SCaccounting:setPlayerData(source, "occupation", occupation)
- exports.SCaccounting:setPlayerData(source, "armor", armor)
- exports.SCaccounting:setPlayerData(source, "rotation", rot)
- exports.SCaccounting:setPlayerData(source, "dimension", dim)
- exports.SCaccounting:setPlayerData(source, "interior", int)
- exports.SCaccounting:setPlayerData(source, "skin", skin)
- exports.SCaccounting:setPlayerData(source, "location", toJSON({x,y,z}))
- end
- addEventHandler("onPlayerQuit", root, saveDataWhenQuit)
- function saveMyData (plr, cmd)
- local user = getElementData(plr, "accName")
- if (user == false) then return false end
- local money = getPlayerMoney(plr)
- local team = getTeamName(getPlayerTeam(plr))
- local x,y,z = getElementPosition(plr)
- local rot = getElementRotation(plr)
- local dim = getElementDimension(plr)
- local int = getElementInterior(plr)
- local skin = getElementModel(plr)
- local health = getElementHealth(plr)
- local armor = getPlayerArmor(plr)
- local occupation = getElementData(plr, "Occupation")
- exports.SCaccounting:setPlayerData(plr, "cash", money)
- exports.SCaccounting:setPlayerData(plr, "health", health)
- exports.SCaccounting:setPlayerData(plr, "team", team)
- exports.SCaccounting:setPlayerData(plr, "occupation", occupation)
- exports.SCaccounting:setPlayerData(plr, "armor", armor)
- exports.SCaccounting:setPlayerData(plr, "rotation", rot)
- exports.SCaccounting:setPlayerData(plr, "dimension", dim)
- exports.SCaccounting:setPlayerData(plr, "interior", int)
- exports.SCaccounting:setPlayerData(plr, "skin", skin)
- exports.SCaccounting:setPlayerData(plr, "location", toJSON({x,y,z}))
- end
- addCommandHandler("save", saveMyData)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement