Jump to content

The register doen't work


Recommended Posts

Hi all,

I need you:

Login Work but not the Register

  
function iLogin(username, password) 
    --if (not username == "") and (not password == "") then 
        local account = getAccount(username, password) 
        if (account ~= false) then 
            logIn(source, account, password) 
            outputChatBox("#ffffff* #00ff00You successfully logged in as "..username, source, 0, 255, 0, true) 
            triggerClientEvent(source, "destroyLogin", source) 
        else 
            outputChatBox("#ffffff* #ff0000Wrong username and/or password!", source, 255, 0, 0, true) 
        end 
    --else 
    --    outputChatBox("#ffffff* #ff0000Please, enter your username and/or password.", source, 255, 0, 0, true) 
    --end 
end 
addEvent("iLogin", true) 
addEventHandler("iLogin", root, iLogin) 
  
function iRegister(username, password) 
    --if (not username == "") and (not password == "") then 
        local account = getAccount(username, password) 
        if (account == false) then 
            local accountAdded = addAccount(tostring(username), tostring(password)) 
            if (accountAdded) then 
                outputChatBox("#ffffff* #00ff00You have successfully registered.", source, 0, 255, 0, true) 
                triggerClientEvent(source, "destroyLogin", source) 
            else 
                outputChatBox("#ffffff* #ff0000An error occured! Please, report!", source, 255, 0, 0, true) 
            end 
        else 
            outputChatBox("#ffffff* #ff0000That account already exists!", source, 255, 0, 0, true) 
        end 
    --else 
    --    outputChatBox("#ffffff* #ff0000Please, enter your username and/or password.", source, 255, 0, 0, true) 
    --end 
end 
addEvent("iRegister", true) 
addEventHandler("iRegister", root, iRegister) 

local vibX, vibY = 0, 0 
local x, y = guiGetScreenSize() 
local LogoSizeX, LogoSizeY = 196, 56 
local WindowSizeX, WindowSizeY = 425, 425 
local BGSizeX, BGSizeY = 350, 295 
local ButtonSizeX, ButtonSizeY = 450*0.475, 250*0.115 
local font = dxCreateFont( "files/bebas.ttf", 22 ) 
local bgnumber = 0 
local coul = 255,204,0 
passwordEditBox = guiCreateEdit(((x-105)/2), ((y-22)/2)-20, 105, 22, "", false) 
guiSetFont(passwordEditBox, "default-bold-small") 
usernameEditBox = guiCreateEdit(((x-105)/2), ((y-2)/2)-80, 105, 22, "", false) 
guiSetFont(usernameEditBox, "default-bold-small") 
guiEditSetMasked(passwordEditBox, true) 
loginButton = guiCreateButton(((x-ButtonSizeX)/2), ((y-ButtonSizeY)/2)+30, ButtonSizeX, ButtonSizeY, "LOGIN", false) 
guiSetFont(loginButton, "default-bold-small") 
guiSetAlpha(loginButton, 0) 
registerButton = guiCreateButton(((x-ButtonSizeX)/2), ((y-ButtonSizeY)/2)+40+ButtonSizeY, ButtonSizeX, ButtonSizeY, "REGISTER", false) 
guiSetFont(registerButton, "default-bold-small") 
guiSetAlpha(registerButton, 0) 
playasguestButton = guiCreateButton(((x-ButtonSizeX)/2), ((y-ButtonSizeY)/2)+50+(ButtonSizeY*2), ButtonSizeX, ButtonSizeY, "PLAY AS GUEST", false) 
guiSetFont(playasguestButton, "default-bold-small") 
guiSetAlpha(playasguestButton, 0) 
  
