Jump to content

does serial exist


JimmyJ

Recommended Posts

Posted

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.

Posted

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 

Posted

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) 

Posted

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 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...