Jump to content

Detect account data in LOGED OUT accounts. Help!


Headshot4Fun

Recommended Posts

Posted (edited)

here goes the problem. Im making a rpg server, and im scripting like everything... anyway this is the real problem: my account system works like that:

1. You create your account

2. Choose your charater name

3. And we save the charater name in your account (setAccountData)

Now, how can i detect if this name is already in use by another account, because getAccountData/setAccountData only works when the player is LOGGED IN.

Is there another way? Because I Tried XML they told me XML its not the best idea because it can lag as hell the server, and mysql i don't understand the wiki exemples... are they trolling me?

Thanks!

Edited by Guest
Posted
for index , account in ipairs ( getAccounts () ) do 
if getAccountData ( account , "charName" ) == newCharName then 
outputChatBox("BLABLA" , player ) 
return 
end 
end 

This will check if the account data == something, if so it will return (stops the rest of the code execution)

Needs edit.

I hope I understood you correctly.

Posted
for index , account in ipairs ( getAccounts () ) do 
if getAccountData ( account , "charName" ) == newCharName then 
outputChatBox("BLABLA" , player ) 
return 
end 
end 

This will check if the account data == something, if so it will return (stops the rest of the code execution)

Needs edit.

I hope I understood you correctly.

But it will even check for offline accounts?
Posted (edited)
getAccounts() returns ALL server accounts, offline or online.
Hm, i get it.

Thanks JR and Solid for helping me to solve this puzzle. Now i have everything that my server needs to work! :D

Edited by Guest
  • MTA Team
Posted

