Jump to content

Gui Button not work


Dimos7

Recommended Posts

local GUIEditor = {
   window = { },
   label = { },
   edit = { },
   button= { }
}

function createPasswordWindow()
    GUIEditor.window[1] = guiCreateWindow(693, 268, 303, 307, "Change Password", false)
	guiWindowSetMovable(GUIEditor.window[1], false)
	guiWindowSetSizable(GUIEditor.window[1], false)
	GUIEditor.label[1] = guiCreateLabel(7, 75, 289, 24, "                             New Password:", false, GUIEditor.window[1])
	guiLabelSetVerticalAlign(GUIEditor.label[1], "top")
	guiLabelSetHorizontalAlign(GUIEditor.label[1], "left")
	guiSetFont(GUIEditor.label[1], "clear-normal")
	GUIEditor.edit[1] = guiCreateEdit(9, 100, 285, 25, "", false, GUIEditor.window[1])
	guiEditSetMasked(GUIEditor.edit[1], true)
	GUIEditor.label[2] = guiCreateLabel(7, 140, 289, 24, "                             Repeat Password:", false, GUIEditor.window[1])
	guiLabelSetVerticalAlign(GUIEditor.label[2], "top")
	guiLabelSetHorizontalAlign(GUIEditor.label[2], "left")
	guiSetFont(GUIEditor.label[2], "clear-normal")
	GUIEditor.edit[2] = guiCreateEdit(9, 168, 285, 25, "", false, GUIEditor.window[1])
	guiEditSetMasked(GUIEditor.edit[2], true)
	GUIEditor.button[1] = guiCreateButton(9, 254, 143, 53, "Change", false, GUIEditor.window[1])
	GUIEditor.button[2] = guiCreateButton(153, 254, 143, 53, "Cancel", false, GUIEditor.window[1])
	guiSstVisible(GUIEditor.window[1], false)
	addEventHandler("onClientGUIClick", GUIEditor.button[1], clientSubmitChangepw, false)
	addEventHandler("onClientGUIClick", GUIEditor.button[2], hidePasswordWindow, false)
end

function createLoginWindow()
    GUIEditor.window[2] = guiCreateWindow(693, 268, 303, 307, "login Panel", false)
	guiWindowSetMovable(GUIEditor.window[2], false)
	guiWindowSetSizable(GUIEditor.window[2], false)
	GUIEditor.label[3] = guiCreateLabel(7, 75, 289, 24, "                             Username:", false, GUIEditor.window[2])
	guiLabelSetVerticalAlign(GUIEditor.label[3], "top")
	guiLabelSetHorizontalAlign(GUIEditor.label[3], "left")
	guiSetFont(GUIEditor.label[3], "clear-normal")
	GUIEditor.edit[3] = guiCreateEdit(9, 100, 285, 25, "", false, GUIEditor.window[2])
	GUIEditor.label[4] = guiCreateLabel(7, 140, 289, 24, "                             Password:", false, GUIEditor.window[2])
	guiLabelSetVerticalAlign(GUIEditor.label[4], "top")
	guiLabelSetHorizontalAlign(GUIEditor.label[4], "left")
	guiSetFont(GUIEditor.label[4], "clear-normal")
	GUIEditor.edit[4] = guiCreateEdit(9, 168, 285, 25, "", false, GUIEditor.window[2])
	guiEditSetMasked(GUIEditor.edit[4], true)
	GUIEditor.button[3] = guiCreateButton(9, 254, 143, 53, "Login", false, GUIEditor.window[2])
	GUIEditor.button[4] = guiCreateButton(153, 254, 143, 53, "Register", false, GUIEditor.window[2])
	addEventHandler("onClientGUIClick", GUIEditor.button[3], clientSubmitLogin, false)
	addEventHandler("onClientGUIClick", GUIEditor.button[4], clientSubmitRegister, false)
end

function resourceStart()
    createLoginWindow()
	if (GUIEditor.window[2] ~= nil) then
	    guiSetVisible(GUIEditor.window[2], true)
    else
	   outputChatBox("An error has occupied.")
	end
	showCursor(true)
	guiSetInputEnabled(true)
end

function changepw()
    createPasswordWindow()
	guiSetVisible(GUIEditor.window[1], true)
	showCursor(true)
	guiSetInputEnabled(true)
end

function clientSubmitLogin(button, state)
    if button == "left" and state == "down" then
	   local username = guiGetText(GUIEditor.edit[3])
	   local password = guiGetText(GUIEditor.edit[4])
	   if username ~= "" and password ~= "" then
	      triggerSeverEvent("submitLogin", root, localPlayer, username, password)
	   else
	      outputChatBox("Enter username and password.", 255, 0, 0)
		end
	end
end

function clientSubmitRegister(button, state)
    if button == "left" and state == "down" then
       local username = guiGetText(GUIEditor[3])
       local password = guiGetText(GUIEditor[4])
       if username ~= "" and password ~= "" then
          triggerSeverEvent("submitRegister", root, localPlayer, username, password)
       else
  		  outputChatBox("Enter username and password.", 255, 0, 0)
	   end
	end
end

function clientSubmitChangepw(button, state)
    if button == "left" and state == "down" then
	   local password = guiGetText(GUIEditor.edit[1])
	   local rpassword = guiGetText(GUIEditor.edit[2])
	   if password ~= "" and rpassword ~= "" then
	      triggerSeverEvent("submitChangepw", root, localPlayer, password, rpassword)
	   else
	      outputChatBox("Enter new password and repeat it", 255, 0, 0)
	   end
	end
end

function hideLoginWindow()
    guiSetVisible(GUIEditor.window[2], false)
	showCursor(false)
	guiSetInputEnabled(false)
end

