Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --set prespecifical settings for getting no probs with the Gamemode
- function createSQLOnScriptStart()
- executeSQLCreateTable ( "accounts", "accountname TEXT, accountpassword TEXT, level INTEGER, ip TEXT, serial TEXT, money INTEGER, bank INTEGER, online INTEGER")
- local online = 0
- local onlineCheck = 1
- executeSQLUpdate("accounts","online='"..online.."'","online='"..onlineCheck.."'")
- end
- addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),createSQLOnScriptStart)
- function dropMyTable()
- success = executeSQLDropTable("accounts")
- if (success ) then
- outputChatBox("Table Dropped!")
- end
- end
- addCommandHandler("drop",dropMyTable)
- --Login
- function loginCheck( loginName,loginPassword )
- --Check if there´s a password entered
- if (string.len(tostring(loginName)) <= 0 ) or (string.len(tostring(loginPassword)) <= 0) then
- outputChatBox("Please insert your logindata!",client,255,0,0)
- triggerClientEvent("onPasswordEntryIsWrong",getRootElement())
- else
- local getAccountViaDB = executeSQLQuery("SELECT * FROM accounts WHERE accountname=? AND accountpassword=?", loginName, md5(loginPassword) )
- local alreadyLoggedInCheck = executeSQLQuery("SELECT * FROM accounts WHERE accountname=? AND accountpassword=? AND online=?", loginName, md5(loginPassword), 1 )
- --check if the SQL is a table and if there is an accountname == loginName
- if (type(getAccountViaDB) == "table") and( #getAccountViaDB == 1) then
- --check if User is already logged in
- if (type(alreadyLoggedInCheck) == "table") and ( #alreadyLoggedInCheck ~= 1 ) then
- --Update my SQLStats on Login--
- local getDataFromDatabase = executeSQLQuery("SELECT * FROM accounts WHERE accountname=?",loginName)
- local ipFromPlayerRegistered = getPlayerIP(client)
- local serialFromPlayerRegistered = getPlayerSerial(client)
- local getNumberOfSameSerialsInDB = executeSQLQuery("SELECT * FROM accounts WHERE serial=?",serialFromPlayerRegistered)
- if (type(getNumberOfSameSerialsInDB) == "table") and (#getNumberOfSameSerialsInDB > 1 ) then
- local serialreset = "RESETTED"
- outputChatBox("MORESERIALS")
- executeSQLUpdate("accounts","serial='"..serialreset.."'","serial='"..serialFromPlayerRegistered.."'")
- end
- for i, updateStats in ipairs(getDataFromDatabase) do
- setPlayerMoney(client,updateStats.money)
- local online = 1
- executeSQLUpdate("accounts","ip='"..ipFromPlayerRegistered.."',serial='"..serialFromPlayerRegistered.."',online='"..online.."'","accountname='"..loginName.."'")
- end
- --Spawn the player and other stuff for spawn--
- spawnPlayer( client,1213.4375, -6.7730188369751, 1000.921875 )
- setElementInterior( client, 2 )
- setElementRotation( client, 0,0,90)
- r,g,b=math.random(0,255),math.random(0,255),math.random(0,255)
- createBlipAttachedTo(client,0,2,r,g,b)
- fadeCamera( client, true, 3.0, 0, 0, 0 )
- setCameraTarget(client,client)
- outputChatBox("You have been successfully logged in!",client,255,0,0)
- else
- outputChatBox("Your account is already logged in!",client,255,0,0)
- triggerClientEvent("onPasswordEntryIsWrong",getRootElement())
- end
- else
- triggerClientEvent("onPasswordEntryIsWrong",getRootElement())
- outputChatBox("The loginName: "..tostring(loginName).. " or your password: "..loginPassword.." is wrong!",client,255,0,0)
- end
- end
- end
- addEvent("checkMyLogin",true)
- addEventHandler("checkMyLogin",getRootElement(),loginCheck)
- --Registration
- function registerPlayer(userName,password,passwordReEntry)
- if userName ~= nil and password ~= nil and passwordReEntry ~= nil then
- local playerSerial = getPlayerSerial(client)
- local accountAvailable = executeSQLQuery("SELECT * FROM accounts WHERE serial=?",playerSerial)
- if (type(accountAvailable) == "table") and( #accountAvailable ~= 0) then
- outputChatBox("Only one account per serial is allowed!",client,255,0,0)
- return
- else
- local checkIfAccountAvailable = executeSQLQuery("SELECT * FROM accounts WHERE accountname =?",userName)[1]
- if (string.len(password) < 6) then
- outputChatBox("Your password should be at least 6 chars. long!",client,255,0,0)
- elseif (password ~= passwordReEntry) then
- outputChatBox("Your password and your re-entered one arent the same!",client,255,0,0)
- elseif (string.len(userName) <= 0) then
- outputChatBox("Please insert an username!",client,255,0,0)
- elseif ( checkIfAccountAvailable ~= nil ) then
- outputChatBox("#FF0000This Username is already taken!#FFFFFF ( "..userName.." )", client, 255,0,0, true)
- return
- elseif (userName) and (password == passwordReEntry) then
- local ipFromPlayerRegistered = getPlayerIP(client)
- local serialFromPlayerRegistered = getPlayerSerial(client)
- executeSQLInsert("accounts","'"..userName.."','"..md5(password).."',0,'"..ipFromPlayerRegistered.."','"..serialFromPlayerRegistered.."',0,0","accountname,accountpassword,level,ip,serial,money,bank")
- outputChatBox("#FF0000Your account has been successfully created!#FFFFFF(User: "..tostring(userName)..", Password: "..tostring(password)..")",client,255,0,0,true)
- triggerClientEvent("onRegisterDone",getRootElement())
- end
- end
- end
- end
- addEvent("onClientRegisterFinish",true)
- addEventHandler("onClientRegisterFinish",getRootElement(),registerPlayer)
- --playerquit saves all your stats on your Quit to prevent statsloss
- function playerQuit(player)
- local playerMoney = getPlayerMoney(source)
- local playerSerial = getPlayerSerial(source)
- local accountName = executeSQLQuery("SELECT accountname FROM accounts WHERE serial=?",playerSerial)
- local onlineStatus = 0
- if (type(accountName) == "table") and (#accountName == 1) then
- for k,account in ipairs(accountName) do
- executeSQLUpdate("accounts","money='"..playerMoney.."',online='"..onlineStatus.."'","accountname='"..account.accountname.."'")
- end
- local attached = getAttachedElements ( source )
- if ( attached ) then
- for k,element in ipairs(attached) do
- if getElementType ( element ) == "blip" then
- destroyElement ( element )
- end
- end
- end
- end
- end
- addEventHandler("onPlayerQuit",getRootElement(),playerQuit)
- --Change your accountpassword if you forgot it ( JUST WORKS if your serial is the same )
- function changeAccountPW(source,command,newPassword)
- local playerSerial = getPlayerSerial(source)
- local getAccountToChangePW = executeSQLQuery("SELECT * FROM accounts WHERE serial=?",playerSerial)
- if newPassword == nil or newPassword == false then
- outputChatBox("Please fill out all gaps!",source,255,0,0)
- return
- end
- if (type(getAccountToChangePW)== "table") and (#getAccountToChangePW == 1) then
- if (string.len(newPassword) >= 6 ) then
- for k,getAccountChangePW in ipairs(getAccountToChangePW)do
- executeSQLUpdate("accounts","accountpassword='"..md5(newPassword).."'","serial='"..getAccountChangePW.serial.."'")
- outputChatBox("#FF0000Your password has been successfully changed to#FFFFFF("..newPassword..")!",source,255,0,0,true)
- end
- else
- outputChatBox("#FF0000Your password is too short!#FFFFFF ( Min 6 letters! )",source,255,0,0,true)
- end
- else
- outputChatBox("No account with your serial found!",source,255,0,0)
- end
- end
- addCommandHandler("npw",changeAccountPW)
Add Comment
Please, Sign In to add comment