Jump to content

Register Once


iMonkr

Recommended Posts

Quote

is this coding is correct? if player register, he can't register again, is this correct?

 

bRegisteredOnce = {}

function registerPlayer(source, username, password )
    local accountAdded = addAccount(username, password)
    if (accountAdded) then
       triggerClientEvent (client, "createNotification", client, "#33aaccCogratuation #ffffffyour have account now .", "success")
       bRegisteredOnce[source] = true
    elseif bRegisteredOnce[source] == true then
        outputChatBox("You already registered on this server!",source)
    end
end
addEvent("register", true)
addEventHandler("register", root, registerPlayer)

 

Link to comment
  • Moderators

Hi!
I moved your thread to Scripting section, next time ask your scripting related questions here.

You have to check "bRegisteredOnce[source] == true" before(!) calling addAccount. Should look like this:

bRegisteredOnce = {}

function registerPlayer(source, username, password )
    if bRegisteredOnce[source] == true then
        outputChatBox("You already registered on this server!",source)
    else
        local accountAdded = addAccount(username, password)
        if (accountAdded) then
            triggerClientEvent (client, "createNotification", client, "#33aaccCogratuation #ffffffyour have account now .", "success")
            bRegisteredOnce[source] = true
        end
    end
end
addEvent("register", true)
addEventHandler("register", root, registerPlayer)

- Of course, this works until the next resource/server restart.

 

Probably a better solution if you use getAccountsBySerial to check is there any associated account to player's serial.

function registerPlayer(source, username, password )
    local serial = getPlayerSerial(source)
    local serialAccounts = getAccountsBySerial(serial)
  
    if serialAccounts and #serialAccounts > 0 then
        outputChatBox("You already registered on this server!",source)
    else
        local accountAdded = addAccount(username, password)
        if (accountAdded) then
            triggerClientEvent (client, "createNotification", client, "#33aaccCogratuation #ffffffyour have account now .", "success")
        end
    end
end
addEvent("register", true)
addEventHandler("register", root, registerPlayer)

 

Link to comment

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