function hidePasswordWindow()
    guiSetVisible(GUIEditor.window[1], false)
	showCursor(false)
	guiSetInputEnabled(false)
end

addEvent("hideLoginWindow", true)
addEvent("hidePasswordWindow", true)
addEventHandler("hideLoginWindow", root, hideLoginWindow)
addEventHandler("hidePasswordWindow", root, hidePasswordWindow)
addEventHandler("onClientResourceStart", resourceRoot, resourceStart)
addCommandHandler("changepw", changepw)
function passwordHandler(thePlayer, password, rpassword)
    local account = getPlayerAccount(thePlayer)
	if account then
	   if isGuestAccount(account) then
	      outputChatBox("You must be logged in to change password!", thePlayer, 255, 0, 0)
		  return
	   end
	   if password == rpassword then
	      if string.len(password) >= 5 then
		      setAccountPassword(account, password)
			  triggerClientEvent(thePlayer, "hidePasswordWindow", root)
		  else
		     outputChatBox("Your new password must be at least 5 characters long!", thePlayer, 255, 0, 0)
		  end
	   else
	      outputChatBox("Your passwords aren't the same!", thePlayer, 255, 0, 0)
	   end
	end
end

function loginHandler(thePlayer, username, password)
    local account = getAccount(username, password)
	if account ~= false then
	   if (logIn(thePlayer, account, password) == true) then 
	        outputChatBox("You succefuly logged in!", thePlayer, 0, 255, 0)
	        triggerClientEvent(thePlayer, "hideLoginWindow", root)
	   else
	      outputChatBox("An error please report it to forum!", thePlayer, 255, 0, 0)
	   end
	else
	   outputChatBox("Username or password are incorrect!", thePlayer, 255, 0, 0)
	end
end

function registerHandler(thePlayer, username, password)
    local account = getAccount(username, password)
	if account ~= false then
	    outputChatBox("This username is already exist!", thePlayer, 255, 0, 0)
    else
	   account = addAccount(username, password)
	   outputChatBox("You succefuly registered!", thePlayer, 0, 255, 0)
	   if (logIn(thePlayer, account, password) == true) then
	        outputChatBox("You succefuly logged in!", thePlayer, 0, 255, 0)
			triggerClientEvent(thePlayer, "hideLoginWindow", root)
	   else
	      outputChatBox("An error please report it to forum!", thePlayer, 255, 0, 0)
	   end
	end
end

addEvent("submitChangepw", true)
addEvent("submitLogin", true)
addEvent("submitRegister", true)
addEventHandler("submitChangepw", root, passwordHandler)
addEventHandler("submitLogin", root, loginHandler)
addEventHandler("submitRegister", root, registerHandler)

When i press button for login nothing happend event if is empty same with register

Edited by Dimos7
Link to comment

nothing in debugscript 3 not working at all the buttons of loginpanel not even the error given if are empty the edits

local GUIEditor = {
   window = { },
   label = { },
   edit = { },
   button= { }
}

function createPasswordWindow()
    GUIEditor.window[1] = guiCreateWindow(693, 268, 303, 307, "Change Password", false)
	guiWindowSetMovable(GUIEditor.window[1], false)
	guiWindowSetSizable(GUIEditor.window[1], false)
	GUIEditor.label[1] = guiCreateLabel(7, 75, 289, 24, "                             New Password:", false, GUIEditor.window[1])
	guiLabelSetVerticalAlign(GUIEditor.label[1], "top")
	guiLabelSetHorizontalAlign(GUIEditor.label[1], "left")
	guiSetFont(GUIEditor.label[1], "clear-normal")
	GUIEditor.edit[1] = guiCreateEdit(9, 100, 285, 25, "", false, GUIEditor.window[1])
	guiEditSetMasked(GUIEditor.edit[1], true)
	GUIEditor.label[2] = guiCreateLabel(7, 140, 289, 24, "                             Repeat Password:", false, GUIEditor.window[1])
	guiLabelSetVerticalAlign(GUIEditor.label[2], "top")
	guiLabelSetHorizontalAlign(GUIEditor.label[2], "left")
	guiSetFont(GUIEditor.label[2], "clear-normal")
	GUIEditor.edit[2] = guiCreateEdit(9, 168, 285, 25, "", false, GUIEditor.window[1])
	guiEditSetMasked(GUIEditor.edit[2], true)
	GUIEditor.button[1] = guiCreateButton(9, 254, 143, 53, "Change", false, GUIEditor.window[1])
	GUIEditor.button[2] = guiCreateButton(153, 254, 143, 53, "Cancel", false, GUIEditor.window[1])
	guiSetVisible(GUIEditor.window[1], false)
	addEventHandler("onClientGUIClick", GUIEditor.button[1], clientSubmitChangepw)
	addEventHandler("onClientGUIClick", GUIEditor.button[2], hidePasswordWindow)
end

function createLoginWindow()
    GUIEditor.window[2] = guiCreateWindow(693, 268, 303, 307, "login Panel", false)
	guiWindowSetMovable(GUIEditor.window[2], false)
	guiWindowSetSizable(GUIEditor.window[2], false)
	GUIEditor.label[3] = guiCreateLabel(7, 75, 289, 24, "                             Username:", false, GUIEditor.window[2])
	guiLabelSetVerticalAlign(GUIEditor.label[3], "top")
	guiLabelSetHorizontalAlign(GUIEditor.label[3], "left")
	guiSetFont(GUIEditor.label[3], "clear-normal")
	GUIEditor.edit[3] = guiCreateEdit(9, 100, 285, 25, "", false, GUIEditor.window[2])
	GUIEditor.label[4] = guiCreateLabel(7, 140, 289, 24, "                             Password:", false, GUIEditor.window[2])
	guiLabelSetVerticalAlign(GUIEditor.label[4], "top")
	guiLabelSetHorizontalAlign(GUIEditor.label[4], "left")
	guiSetFont(GUIEditor.label[4], "clear-normal")
	GUIEditor.edit[4] = guiCreateEdit(9, 168, 285, 25, "", false, GUIEditor.window[2])
	guiEditSetMasked(GUIEditor.edit[4], true)
	GUIEditor.button[3] = guiCreateButton(9, 254, 143, 53, "Login", false, GUIEditor.window[2])
	GUIEditor.button[4] = guiCreateButton(153, 254, 143, 53, "Register", false, GUIEditor.window[2])
	addEventHandler("onClientGUIClick", GUIEditor.button[3], clientSubmitLogin)
	addEventHandler("onClientGUIClick", GUIEditor.button[4], clientSubmitRegister)
