Jump to content

Register Button


maky55

Recommended Posts

Hey again :D. The newbie scripter here.

Well this may seem real stupid thing to say, but I don't know how to add a register button to my login gui :\.

I've looked all over for a register function on the wiki, and i have found:

account addAccount ( string name, string pass ) 

I know it's a server side function, and i've tried messing about with the script to get it to register an account, but no luck here.

Any help with this would be appreciated!

Server:

local posX, posY, posZ = 2584.9523925781, -2209.318359375, 1.9927320480347 
local thePlayer = source 
function loginHandler(username, password) 
    local account = getAccount(username, password) 
    if ( account ) then 
        local loggin = logIn(source, account, password) 
        if ( loggin ) then 
            spawnPlayer(source, posX, posY, posZ) 
            fadeCamera(source, true) 
            setCameraTarget(source, source) 
            outputChatBox("Wow, you actually made it on", source) 
            triggerClientEvent(source, "hideLoginWindow", source) 
        end 
    else 
       outputChatBox("Invalid username or password!",source) 
    end 
end 
addEvent("submitLogin", true) 
addEventHandler("submitLogin", getRootElement(), loginHandler) 
  
function deathHandler() 
    spawnPlayer(source, posX, posY, posZ) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
end 
addEventHandler("onPlayerWasted", getRootElement(), deathHandler) 
  

Client:

local playerName = getPlayerName(localPlayer) 
local guiElements = { } 
  
function clientSubmitLogin() 
    local username = guiGetText(guiElements["edit_user"]) 
    local password = guiGetText(guiElements["edit_pass"]) 
    if ( username ~= "" and password ~= "" ) then 
        triggerServerEvent("submitLogin", localPlayer, username, password) 
     else 
        outputChatBox("Please enter a username and password.") 
    end 
end 
  
function createLoginWindow() 
    guiElements["login_window"] = guiCreateWindow(0.375, 0.375, 0.25, 0.25, "Please enter your Username and Password", true) 
    guiCreateLabel(0.0825, 0.225, 0.25, 0.25, "Username", true, guiElements["login_window"]) 
    guiCreateLabel(0.0825, 0.425, 0.25, 0.25, "Password", true, guiElements["login_window"]) 
    
    guiElements["edit_user"] = guiCreateEdit(0.415, 0.2, 0.5, 0.15, "", true, guiElements["login_window"]) 
    guiElements["edit_pass"] = guiCreateEdit(0.415, 0.4, 0.5, 0.15, "", true, guiElements["login_window"]) 
    guiEditSetMaxLength(guiElements["edit_user"], 20) 
    guiEditSetMaxLength(guiElements["edit_pass"], 20) 
    
    guiElements["login_button"] = guiCreateButton(0.415, 0.7, 0.25, 0.20, "Log In", true, guiElements["login_window"]) 
    addEventHandler("onClientGUIClick", guiElements["login_button"], clientSubmitLogin, false) 
end 
  
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function () 
        createLoginWindow() 
        outputChatBox("Welcome to My MTA:SA Server, please log in.") 
        showCursor(true) 
        guiSetInputEnabled(true) 
    end 
) 
function hideLoginWindow() 
    guiSetInputEnabled(false) 
    showCursor(false) 
    
    if ( isElement ( guiElements["login_window"] ) ) then 
        destroyElement ( guiElements["login_window"] ) 
    end 
end 
addEvent("hideLoginWindow", true) 
addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) 

Meta:

<meta> 
    <info author="Tiger" version="1.0" type="gamemode" name="Server" description="a simple spawn script" /> 
     
    <script src="Server\Server_Script.lua" /> 
        <script src="Client\gui.lua" type="client" /> 
</meta> 

Just for fun, here is what I tried to edit it too :D, atleast I tried ;):

Server:

local posX, posY, posZ = 2584.9523925781, -2209.318359375, 1.9927320480347 
local thePlayer = source 
  
function registerHandler(username, password) 
    local account = getAccount(username, password) 
    if ( account ) then 
        local register = addAccount(username, password) 
        if ( register ) then 
            outputChatbox("You have registered your account", source) 
        end 
    end 
end 
addEvent("submitRegister", true) 
addEventHandler("submitRegister", getRootElement(), registerHandler) 
  