function renderLogin() 
    dxDrawRectangle(((x-WindowSizeX)/2), ((y-WindowSizeY)/2), WindowSizeX, WindowSizeY*0.05, tocolor( 0, 0, 0, 150 )) -- header 
    dxDrawRectangle(((x-WindowSizeX)/2), ((y-WindowSizeY)/2), WindowSizeX, WindowSizeY*0.875, tocolor( 0+math.random(0,bgnumber), 0+math.random(0,bgnumber), 0+math.random(0,bgnumber), 150+math.random(0,bgnumber) )) --background 
    dxDrawRectangle(((x-WindowSizeX)/2), ((y-WindowSizeY)/2)+(WindowSizeY*0.875)-7, WindowSizeX, 7, tocolor( 0+math.random(0,bgnumber), 0+math.random(0,bgnumber), 0+math.random(0,bgnumber), 150+math.random(0,bgnumber) )) --bar down 
    dxDrawText("Welcome to Play 4 Fun!",0, ((y-WindowSizeY)/2), x, 0,tocolor(255,255,255,255), 1.55*(7*7/dxGetFontHeight(1.55, font)), "default-bold", "center", "top", false, false, false, true, true)      
    dxDrawImage(((x-LogoSizeX)/2)+math.random(0,vibX), (((y-LogoSizeY)/2)-160)+math.random(0,vibY), LogoSizeX, LogoSizeY, "img/logo.png", 0,0,0,tocolor(255, 255, 255, 255),true) 
    dxDrawRectangle(((x-BGSizeX)/2), ((y-BGSizeY)/2)+15, BGSizeX, BGSizeY-10, tocolor( 255, 204, 0, 50 )) -- BG LOGIN STATS HERE 
    dxDrawRectangle(((x-BGSizeX)/2), ((y-WindowSizeY)/2)+(WindowSizeY*0.05), BGSizeX, BGSizeY*0.275, tocolor( 255, 204, 0, 100 )) -- BG header 
    dxDrawText("Enter your account's details:", 0, ((y-BGSizeY)/2)+5, x, BGSizeY-10,tocolor(255,255,255,255), 1.1*(6*7/dxGetFontHeight(1.1, font)), "default-bold", "center", "center", false, false, false, true, true)     
    dxDrawText("Username ", 0, -185, x, y,tocolor(255,255,255,255), 1.25*(6*6/dxGetFontHeight(1.25, font)), "default-bold", "center", "center", false, false, false, true, true)   
    dxDrawText("Password", 0, -85, x, y,tocolor(255,255,255,255), 1.25*(6*6/dxGetFontHeight(1.25, font)), "default-bold", "center", "center", false, false, false, true, true)   
    dxDrawRectangle(((x-ButtonSizeX)/2), ((y-ButtonSizeY)/2)+30, ButtonSizeX, ButtonSizeY, tocolor( 255, 255, 255, 100 )) -- Login button 
    if hovered == 1 then 
        dxDrawRectangle(((x-ButtonSizeX)/2), ((y-ButtonSizeY)/2)+30, ButtonSizeX, ButtonSizeY, tocolor( 255,204,0, 150 )) -- Login button hover   
    end 
    dxDrawRectangle(((x-ButtonSizeX)/2), ((y-ButtonSizeY)/2)+40+ButtonSizeY, ButtonSizeX, ButtonSizeY, tocolor( 255, 255, 255, 100 )) -- Register button 
    if hovered == 2 then 
        dxDrawRectangle(((x-ButtonSizeX)/2), ((y-ButtonSizeY)/2)+40+ButtonSizeY, ButtonSizeX, ButtonSizeY, tocolor( 255,204,0, 150 )) -- Register button hover 
    end 
    dxDrawRectangle(((x-ButtonSizeX)/2), ((y-ButtonSizeY)/2)+50+(ButtonSizeY*2), ButtonSizeX, ButtonSizeY, tocolor( 255, 255, 255, 100 )) -- Play As Guest button   
    if hovered == 3 then 
        dxDrawRectangle(((x-ButtonSizeX)/2), ((y-ButtonSizeY)/2)+50+(ButtonSizeY*2), ButtonSizeX, ButtonSizeY, tocolor( 255,204,0, 150 )) -- Play As Guest button hover   
    end 
    dxDrawText("Login", 0, 60, x, y,tocolor(255,255,255,255), 1.25*(6*6/dxGetFontHeight(1.25, font)), "default-bold", "center", "center", false, false, false, true, true)  
    dxDrawText("Login", 0, 60, x, y,tocolor(255,255,255,255), 1.25*(6*6/dxGetFontHeight(1.25, font)), "default-bold", "center", "center", false, false, false, true, true)  
    dxDrawText("Register", 0, 140, x, y,tocolor(255,255,255,255), 1.25*(6*6/dxGetFontHeight(1.25, font)), "default-bold", "center", "center", false, false, false, true, true)  
    dxDrawText("Play as guest", 0, 215, x, y,tocolor(255,255,255,255), 1.25*(6*6/dxGetFontHeight(1.25, font)), "default-bold", "center", "center", false, false, false, true, true)  