end

function resourceStart()
    createLoginWindow()
	if (GUIEditor.window[2] ~= nil) then
	    guiSetVisible(GUIEditor.window[2], true)
    else
	   outputChatBox("An error has occupied.")
	end
	showCursor(true)
	guiSetInputEnabled(true)
end

function changepw()
    createPasswordWindow()
	guiSetVisible(GUIEditor.window[1], true)
	showCursor(true)
	guiSetInputEnabled(true)
end

function clientSubmitLogin(button, state)
    if button == "left" and state == "down" then
	   local username = guiGetText(GUIEditor.edit[3])
	   local password = guiGetText(GUIEditor.edit[4])
	   if username ~= "" and password ~= "" then
	      triggerServerEvent("submitLogin", root, localPlayer, username, password)
	   else
	      outputChatBox("Enter username and password.", 255, 0, 0)
		end
	end
end

function clientSubmitRegister(button, state)
    if button == "left" and state == "down" then
       local username = guiGetText(GUIEditor[3])
       local password = guiGetText(GUIEditor[4])
       if username ~= "" and password ~= "" then
          triggerServerEvent("submitRegister", root, localPlayer, username, password)
       else
  		  outputChatBox("Enter username and password.", 255, 0, 0)
	   end
	end
end

function clientSubmitChangepw(button, state)
    if button == "left" and state == "down" then
	   local password = guiGetText(GUIEditor.edit[1])
	   local rpassword = guiGetText(GUIEditor.edit[2])
	   if password ~= "" and rpassword ~= "" then
	      triggerServerEvent("submitChangepw", root, localPlayer, password, rpassword)
	   else
	      outputChatBox("Enter new password and repeat it", 255, 0, 0)
	   end
	end
end

function hideLoginWindow()
    guiSetVisible(GUIEditor.window[2], false)
	showCursor(false)
	guiSetInputEnabled(false)
end

function hidePasswordWindow()
    guiSetVisible(GUIEditor.window[1], false)
	showCursor(false)
	guiSetInputEnabled(false)
end

addEvent("hideLoginWindow", true)
addEvent("hidePasswordWindow", true)
addEventHandler("hideLoginWindow", root, hideLoginWindow)
addEventHandler("hidePasswordWindow", root, hidePasswordWindow)
addEventHandler("onClientResourceStart", resourceRoot, resourceStart)
addCommandHandler("changepw", changepw)

 

Edited by Dimos7
Link to comment

Try this : 

 

Client :

 

local GUIEditor = {
   window = { },
   label = { },
   edit = { },
   button= { }
}

function createPasswordWindow()
    GUIEditor.window[1] = guiCreateWindow(693, 268, 303, 307, "Change Password", false)
    guiWindowSetMovable(GUIEditor.window[1], false)
    guiWindowSetSizable(GUIEditor.window[1], false)
    GUIEditor.label[1] = guiCreateLabel(7, 75, 289, 24, "                             New Password:", false, GUIEditor.window[1])
    guiLabelSetVerticalAlign(GUIEditor.label[1], "top")
    guiLabelSetHorizontalAlign(GUIEditor.label[1], "left")
    guiSetFont(GUIEditor.label[1], "clear-normal")
    GUIEditor.edit[1] = guiCreateEdit(9, 100, 285, 25, "", false, GUIEditor.window[1])
    guiEditSetMasked(GUIEditor.edit[1], true)
    GUIEditor.label[2] = guiCreateLabel(7, 140, 289, 24, "                             Repeat Password:", false, GUIEditor.window[1])
    guiLabelSetVerticalAlign(GUIEditor.label[2], "top")
    guiLabelSetHorizontalAlign(GUIEditor.label[2], "left")
    guiSetFont(GUIEditor.label[2], "clear-normal")
    GUIEditor.edit[2] = guiCreateEdit(9, 168, 285, 25, "", false, GUIEditor.window[1])
    guiEditSetMasked(GUIEditor.edit[2], true)
    GUIEditor.button[1] = guiCreateButton(9, 254, 143, 53, "Change", false, GUIEditor.window[1])
    GUIEditor.button[2] = guiCreateButton(153, 254, 143, 53, "Cancel", false, GUIEditor.window[1])
    guiSstVisible(GUIEditor.window[1], false)
    addEventHandler("onClientGUIClick", GUIEditor.button[1], clientSubmitChangepw, false)
    addEventHandler("onClientGUIClick", GUIEditor.button[2], hidePasswordWindow, false)
end

