JimmyJ Posted November 30, 2013 Posted November 30, 2013 Is there a way to check if a serial already exists in the database? I want to prevent multiple accounts from a single player but I am having trouble finding a way to check.
JimmyJ Posted December 1, 2013 Author Posted December 1, 2013 But is there a way to check the whole serial column to see if a serial already exists and return a true or false value?
Castillo Posted December 1, 2013 Posted December 1, 2013 Are you talking about the default account system?
Castillo Posted December 1, 2013 Posted December 1, 2013 You can't get the serial stored there. You can create a SQLite table and store serials with the account names there when they register. executeSQLQuery
Gallardo9944 Posted December 3, 2013 Posted December 3, 2013 This should be working. Though if you have tons of accounts (e.g. more than a thousand), spamming the function might slow down the server. The code is untested, report if any problems found. function isRegisteredWithSerial(serial) local accounts = getAccounts() for i=1,#accounts do local acc = accounts[i] local srl = getAccountData(acc,"serial") if srl == serial then -- If we found an account with the serial return true -- Return true end end return false -- Unless the interation finished and found nothing, return false end function onLogin(prev,new) -- Get the logged account serial local srl = getAccountData(new,"serial") if not srl then -- If the account doesn't have serial info yet setAccountData(new,"serial",getPlayerSerial(source)) -- Write it with the player's serial end end addEventHandler("onPlayerLogin",getRootElement(),onLogin) function customFunctionToCheck(player) local isreg = isRegisteredWithSerial(getPlayerSerial(player)) if isreg == true then outputChatBox("You have an account with your serial") else outputChatBox("Nope, you're not owning any account") end end addCommandHandler("check",customFunctionToCheck)
JimmyJ Posted December 7, 2013 Author Posted December 7, 2013 We have over 1000 people Is there any way to have mta search the database using something like this and have it return the results? select serial, count(*) from accounts group by serial having count(*) > 1
Castillo Posted December 7, 2013 Posted December 7, 2013 No, because MTA can't access the accounts database file like that.
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