end 
addEventHandler("onClientRender", root, renderLogin) 
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        showCursor(true) 
        guiSetInputEnabled(true) 
        local xmlL = xmlLoadFile("@remember.xml") 
        if xmlL then 
            local xmlNodeL = xmlFindChild(xmlL, "username", 0) 
            if xmlNodeL then 
                guiSetText(usernameEditBox, xmlNodeGetValue(xmlNodeL)) 
            end 
            local xmlNode2L = xmlFindChild(xmlL, "password", 0) 
            if xmlNode2L then 
                guiSetText(passwordEditBox, xmlNodeGetValue(xmlNode2L)) 
            end 
        end 
    end 
) 
  
addEventHandler("onClientMouseEnter", root, 
    function() 
        if source == loginButton then 
            hovered = 1 
            playSound("files/hover.mp3") 
        elseif source == registerButton then 
            hovered = 2     
            playSound("files/hover.mp3")             
        elseif source == playasguestButton then 
            hovered = 3  
            playSound("files/hover.mp3")             
        end 
    end 
) 
  
addEventHandler("onClientMouseLeave", root, 
    function() 
        if source == loginButton then 
            hovered = 0 
        elseif source == registerButton then 
            hovered = 0 
        elseif source == playasguestButton then 
            hovered = 0 
        end 
    end 
) 
  
addEventHandler("onClientGUIClick", root, 
    function() 
        if source == loginButton then 
            triggerServerEvent("iLogin", localPlayer, guiGetText(usernameEditBox), guiGetText(passwordEditBox)) 
        elseif source == registerButton then 
            triggerServerEvent("iRegister", localPlayer, guiGetText(usernameEditBox), guiGetText(passwordEditBox)) 
        elseif source == playasguestButton then 
            destroyLogin("guest") 
            outputChatBox("* #00ff00You're now playing as guest.", 255, 255, 255, true) 
        end 
    end 
) 
  
function destroyLogin(action) 
    if action ~= "guest" then 
        local xml = xmlLoadFile("@remember.xml") 
        if not xml then 
            xml = xmlCreateFile("@remember.xml", "rememberMe") 
        end 
        local xmlNode = xmlFindChild(xml, "username", 0) 
        if not xmlNode then 
            xmlNode = xmlCreateChild(xml, "username") 
        end 
        local xmlNode2 = xmlFindChild(xml, "password", 0) 
        if not xmlNode2 then 
            xmlNode2 = xmlCreateChild(xml, "password") 
        end 
        xmlNodeSetValue(xmlNode, guiGetText(usernameEditBox)) 
        xmlNodeSetValue(xmlNode2, guiGetText(passwordEditBox)) 
        xmlSaveFile(xml) 
        xmlUnloadFile(xml) 
    end 
    destroyElement(usernameEditBox) 
    destroyElement(passwordEditBox) 
    destroyElement(registerButton) 
    destroyElement(loginButton) 
    destroyElement(playasguestButton) 
    showCursor(false) 
    guiSetInputEnabled(false) 
    removeEventHandler("onClientRender", root, renderLogin) 
end 
addEvent("destroyLogin", true) 
addEventHandler("destroyLogin", root, destroyLogin) 