function createLoginWindow()
    GUIEditor.window[2] = guiCreateWindow(693, 268, 303, 307, "login Panel", false)
    guiWindowSetMovable(GUIEditor.window[2], false)
    guiWindowSetSizable(GUIEditor.window[2], false)
    GUIEditor.label[3] = guiCreateLabel(7, 75, 289, 24, "                             Username:", false, GUIEditor.window[2])
    guiLabelSetVerticalAlign(GUIEditor.label[3], "top")
    guiLabelSetHorizontalAlign(GUIEditor.label[3], "left")
    guiSetFont(GUIEditor.label[3], "clear-normal")
    GUIEditor.edit[3] = guiCreateEdit(9, 100, 285, 25, "", false, GUIEditor.window[2])
    GUIEditor.label[4] = guiCreateLabel(7, 140, 289, 24, "                             Password:", false, GUIEditor.window[2])
    guiLabelSetVerticalAlign(GUIEditor.label[4], "top")
    guiLabelSetHorizontalAlign(GUIEditor.label[4], "left")
    guiSetFont(GUIEditor.label[4], "clear-normal")
    GUIEditor.edit[4] = guiCreateEdit(9, 168, 285, 25, "", false, GUIEditor.window[2])
    guiEditSetMasked(GUIEditor.edit[4], true)
    GUIEditor.button[3] = guiCreateButton(9, 254, 143, 53, "Login", false, GUIEditor.window[2])
    GUIEditor.button[4] = guiCreateButton(153, 254, 143, 53, "Register", false, GUIEditor.window[2])
    addEventHandler("onClientGUIClick", GUIEditor.button[3], clientSubmitLogin, false)
    addEventHandler("onClientGUIClick", GUIEditor.button[4], clientSubmitRegister, false)
end

function resourceStart()
    createLoginWindow()
    if (GUIEditor.window[2] ~= nil) then
        guiSetVisible(GUIEditor.window[2], true)
    else
       outputChatBox("An error has occupied.")
    end
    showCursor(true)
    guiSetInputEnabled(true)
end

function changepw()
    createPasswordWindow()
    guiSetVisible(GUIEditor.window[1], true)
    showCursor(true)
    guiSetInputEnabled(true)
end

function clientSubmitLogin(button, state)
    if button == "left" and state == "down" then
       local username = guiGetText(GUIEditor.edit[3])
       local password = guiGetText(GUIEditor.edit[4])
       if username ~= "" and password ~= "" then
          triggerServerEvent("submitLogin", localPlayer, username, password)
       else
          outputChatBox("Enter username and password.", 255, 0, 0)
        end
    end
end

function clientSubmitRegister(button, state)
    if button == "left" and state == "down" then
       local username = guiGetText(GUIEditor[3])
       local password = guiGetText(GUIEditor[4])
       if username ~= "" and password ~= "" then
          triggerServerEvent("submitRegister", localPlayer, username, password)
       else
          outputChatBox("Enter username and password.", 255, 0, 0)
       end
    end
end

function clientSubmitChangepw(button, state)
    if button == "left" and state == "down" then
       local password = guiGetText(GUIEditor.edit[1])
       local rpassword = guiGetText(GUIEditor.edit[2])
       if password ~= "" and rpassword ~= "" then
          triggerServerEvent("submitChangepw", localPlayer, password, rpassword)
       else
          outputChatBox("Enter new password and repeat it", 255, 0, 0)
       end
    end
end

function hideLoginWindow()
    guiSetVisible(GUIEditor.window[2], false)
    showCursor(false)
    guiSetInputEnabled(false)
end

function hidePasswordWindow()
    guiSetVisible(GUIEditor.window[1], false)
    showCursor(false)
    guiSetInputEnabled(false)
end

addEvent("hideLoginWindow", true)
addEvent("hidePasswordWindow", true)
addEventHandler("hideLoginWindow", root, hideLoginWindow)
addEventHandler("hidePasswordWindow", root, hidePasswordWindow)
addEventHandler("onClientResourceStart", resourceRoot, resourceStart)
addCommandHandler("changepw", changepw)

 

Server :

 

function passwordHandler(password, rpassword)
    local account = getPlayerAccount(source)
    if account then
       if isGuestAccount(account) then
          outputChatBox("You must be logged in to change password!", source, 255, 0, 0)
          return
       end
       if password == rpassword then
          if string.len(password) >= 5 then
              setAccountPassword(account, password)
              triggerClientEvent(source, "hidePasswordWindow",source )
          else
             outputChatBox("Your new password must be at least 5 characters long!", source, 255, 0, 0)
          end
       else
          outputChatBox("Your passwords aren't the same!", source, 255, 0, 0)
       end
    end
end

function loginHandler(username, password)
    local account = getAccount(username, password)
    if account ~= false then
       if (logIn(source, account, password) == true) then 
            outputChatBox("You succefuly logged in!", source, 0, 255, 0)
            triggerClientEvent(source, "hideLoginWindow", source)
       else
          outputChatBox("An error please report it to forum!", source, 255, 0, 0)
       end
    else
       outputChatBox("Username or password are incorrect!", source, 255, 0, 0)
    end
end

function registerHandler(username, password)
    local account = getAccount(username, password)
    if account ~= false then
        outputChatBox("This username is already exist!", source, 255, 0, 0)
    else
       account = addAccount(username, password)
       outputChatBox("You succefuly registered!", source, 0, 255, 0)
       if (logIn(source, account, password) == true) then
            outputChatBox("You succefuly logged in!", source, 0, 255, 0)
            triggerClientEvent(source, "hideLoginWindow", source)
       else
          outputChatBox("An error please report it to forum!", source, 255, 0, 0)
       end
    end
end

addEvent("submitChangepw", true)
addEvent("submitLogin", true)
addEvent("submitRegister", true)
addEventHandler("submitChangepw", root, passwordHandler)
addEventHandler("submitLogin", root, loginHandler)
addEventHandler("submitRegister", root, registerHandler)

 

 

Please make sure to add this resource to 'Admin' Group to add accounts. Ex. resource.MyResourceName

Link to comment