function loginHandler(username, password) 
    local account = getAccount(username, password) 
    if ( account ) then 
        local loggin = logIn(source, account, password) 
        if ( loggin ) then 
            spawnPlayer(source, posX, posY, posZ) 
            fadeCamera(source, true) 
            setCameraTarget(source, source) 
            outputChatBox("Wow, you actually made it on", source) 
            triggerClientEvent(source, "hideLoginWindow", source) 
        end 
    else 
       outputChatBox("Invalid username or password!",source) 
    end 
end 
addEvent("submitLogin", true) 
addEventHandler("submitLogin", getRootElement(), loginHandler) 
  
function deathHandler() 
    spawnPlayer(source, posX, posY, posZ) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
end 
addEventHandler("onPlayerWasted", getRootElement(), deathHandler) 
     

Client:

local playerName = getPlayerName(localPlayer) 
local guiElements = { } 
  
function clientSubmitLogin() 
    local username = guiGetText(guiElements["edit_user"]) 
    local password = guiGetText(guiElements["edit_pass"]) 
    if ( username ~= "" and password ~= "" ) then 
        triggerServerEvent("submitLogin", localPlayer, username, password) 
     else 
        outputChatBox("Please enter a username and password.") 
    end 
end 
  
function clientSubmitPassword() 
    local username = guiGetText(guiElements["edit_user"]) 
    local password = guiGetText(guiElements["edit_pass"]) 
    if ( username ~= "" and password ~= "" ) then 
        triggerServerEvent("submitRegister", localPlayer, username, password) 
     else 
        outputChatBox("Please enter a username and password to create an account.") 
    end 
end 
  
function createLoginWindow() 
    guiElements["login_window"] = guiCreateWindow(0.375, 0.375, 0.25, 0.25, "Please enter your Username and Password", true) 
    guiCreateLabel(0.0825, 0.225, 0.25, 0.25, "Username", true, guiElements["login_window"]) 
    guiCreateLabel(0.0825, 0.425, 0.25, 0.25, "Password", true, guiElements["login_window"]) 
    
    guiElements["edit_user"] = guiCreateEdit(0.415, 0.2, 0.5, 0.15, "", true, guiElements["login_window"]) 
    guiElements["edit_pass"] = guiCreateEdit(0.415, 0.4, 0.5, 0.15, "", true, guiElements["login_window"]) 
    guiEditSetMaxLength(guiElements["edit_user"], 20) 
    guiEditSetMaxLength(guiElements["edit_pass"], 20) 
    
    guiElements["register_button"] = guiCreateButton(0.315, 0.7, 0.25, 0.20, "Register", true, guiElements["login_window"]) 
    guiElements["login_button"] = guiCreateButton(0.415, 0.7, 0.25, 0.20, "Log In", true, guiElements["login_window"]) 
    addEventHandler("onClientGUIClick", guiElements["login_button"], clientSubmitLogin, false) 
end 
  
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function () 
        createLoginWindow() 
        outputChatBox("Welcome to My MTA:SA Server, please log in.") 
        showCursor(true) 
        guiSetInputEnabled(true) 
    end 
) 
function hideLoginWindow() 
    guiSetInputEnabled(false) 
    showCursor(false) 
    
    if ( isElement ( guiElements["login_window"] ) ) then 
        destroyElement ( guiElements["login_window"] ) 
    end 
end 
addEvent("hideLoginWindow", true) 
addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) 

thanks,

Tiger.

Link to comment
local account = getAccount(username, password) 
    if ( account ) then 

Here is your problem, you are checking if the account already exists, then you add it, which makes no sense.

Change these two lines to:

local account = getAccount ( username ) 
if ( not account ) then 

Link to comment
local account = getAccount(username, password) 
    if ( account ) then 

Here is your problem, you are checking if the account already exists, then you add it, which makes no sense.

Change these two lines to:

local account = getAccount ( username ) 
if ( not account ) then 

Thank you :D at first, it didn't work, but I did some editing and got it to work!:

At first, I did this:

  
guiElements["register_button"] = guiCreateButton(0.715, 0.7, 0.25, 0.20, "Register", true, guiElements["login_window"]) 
guiElements["login_button"] = guiCreateButton(0.415, 0.7, 0.25, 0.20, "Log In", true, guiElements["login_window"]) 
addEventHandler("onClientGUIClick", guiElements["login_button"], clientSubmitLogin, false) 
addEventHandler("onClientGUIClick", guiElements["login_button"], clientSubmitRegister, false) 

then I realised I didn't change:

guiElements["login_button"] 

But I changed it to guiElements["register_button"] and it worked :D. Thank you so much, you've helped alot!

But, how do I delete accounts? I made like 20 testing the script?

Edited by Guest
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...