Link to comment
Hi all,

I need you:

Login Work but not the Register

function iLogin(username, password) 
    --if (not username == "") and (not password == "") then 
        local account = getAccount(username, password) 
        if (account ~= false) then 
            logIn(source, account, password) 
            outputChatBox("#ffffff* #00ff00You successfully logged in as "..username, source, 0, 255, 0, true) 
            triggerClientEvent(source, "destroyLogin", source) 
        else 
            outputChatBox("#ffffff* #ff0000Wrong username and/or password!", source, 255, 0, 0, true) 
        end 
    --else 
    --    outputChatBox("#ffffff* #ff0000Please, enter your username and/or password.", source, 255, 0, 0, true) 
    --end 
end 
addEvent("iLogin", true) 
addEventHandler("iLogin", root, iLogin) 
  
function iRegister(username, password) 
    --if (not username == "") and (not password == "") then 
        local account = getAccount(username, password) 
        if (account == false) then 
            local accountAdded = addAccount(tostring(username), tostring(password)) 
            if (accountAdded) then 
                outputChatBox("#ffffff* #00ff00You have successfully registered.", source, 0, 255, 0, true) 
                triggerClientEvent(source, "destroyLogin", source) 
            else 
                outputChatBox("#ffffff* #ff0000An error occured! Please, report!", source, 255, 0, 0, true) 
            end 
        else 
            outputChatBox("#ffffff* #ff0000That account already exists!", source, 255, 0, 0, true) 
        end 
    --else 
    --    outputChatBox("#ffffff* #ff0000Please, enter your username and/or password.", source, 255, 0, 0, true) 
    --end 
end 
addEvent("iRegister", true) 
addEventHandler("iRegister", root, iRegister) 

local vibX, vibY = 0, 0 
local x, y = guiGetScreenSize() 
local LogoSizeX, LogoSizeY = 196, 56 
local WindowSizeX, WindowSizeY = 425, 425 
local BGSizeX, BGSizeY = 350, 295 
local ButtonSizeX, ButtonSizeY = 450*0.475, 250*0.115 
local font = dxCreateFont( "files/bebas.ttf", 22 ) 
local bgnumber = 0 
local coul = 255,204,0 
passwordEditBox = guiCreateEdit(((x-105)/2), ((y-22)/2)-20, 105, 22, "", false) 
guiSetFont(passwordEditBox, "default-bold-small") 
usernameEditBox = guiCreateEdit(((x-105)/2), ((y-2)/2)-80, 105, 22, "", false) 
guiSetFont(usernameEditBox, "default-bold-small") 
guiEditSetMasked(passwordEditBox, true) 
loginButton = guiCreateButton(((x-ButtonSizeX)/2), ((y-ButtonSizeY)/2)+30, ButtonSizeX, ButtonSizeY, "LOGIN", false) 
guiSetFont(loginButton, "default-bold-small") 
guiSetAlpha(loginButton, 0) 
registerButton = guiCreateButton(((x-ButtonSizeX)/2), ((y-ButtonSizeY)/2)+40+ButtonSizeY, ButtonSizeX, ButtonSizeY, "REGISTER", false) 
guiSetFont(registerButton, "default-bold-small") 
guiSetAlpha(registerButton, 0) 
playasguestButton = guiCreateButton(((x-ButtonSizeX)/2), ((y-ButtonSizeY)/2)+50+(ButtonSizeY*2), ButtonSizeX, ButtonSizeY, "PLAY AS GUEST", false) 
guiSetFont(playasguestButton, "default-bold-small") 
guiSetAlpha(playasguestButton, 0) 
  