already did on admin  

 <group name="Admin">
        <acl name="Moderator"></acl>
        <acl name="SuperModerator"></acl>
        <acl name="Admin"></acl>
        <acl name="RPC"></acl>
        <object name="resource.admin"></object>
        <object name="resource.webadmin"></object>
        <object name="resource.loginpanel"></object>
local GUIEditor = {
   window = { },
   label = { },
   edit = { },
   button= { }
}

function createPasswordWindow()
    GUIEditor.window[1] = guiCreateWindow(693, 268, 303, 307, "Change Password", false)
    guiWindowSetMovable(GUIEditor.window[1], false)
    guiWindowSetSizable(GUIEditor.window[1], false)
    GUIEditor.label[1] = guiCreateLabel(7, 75, 289, 24, "                             New Password:", false, GUIEditor.window[1])
    guiLabelSetVerticalAlign(GUIEditor.label[1], "top")
    guiLabelSetHorizontalAlign(GUIEditor.label[1], "left")
    guiSetFont(GUIEditor.label[1], "clear-normal")
    GUIEditor.edit[1] = guiCreateEdit(9, 100, 285, 25, "", false, GUIEditor.window[1])
    guiEditSetMasked(GUIEditor.edit[1], true)
    GUIEditor.label[2] = guiCreateLabel(7, 140, 289, 24, "                             Repeat Password:", false, GUIEditor.window[1])
    guiLabelSetVerticalAlign(GUIEditor.label[2], "top")
    guiLabelSetHorizontalAlign(GUIEditor.label[2], "left")
    guiSetFont(GUIEditor.label[2], "clear-normal")
    GUIEditor.edit[2] = guiCreateEdit(9, 168, 285, 25, "", false, GUIEditor.window[1])
    guiEditSetMasked(GUIEditor.edit[2], true)
    GUIEditor.button[1] = guiCreateButton(9, 254, 143, 53, "Change", false, GUIEditor.window[1])
    GUIEditor.button[2] = guiCreateButton(153, 254, 143, 53, "Cancel", false, GUIEditor.window[1])
    guiSetVisible(GUIEditor.window[1], false)
    addEventHandler("onClientGUIClick", GUIEditor.button[1], clientSubmitChangepw, false)
    addEventHandler("onClientGUIClick", GUIEditor.button[2], hidePasswordWindow, false)
end

function createLoginWindow()
    GUIEditor.window[2] = guiCreateWindow(693, 268, 303, 307, "login Panel", false)
    guiWindowSetMovable(GUIEditor.window[2], false)
    guiWindowSetSizable(GUIEditor.window[2], false)
    GUIEditor.label[3] = guiCreateLabel(7, 75, 289, 24, "                             Username:", false, GUIEditor.window[2])
    guiLabelSetVerticalAlign(GUIEditor.label[3], "top")
    guiLabelSetHorizontalAlign(GUIEditor.label[3], "left")
    guiSetFont(GUIEditor.label[3], "clear-normal")
    GUIEditor.edit[3] = guiCreateEdit(9, 100, 285, 25, "", false, GUIEditor.window[2])
    GUIEditor.label[4] = guiCreateLabel(7, 140, 289, 24, "                             Password:", false, GUIEditor.window[2])
    guiLabelSetVerticalAlign(GUIEditor.label[4], "top")
    guiLabelSetHorizontalAlign(GUIEditor.label[4], "left")
    guiSetFont(GUIEditor.label[4], "clear-normal")
    GUIEditor.edit[4] = guiCreateEdit(9, 168, 285, 25, "", false, GUIEditor.window[2])
    guiEditSetMasked(GUIEditor.edit[4], true)
    GUIEditor.button[3] = guiCreateButton(9, 254, 143, 53, "Login", false, GUIEditor.window[2])
    GUIEditor.button[4] = guiCreateButton(153, 254, 143, 53, "Register", false, GUIEditor.window[2])
    addEventHandler("onClientGUIClick", GUIEditor.button[3], clientSubmitLogin, false)
    addEventHandler("onClientGUIClick", GUIEditor.button[4], clientSubmitRegister, false)
end

function resourceStart()
    createLoginWindow()
    if (GUIEditor.window[2] ~= nil) then
        guiSetVisible(GUIEditor.window[2], true)
    else
       outputChatBox("An error has occupied.")
    end
    showCursor(true)
    guiSetInputEnabled(true)
end

function changepw()
    createPasswordWindow()
    guiSetVisible(GUIEditor.window[1], true)
    showCursor(true)
    guiSetInputEnabled(true)
end

function clientSubmitLogin(button, state)
    if button == "left" and state == "down" then
       local username = guiGetText(GUIEditor.edit[3])
       local password = guiGetText(GUIEditor.edit[4])
       if username ~= "" and password ~= "" then
          triggerServerEvent("submitLogin", localPlayer, username, password)
       else
          outputChatBox("Enter username and password.", 255, 0, 0)
        end
    end
end

function clientSubmitRegister(button, state)
    if button == "left" and state == "down" then
       local username = guiGetText(GUIEditor.edit[3])
       local password = guiGetText(GUIEditor.edit[4])
       if username ~= "" and password ~= "" then
          triggerServerEvent("submitRegister", localPlayer, username, password)
       else
          outputChatBox("Enter username and password.", 255, 0, 0)
       end
    end
end

function clientSubmitChangepw(button, state)
    if button == "left" and state == "down" then
       local password = guiGetText(GUIEditor.edit[1])
       local rpassword = guiGetText(GUIEditor.edit[2])
       if password ~= "" and rpassword ~= "" then
          triggerServerEvent("submitChangepw", localPlayer, password, rpassword)
       else
          outputChatBox("Enter new password and repeat it", 255, 0, 0)
       end
    end
end

function hideLoginWindow()
    guiSetVisible(GUIEditor.window[2], false)
    showCursor(false)
    guiSetInputEnabled(false)