Headshot4Fun, i recommend you create an sql table with a list of account names and their data using SQLite (it's inbuilt, not mysql)

Posted
Headshot4Fun, i recommend you create an sql table with a list of account names and their data using SQLite (it's inbuilt, not mysql)

As far as I remember, MTA uses SQL for accounts unless it's changed again but I doubt. So, no need to create another table for that.

  • MTA Team
Posted
Headshot4Fun, i recommend you create an sql table with a list of account names and their data using SQLite (it's inbuilt, not mysql)

As far as I remember, MTA uses SQL for accounts unless it's changed again but I doubt. So, no need to create another table for that.

it does, but using sql functions is better than acctn data. sometimes.
Posted

So, this should work, after all, but debugscript keep saying:

ERROR: ... server.lua:48: attempt to call a table value

But the fun part, is that THATS what im trying to do... heres relevantpart the code. This basically checks a account data in all accounts, compare them if they are the same you input ( nome ) and add them to a table ( resultado ) then it checks if theres results, if theres results: -- fail, else -- works!

function checarConta(nome) 
  
    local resultado = {} 
  
    for i,v in getAccounts() do 
        if getPlayerData(v,"char.nome") == nome then 
            table.insert(resultado,v) 
            return 
            else 
        end 
    end 
     
  
  
  
    if resultado[1] then 
        -- Fail 
         
    elseif not resultado[1] then 
        -- Win! 
    end 
end 
addEventHandler ( "checarConta", getRootElement ( ), checarConta) 

Im trying to make this way so there is no floods, because otherwise, i would receive alot of -- works and only one --fail if there is one.

Posted

this is wrong for i,v in getAccounts() do it need to be for i,v in pairs(getAccounts()) do

and getPlayerData is not a function that need to getAccountData(v,"char.none")

and on tabel insert you instert whit v the account now i don't know if you wanna insert the account or the account data and if the "nome" is not a local nome = ... the need to be "nome" not nome

function checarConta(nome) 
  
    local resultado = {} 
  
    for i,v in pairs  (getAccounts()) do 
        if getAccountData(v,"char.nome") == nome then 
            table.insert(resultado,v) 
            return 
            else 
        end 
    end 
    
  
  
  
    if resultado[1] then 
        -- Fail 
        
    elseif not resultado[1] then 
        -- Win! 
    end 
end 
addEventHandler ( "checarConta", getRootElement ( ), checarConta) 

Posted
What is getPlayerData.

And specify the error line.

Oh, what a idiot am i... changing it...
this is wrong for i,v in getAccounts() do it need to be for i,v in pairs(getAccounts()) do

and getPlayerData is not a function that need to getAccountData(v,"char.none")

and on tabel insert you instert whit v the account now i don't know if you wanna insert the account or the account data and if the "nome" is not a local nome = ... the need to be "nome" not nome

I Know, but for some reason i forgot it. Well, thats what happens when you try to script a gamemod at 3:00 am.

Edit shit, i can't just make it works. it returns the --fail when should return --true, and also, doen't return --true. Can some one help me to make this function, it should searches a accountData in all accounts and return false if someone have it, and true if noone haves it.

Heres the full relevant code:

function checarConta(nome) 
  
    local resultado = {} 
  
    for i,v in pairs  (getAccounts()) do 
        if getAccountData(v,"char.nome") == tostring(nome) then 
            return 
            else 
            table.insert(resultado,v) 
        end 
    end 
    
   outputChatBox(resultado[1],source) 
  
  
  
    if resultado[1] then 
        --resultado={} 
        outputChatBox("Fails",source) 
        
    elseif not resultado[1] then 
        outputChatBox("Works",source) 
        setElementDimension ( source, 0) 
        setPlayerName ( source,tostring(nome) ) 
     
        local UsuarioCn = getPlayerAccount(source) 
        setAccountData(UsuarioCn,"char.passouNoTutorial",true) 
        setAccountData(UsuarioCn,"char.nome",nome) 
        triggerClientEvent ( source, "DetectarNomeWin", source) 
  
    end 
end 
addEventHandler ( "checarConta", getRootElement ( ), checarConta) 

Posted

Actually, if the char name exists, there will be no resultado [ 1 ], so basically you are reversing it.

function checarConta(nome) 
  
    local resultado = {} 
  
    for i,v in pairs  (getAccounts()) do 
        if getAccountData(v,"char.nome") == tostring(nome) then 
            return 
            else 
            table.insert(resultado,v) 
           break 
        end 
    end 
    
   outputChatBox(resultado[1],source) 
  
  
  
    if not resultado[1] then 
        --resultado={} 
        outputChatBox("Fails",source) 
        
    elseif resultado[1] then 
        outputChatBox("Works",source) 
        setElementDimension ( source, 0) 
        setPlayerName ( source,tostring(nome) ) 
    
        local UsuarioCn = getPlayerAccount(source) 
        setAccountData(UsuarioCn,"char.passouNoTutorial",true) 
        setAccountData(UsuarioCn,"char.nome",nome) 
        triggerClientEvent ( source, "DetectarNomeWin", source) 
  
    end 
end 
addEventHandler ( "checarConta", getRootElement ( ), checarConta) 

Posted
Actually, if the char name exists, there will be no resultado [ 1 ], so basically you are reversing it.
function checarConta(nome) 
  
    local resultado = {} 
  
    for i,v in pairs  (getAccounts()) do 
        if getAccountData(v,"char.nome") == tostring(nome) then 
            return 
            else 
            table.insert(resultado,v) 
           break 
        end 
    end 
    
   outputChatBox(resultado[1],source) 
  
  
  
    if not resultado[1] then 
        --resultado={} 
        outputChatBox("Fails",source) 
        
    elseif resultado[1] then 
        outputChatBox("Works",source) 
        setElementDimension ( source, 0) 
        setPlayerName ( source,tostring(nome) ) 
    
        local UsuarioCn = getPlayerAccount(source) 
        setAccountData(UsuarioCn,"char.passouNoTutorial",true) 
        setAccountData(UsuarioCn,"char.nome",nome) 
        triggerClientEvent ( source, "DetectarNomeWin", source) 
  
    end 
end 
addEventHandler ( "checarConta", getRootElement ( ), checarConta) 

Worked, thanks man. Now i tested with some of my friend and it worked.

Thanks bro ;D

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...