function renderLogin() 
    dxDrawRectangle(((x-WindowSizeX)/2), ((y-WindowSizeY)/2), WindowSizeX, WindowSizeY*0.05, tocolor( 0, 0, 0, 150 )) -- header 
    dxDrawRectangle(((x-WindowSizeX)/2), ((y-WindowSizeY)/2), WindowSizeX, WindowSizeY*0.875, tocolor( 0+math.random(0,bgnumber), 0+math.random(0,bgnumber), 0+math.random(0,bgnumber), 150+math.random(0,bgnumber) )) --background 
    dxDrawRectangle(((x-WindowSizeX)/2), ((y-WindowSizeY)/2)+(WindowSizeY*0.875)-7, WindowSizeX, 7, tocolor( 0+math.random(0,bgnumber), 0+math.random(0,bgnumber), 0+math.random(0,bgnumber), 150+math.random(0,bgnumber) )) --bar down 
    dxDrawText("Welcome to Play 4 Fun!",0, ((y-WindowSizeY)/2), x, 0,tocolor(255,255,255,255), 1.55*(7*7/dxGetFontHeight(1.55, font)), "default-bold", "center", "top", false, false, false, true, true)      
    dxDrawImage(((x-LogoSizeX)/2)+math.random(0,vibX), (((y-LogoSizeY)/2)-160)+math.random(0,vibY), LogoSizeX, LogoSizeY, "img/logo.png", 0,0,0,tocolor(255, 255, 255, 255),true) 
    dxDrawRectangle(((x-BGSizeX)/2), ((y-BGSizeY)/2)+15, BGSizeX, BGSizeY-10, tocolor( 255, 204, 0, 50 )) -- BG LOGIN STATS HERE 
    dxDrawRectangle(((x-BGSizeX)/2), ((y-WindowSizeY)/2)+(WindowSizeY*0.05), BGSizeX, BGSizeY*0.275, tocolor( 255, 204, 0, 100 )) -- BG header 
    dxDrawText("Enter your account's details:", 0, ((y-BGSizeY)/2)+5, x, BGSizeY-10,tocolor(255,255,255,255), 1.1*(6*7/dxGetFontHeight(1.1, font)), "default-bold", "center", "center", false, false, false, true, true)     
    dxDrawText("Username ", 0, -185, x, y,tocolor(255,255,255,255), 1.25*(6*6/dxGetFontHeight(1.25, font)), "default-bold", "center", "center", false, false, false, true, true)   
    dxDrawText("Password", 0, -85, x, y,tocolor(255,255,255,255), 1.25*(6*6/dxGetFontHeight(1.25, font)), "default-bold", "center", "center", false, false, false, true, true)   
    dxDrawRectangle(((x-ButtonSizeX)/2), ((y-ButtonSizeY)/2)+30, ButtonSizeX, ButtonSizeY, tocolor( 255, 255, 255, 100 )) -- Login button 
    if hovered == 1 then 
        dxDrawRectangle(((x-ButtonSizeX)/2), ((y-ButtonSizeY)/2)+30, ButtonSizeX, ButtonSizeY, tocolor( 255,204,0, 150 )) -- Login button hover   
    end 
    dxDrawRectangle(((x-ButtonSizeX)/2), ((y-ButtonSizeY)/2)+40+ButtonSizeY, ButtonSizeX, ButtonSizeY, tocolor( 255, 255, 255, 100 )) -- Register button 
    if hovered == 2 then 
        dxDrawRectangle(((x-ButtonSizeX)/2), ((y-ButtonSizeY)/2)+40+ButtonSizeY, ButtonSizeX, ButtonSizeY, tocolor( 255,204,0, 150 )) -- Register button hover 
    end 
    dxDrawRectangle(((x-ButtonSizeX)/2), ((y-ButtonSizeY)/2)+50+(ButtonSizeY*2), ButtonSizeX, ButtonSizeY, tocolor( 255, 255, 255, 100 )) -- Play As Guest button   
    if hovered == 3 then 
        dxDrawRectangle(((x-ButtonSizeX)/2), ((y-ButtonSizeY)/2)+50+(ButtonSizeY*2), ButtonSizeX, ButtonSizeY, tocolor( 255,204,0, 150 )) -- Play As Guest button hover   
    end 
    dxDrawText("Login", 0, 60, x, y,tocolor(255,255,255,255), 1.25*(6*6/dxGetFontHeight(1.25, font)), "default-bold", "center", "center", false, false, false, true, true)  
    dxDrawText("Login", 0, 60, x, y,tocolor(255,255,255,255), 1.25*(6*6/dxGetFontHeight(1.25, font)), "default-bold", "center", "center", false, false, false, true, true)  
    dxDrawText("Register", 0, 140, x, y,tocolor(255,255,255,255), 1.25*(6*6/dxGetFontHeight(1.25, font)), "default-bold", "center", "center", false, false, false, true, true)  
    dxDrawText("Play as guest", 0, 215, x, y,tocolor(255,255,255,255), 1.25*(6*6/dxGetFontHeight(1.25, font)), "default-bold", "center", "center", false, false, false, true, true)  