end

function hidePasswordWindow()
    guiSetVisible(GUIEditor.window[1], false)
    showCursor(false)
    guiSetInputEnabled(false)
end

addEvent("hideLoginWindow", true)
addEvent("hidePasswordWindow", true)
addEventHandler("hideLoginWindow", root, hideLoginWindow)
addEventHandler("hidePasswordWindow", root, hidePasswordWindow)
addEventHandler("onClientResourceStart", resourceRoot, resourceStart)
addCommandHandler("changepw", changepw)
function passwordHandler(thePlayer, password, rpassword)
    local account = getPlayerAccount(thePlayer)
	if account then
	   if isGuestAccount(account) then
	      outputChatBox("You must be logged in to change password!", thePlayer, 255, 0, 0)
		  return
	   end
	   if password == rpassword then
	      if string.len(password) >= 5 then
		      setAccountPassword(account, password)
			  triggerClientEvent(thePlayer, "hidePasswordWindow", root)
		  else
		     outputChatBox("Your new password must be at least 5 characters long!", thePlayer, 255, 0, 0)
		  end
	   else
	      outputChatBox("Your passwords aren't the same!", thePlayer, 255, 0, 0)
	   end
	end
end

function loginHandler(thePlayer, username, password)
    local account = getAccount(username, password)
	if account ~= false then
	   if (logIn(thePlayer, account, password) == true) then 
	        outputChatBox("You succefuly logged in!", thePlayer, 0, 255, 0)
	        triggerClientEvent(thePlayer, "hideLoginWindow", root)
	   else
	      outputChatBox("An error please report it to forum!", thePlayer, 255, 0, 0)
	   end
	else
	   outputChatBox("Username or password are incorrect!", thePlayer, 255, 0, 0)
	end
end

function registerHandler(thePlayer, username, password)
    local account = getAccount(username, password)
	if account ~= false then
	    outputChatBox("This username is already exist!", thePlayer, 255, 0, 0)
    else
	   account = addAccount(username, password)
	   outputChatBox("You succefuly registered!", thePlayer, 0, 255, 0)
	   if (logIn(thePlayer, account, password) == true) then
	        outputChatBox("You succefuly logged in!", thePlayer, 0, 255, 0)
			triggerClientEvent(thePlayer, "hideLoginWindow", root)
	   else
	      outputChatBox("An error please report it to forum!", thePlayer, 255, 0, 0)
	   end
	end
end

addEvent("submitChangepw", true)
addEvent("submitLogin", true)
addEvent("submitRegister", true)
addEventHandler("submitChangepw", root, passwordHandler)
addEventHandler("submitLogin", root, loginHandler)
addEventHandler("submitRegister", root, registerHandler)

 nothing

the server function is fine the client side is the problem

 

Edited by Dimos7
Link to comment

Try it this way :

 

local GUIEditor = {
   window = { },
   label = { },
   edit = { },
   button= { }
}
function createPasswordWindow()
    GUIEditor.window[1] = guiCreateWindow(693, 268, 303, 307, "Change Password", false)
    guiWindowSetMovable(GUIEditor.window[1], false)
    guiWindowSetSizable(GUIEditor.window[1], false)
    GUIEditor.label[1] = guiCreateLabel(7, 75, 289, 24, "                             New Password:", false, GUIEditor.window[1])
    guiLabelSetVerticalAlign(GUIEditor.label[1], "top")
    guiLabelSetHorizontalAlign(GUIEditor.label[1], "left")
    guiSetFont(GUIEditor.label[1], "clear-normal")
    GUIEditor.edit[1] = guiCreateEdit(9, 100, 285, 25, "", false, GUIEditor.window[1])
    guiEditSetMasked(GUIEditor.edit[1], true)
    GUIEditor.label[2] = guiCreateLabel(7, 140, 289, 24, "                             Repeat Password:", false, GUIEditor.window[1])
    guiLabelSetVerticalAlign(GUIEditor.label[2], "top")
    guiLabelSetHorizontalAlign(GUIEditor.label[2], "left")
    guiSetFont(GUIEditor.label[2], "clear-normal")
    GUIEditor.edit[2] = guiCreateEdit(9, 168, 285, 25, "", false, GUIEditor.window[1])
    guiEditSetMasked(GUIEditor.edit[2], true)
    GUIEditor.button[1] = guiCreateButton(9, 254, 143, 53, "Change", false, GUIEditor.window[1])
    GUIEditor.button[2] = guiCreateButton(153, 254, 143, 53, "Cancel", false, GUIEditor.window[1])
    guiSetVisible(GUIEditor.window[1], false)
    addEventHandler("onClientGUIClick", GUIEditor.button[1], clientSubmitChangepw, false)
    addEventHandler("onClientGUIClick", GUIEditor.button[2], hidePasswordWindow, false)
end
function createLoginWindow()
    GUIEditor.window[2] = guiCreateWindow(693, 268, 303, 307, "login Panel", false)
    guiWindowSetMovable(GUIEditor.window[2], false)
    guiWindowSetSizable(GUIEditor.window[2], false)
    GUIEditor.label[3] = guiCreateLabel(7, 75, 289, 24, "                             Username:", false, GUIEditor.window[2])
    guiLabelSetVerticalAlign(GUIEditor.label[3], "top")
    guiLabelSetHorizontalAlign(GUIEditor.label[3], "left")
    guiSetFont(GUIEditor.label[3], "clear-normal")
    GUIEditor.edit[3] = guiCreateEdit(9, 100, 285, 25, "", false, GUIEditor.window[2])
    GUIEditor.label[4] = guiCreateLabel(7, 140, 289, 24, "                             Password:", false, GUIEditor.window[2])
    guiLabelSetVerticalAlign(GUIEditor.label[4], "top")
    guiLabelSetHorizontalAlign(GUIEditor.label[4], "left")
    guiSetFont(GUIEditor.label[4], "clear-normal")
    GUIEditor.edit[4] = guiCreateEdit(9, 168, 285, 25, "", false, GUIEditor.window[2])
    guiEditSetMasked(GUIEditor.edit[4], true)
    GUIEditor.button[3] = guiCreateButton(9, 254, 143, 53, "Login", false, GUIEditor.window[2])
    GUIEditor.button[4] = guiCreateButton(153, 254, 143, 53, "Register", false, GUIEditor.window[2])
    addEventHandler("onClientGUIClick", GUIEditor.button[3], clientSubmitLogin, false)
    addEventHandler("onClientGUIClick", GUIEditor.button[4], clientSubmitRegister, false)