end 
addEventHandler("onClientRender", root, renderLogin) 
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        showCursor(true) 
        guiSetInputEnabled(true) 
        local xmlL = xmlLoadFile("@remember.xml") 
        if xmlL then 
            local xmlNodeL = xmlFindChild(xmlL, "username", 0) 
            if xmlNodeL then 
                guiSetText(usernameEditBox, xmlNodeGetValue(xmlNodeL)) 
            end 
            local xmlNode2L = xmlFindChild(xmlL, "password", 0) 
            if xmlNode2L then 
                guiSetText(passwordEditBox, xmlNodeGetValue(xmlNode2L)) 
            end 
        end 
    end 
) 
  
addEventHandler("onClientMouseEnter", root, 
    function() 
        if source == loginButton then 
            hovered = 1 
            playSound("files/hover.mp3") 
        elseif source == registerButton then 
            hovered = 2     
            playSound("files/hover.mp3")             
        elseif source == playasguestButton then 
            hovered = 3  
            playSound("files/hover.mp3")             
        end 
    end 
) 
  
addEventHandler("onClientMouseLeave", root, 
    function() 
        if source == loginButton then 
            hovered = 0 
        elseif source == registerButton then 
            hovered = 0 
        elseif source == playasguestButton then 
            hovered = 0 
        end 
    end 
) 
  
addEventHandler("onClientGUIClick", root, 
    function() 
        if source == loginButton then 
            triggerServerEvent("iLogin", localPlayer, guiGetText(usernameEditBox), guiGetText(passwordEditBox)) 
        elseif source == registerButton then 
            triggerServerEvent("iRegister", localPlayer, guiGetText(usernameEditBox), guiGetText(passwordEditBox)) 
        elseif source == playasguestButton then 
            destroyLogin("guest") 
            outputChatBox("* #00ff00You're now playing as guest.", 255, 255, 255, true) 
        end 
    end 
) 
  
function destroyLogin(action) 
    if action ~= "guest" then 
        local xml = xmlLoadFile("@remember.xml") 
        if not xml then 
            xml = xmlCreateFile("@remember.xml", "rememberMe") 
        end 
        local xmlNode = xmlFindChild(xml, "username", 0) 
        if not xmlNode then 
            xmlNode = xmlCreateChild(xml, "username") 
        end 
        local xmlNode2 = xmlFindChild(xml, "password", 0) 
        if not xmlNode2 then 
            xmlNode2 = xmlCreateChild(xml, "password") 
        end 
        xmlNodeSetValue(xmlNode, guiGetText(usernameEditBox)) 
        xmlNodeSetValue(xmlNode2, guiGetText(passwordEditBox)) 
        xmlSaveFile(xml) 
        xmlUnloadFile(xml) 
    end 
    destroyElement(usernameEditBox) 
    destroyElement(passwordEditBox) 
    destroyElement(registerButton) 
    destroyElement(loginButton) 
    destroyElement(playasguestButton) 
    showCursor(false) 
    guiSetInputEnabled(false) 
    removeEventHandler("onClientRender", root, renderLogin) 
end 
addEvent("destroyLogin", true) 
addEventHandler("destroyLogin", root, destroyLogin) 
  

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