end
function resourceStart()
    createLoginWindow()
    if (GUIEditor.window[2] ~= nil) then
        guiSetVisible(GUIEditor.window[2], true)
    else
       outputChatBox("An error has occupied.")
    end
    showCursor(true)
    guiSetInputEnabled(true)
end
function changepw()
    createPasswordWindow()
    guiSetVisible(GUIEditor.window[1], true)
    showCursor(true)
    guiSetInputEnabled(true)
end
function clientSubmitLogin(button, state)
   -- if button == "left" and state == "down" then
       local username = guiGetText(GUIEditor.edit[3])
       local password = guiGetText(GUIEditor.edit[4])
       if username ~= "" and password ~= "" then
          triggerServerEvent("submitLogin", localPlayer, username, password)
       else
          outputChatBox("Enter username and password.", 255, 0, 0)
        --end
    end
end
function clientSubmitRegister(button, state)
   -- if button == "left" and state == "down" then
       local username = guiGetText(GUIEditor.edit[3])
       local password = guiGetText(GUIEditor.edit[4])
       if username ~= "" and password ~= "" then
          triggerServerEvent("submitRegister", localPlayer, username, password)
       else
          outputChatBox("Enter username and password.", 255, 0, 0)
       --end
    end
end
function clientSubmitChangepw(button, state)
    --if button == "left" and state == "down" then
       local password = guiGetText(GUIEditor.edit[1])
       local rpassword = guiGetText(GUIEditor.edit[2])
       if password ~= "" and rpassword ~= "" then
          triggerServerEvent("submitChangepw", localPlayer, password, rpassword)
       else
          outputChatBox("Enter new password and repeat it", 255, 0, 0)
       --end
    end
end
function hideLoginWindow()
    guiSetVisible(GUIEditor.window[2], false)
    showCursor(false)
    guiSetInputEnabled(false)
end
function hidePasswordWindow()
    guiSetVisible(GUIEditor.window[1], false)
    showCursor(false)
    guiSetInputEnabled(false)
end
addEvent("hideLoginWindow", true)
addEvent("hidePasswordWindow", true)
addEventHandler("hideLoginWindow", root, hideLoginWindow)
addEventHandler("hidePasswordWindow", root, hidePasswordWindow)
addEventHandler("onClientResourceStart", resourceRoot, resourceStart)
addCommandHandler("changepw", changepw)

 

Link to comment
function passwordHandler(thePlayer, password, rpassword)
    local account = getPlayerAccount(thePlayer)
	if account then
	   if isGuestAccount(account) then
	      outputChatBox("You must be logged in to change password!", thePlayer, 255, 0, 0)
		  return
	   end
	   if password == rpassword then
	      if string.len(password) >= 5 then
		      setAccountPassword(account, password)
			  triggerClientEvent(thePlayer, "hidePasswordWindow", root)
		  else
		     outputChatBox("Your new password must be at least 5 characters long!", thePlayer, 255, 0, 0)
		  end
	   else
	      outputChatBox("Your passwords aren't the same!", thePlayer, 255, 0, 0)
	   end
	end
end

function loginHandler(thePlayer, username, password)
    local account = getAccount(username, password)
	if account ~= false then
	   if (logIn(thePlayer, account, password) == true) then 
	        outputChatBox("You succefuly logged in!", thePlayer, 0, 255, 0)
	        triggerClientEvent(thePlayer, "hideLoginWindow", root)
	   else
	      outputChatBox("An error please report it to forum!", thePlayer, 255, 0, 0)
	   end
	else
	   outputChatBox("Username or password are incorrect!", thePlayer, 255, 0, 0)
	end
end

function registerHandler(thePlayer, username, password)
    local account = getAccount(username, password)
	if account ~= false then
	    outputChatBox("This username is already exist!", thePlayer, 255, 0, 0)
    else
	   account = addAccount(username, password)
	   outputChatBox("You succefuly registered!", thePlayer, 0, 255, 0)
	   if (logIn(thePlayer, account, password) == true) then
	        outputChatBox("You succefuly logged in!", thePlayer, 0, 255, 0)
			triggerClientEvent(thePlayer, "hideLoginWindow", root)
	   else
	      outputChatBox("An error please report it to forum!", thePlayer, 255, 0, 0)
	   end
	end
end

addEvent("submitChangepw", true)
addEvent("submitLogin", true)
addEvent("submitRegister", true)
addEventHandler("submitChangepw", root, passwordHandler)
addEventHandler("submitLogin", root, loginHandler)
addEventHandler("submitRegister", root, registerHandler)
local GUIEditor = {
   window = { },
   label = { },
   edit = { },
   button= { }
}

function createPasswordWindow()
    GUIEditor.window[1] = guiCreateWindow(693, 268, 303, 307, "Change Password", false)
    guiWindowSetMovable(GUIEditor.window[1], false)
    guiWindowSetSizable(GUIEditor.window[1], false)
    GUIEditor.label[1] = guiCreateLabel(7, 75, 289, 24, "                             New Password:", false, GUIEditor.window[1])
    guiLabelSetVerticalAlign(GUIEditor.label[1], "top")
    guiLabelSetHorizontalAlign(GUIEditor.label[1], "left")
    guiSetFont(GUIEditor.label[1], "clear-normal")
    GUIEditor.edit[1] = guiCreateEdit(9, 100, 285, 25, "", false, GUIEditor.window[1])
    guiEditSetMasked(GUIEditor.edit[1], true)
    GUIEditor.label[2] = guiCreateLabel(7, 140, 289, 24, "                             Repeat Password:", false, GUIEditor.window[1])
    guiLabelSetVerticalAlign(GUIEditor.label[2], "top")
    guiLabelSetHorizontalAlign(GUIEditor.label[2], "left")
    guiSetFont(GUIEditor.label[2], "clear-normal")
    GUIEditor.edit[2] = guiCreateEdit(9, 168, 285, 25, "", false, GUIEditor.window[1])
    guiEditSetMasked(GUIEditor.edit[2], true)
    GUIEditor.button[1] = guiCreateButton(9, 254, 143, 53, "Change", false, GUIEditor.window[1])
    GUIEditor.button[2] = guiCreateButton(153, 254, 143, 53, "Cancel", false, GUIEditor.window[1])
    guiSetVisible(GUIEditor.window[1], false)
    addEventHandler("onClientGUIClick", GUIEditor.button[1], clientSubmitChangepw, false)
    addEventHandler("onClientGUIClick", GUIEditor.button[2], hidePasswordWindow, false)
end

function createLoginWindow()
    GUIEditor.window[2] = guiCreateWindow(693, 268, 303, 307, "login Panel", false)
    guiWindowSetMovable(GUIEditor.window[2], false)
    guiWindowSetSizable(GUIEditor.window[2], false)
    GUIEditor.label[3] = guiCreateLabel(7, 75, 289, 24, "                             Username:", false, GUIEditor.window[2])
    guiLabelSetVerticalAlign(GUIEditor.label[3], "top")
    guiLabelSetHorizontalAlign(GUIEditor.label[3], "left")
    guiSetFont(GUIEditor.label[3], "clear-normal")
    GUIEditor.edit[3] = guiCreateEdit(9, 100, 285, 25, "", false, GUIEditor.window[2])
    GUIEditor.label[4] = guiCreateLabel(7, 140, 289, 24, "                             Password:", false, GUIEditor.window[2])
    guiLabelSetVerticalAlign(GUIEditor.label[4], "top")
    guiLabelSetHorizontalAlign(GUIEditor.label[4], "left")
    guiSetFont(GUIEditor.label[4], "clear-normal")
    GUIEditor.edit[4] = guiCreateEdit(9, 168, 285, 25, "", false, GUIEditor.window[2])
    guiEditSetMasked(GUIEditor.edit[4], true)
    GUIEditor.button[3] = guiCreateButton(9, 254, 143, 53, "Login", false, GUIEditor.window[2])
    GUIEditor.button[4] = guiCreateButton(153, 254, 143, 53, "Register", false, GUIEditor.window[2])
    addEventHandler("onClientGUIClick", GUIEditor.button[3], clientSubmitLogin, false)
    addEventHandler("onClientGUIClick", GUIEditor.button[4], clientSubmitRegister, false)
end

function resourceStart()
    createLoginWindow()
    if (GUIEditor.window[2] ~= nil) then
        guiSetVisible(GUIEditor.window[2], true)
    else
       outputChatBox("An error has occupied.")
    end
    showCursor(true)
    guiSetInputEnabled(true)
end

function changepw()
    createPasswordWindow()
    guiSetVisible(GUIEditor.window[1], true)
    showCursor(true)
    guiSetInputEnabled(true)
end

function clientSubmitLogin(button, state)
    if button == "left" and state == "up" then
       local username = guiGetText(GUIEditor.edit[3])
       local password = guiGetText(GUIEditor.edit[4])
       if username ~= "" and password ~= "" then
          triggerServerEvent("submitLogin", root, localPlayer, username, password)
       else
          outputChatBox("Enter username and password.", 255, 0, 0)
        end
    end
end

function clientSubmitRegister(button, state)
    if button == "left" and state == "up" then
       local username = guiGetText(GUIEditor.edit[3])
       local password = guiGetText(GUIEditor.edit[4])
       if username ~= "" and password ~= "" then
          triggerServerEvent("submitRegister", root, localPlayer, username, password)
       else
          outputChatBox("Enter username and password.", 255, 0, 0)
       end
    end
end

function clientSubmitChangepw(button, state)
    if button == "left" and state == "up" then
       local password = guiGetText(GUIEditor.edit[1])
       local rpassword = guiGetText(GUIEditor.edit[2])
       if password ~= "" and rpassword ~= "" then
          triggerServerEvent("submitChangepw", root, localPlayer, password, rpassword)
       else
          outputChatBox("Enter new password and repeat it", 255, 0, 0)
       end
    end
end

function hideLoginWindow()
    guiSetVisible(GUIEditor.window[2], false)
    showCursor(false)
    guiSetInputEnabled(false)
end

function hidePasswordWindow()
    guiSetVisible(GUIEditor.window[1], false)
    showCursor(false)
    guiSetInputEnabled(false)
end

addEvent("hideLoginWindow", true)
addEvent("hidePasswordWindow", true)
addEventHandler("hideLoginWindow", root, hideLoginWindow)
addEventHandler("hidePasswordWindow", root, hidePasswordWindow)
addEventHandler("onClientResourceStart", resourceRoot, resourceStart)
addCommandHandler("changepw", changepw)

every time i press register is auto login the account 

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