death666machine Posted November 22, 2011 Share Posted November 22, 2011 well i made this script with the help of comunity resources and the wiki but the login and register buttons wont work. Client script local localPlayer = getLocalPlayer() local playerName = getPlayerName(localPlayer) function loginWindow() GUIEditor_Button = {} GUIEditor_Label = {} GUIEditor_Edit = {} GUIEditor_Image = {} GUIEditor_Image[1] = guiCreateStaticImage(0,0,1,1,"images/LoginBack.png",true) GUIEditor_Image[2] = guiCreateStaticImage(.2,.1,.6,.4,"images/Logo.png",true,GUIEditor_Image[1]) GUIEditor_Edit[1] = guiCreateEdit(.2,.7,.2,.05,"",true,GUIEditor_Image[1]) guiEditSetMaxLength(GUIEditor_Edit[1],25) GUIEditor_Edit[2] = guiCreateEdit(.6,.7,.2,.05,"",true,GUIEditor_Image[1]) guiEditSetMasked(GUIEditor_Edit[2],true) guiEditSetMaxLength(GUIEditor_Edit[2],25) GUIEditor_Label[1] = guiCreateLabel(.2,.6,.2,.1,"Username:",true,GUIEditor_Image[1]) guiLabelSetColor(GUIEditor_Label[1],0,0,255) guiSetFont(GUIEditor_Label[1],"sa-gothic") GUIEditor_Label[2] = guiCreateLabel(.6,.6,.2,.1,"Password:",true,GUIEditor_Image[1]) guiLabelSetColor(GUIEditor_Label[2],0,0,255) guiSetFont(GUIEditor_Label[2],"sa-gothic") GUIEditor_Button[1] = guiCreateButton(.825,.1,.1,.1,"Guest",true,GUIEditor_Image[1]) guiSetFont(GUIEditor_Button[1],"sa-header") GUIEditor_Button[2] = guiCreateButton(.45,.7,.1,.1,"Login",true,GUIEditor_Image[1]) guiSetFont(GUIEditor_Button[2],"default-bold-small") GUIEditor_Button[3] = guiCreateButton(.45,.85,.1,.1,"Register",true,GUIEditor_Image[1]) guiSetFont(GUIEditor_Button[3],"default-bold-small") guiSetVisible(GUIEditor_Image[1], false) addEventHandler("onClientGUIClick", GUIEditor_Button[1], submitGuest, false) addEventHandler("onClientGUIClick", GUIEditor_Button[2], submitLogin, false) addEventHandler("onClientGUIClick", GUIEditor_Button[3], submitRegister, false) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () loginWindow() if (GUIEditor_Image[1] ~= nil) then guiSetVisible(GUIEditor_Image[1], true) else outputChatBox("An unexpected error has occurred and the log in GUI has not been created. Please reconnect and try again.") end showCursor(true) guiSetInputEnabled(true) end ) function submitGuest(button,state) if button == "left" and state == "up" then guiSetInputEnabled(false) guiSetVisible(GUIEditor_Image[1], false) showCursor(false) outputChatBox("You are playing as a guest please register.") end end function submitLogin(button,state) if button == "left" and state == "up" then local username = guiGetText(username) local password = guiGetText(password) if username and password then triggerServerEvent("submitLogin", getRootElement(), localPlayer, username, password) end end end function submitRegister(button,state) if button == "left" and state == "up" then local username = guiGetText(username) local password = guiGetText(password) if username and password then triggerServerEvent("submitRegister", getRootElement(), localPlayer, username, password) end end end function hideLoginWindow() guiSetInputEnabled(false) guiSetVisible(GUIEditor_Image[1], false) showCursor(false) end function unknownError() outputChatBox("Error 1: Please reconnect and try again.") end function loginWrong() outputChatBox("Error 2: Wrong username/password") end function registerTaken() outputChatBox("Error 3: This name is already taken.") end addEvent("hideLoginWindow", true) addEvent("unknownError", true) addEvent("loginWrong", true) addEvent("registerTaken", true) addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) addEventHandler("unknownError", getRootElement(), unknownError) addEventHandler("loginWrong", getRootElement(), loginWrong) addEventHandler("registerTaken", getRootElement(), registerTaken) Server Script function loginHandler(player, username, password) local account = getAccount(username, password) if (account ~= false) then if (logIn(player, account, password) == true) then triggerClientEvent (player, "hideLoginWindow", getRootElement()) else triggerClientEvent (player, "unknownError", getRootElement()) end else triggerClientEvent (player, "loginWrong", getRootElement()) end end function registerHandler(player, username, password) local account = getAccount(username, password) if (account ~= false) then triggerClientEvent(player, "registerTaken", getRootElement()) else account = addAccount(username, password) if (logIn(player, account, password) == true) then triggerClientEvent(player, "hideLoginWindow", getRootElement()) else triggerClientEvent(player, "unknownError", getRootElement()) end end end addEvent("submitLogin", true) addEvent("submitRegister", true) addEventHandler("submitLogin", getRootElement(), loginHandler) addEventHandler("submitRegister", getRootElement(), registerHandler) Any help would be appreciated. Thanks Link to comment
unknooooown Posted November 22, 2011 Share Posted November 22, 2011 I have made quite a few changes, but I think it works now. Can't test it 100% since I dont have your images. But try it and tell me if it works. If not, then I'll see what I can do then. I can't even remember all the changed that I made, so I hope that you can spot them yourself Just ask if there is something you don't understand about the changed. Btw.. There are a few tips that I can give you. localPlayer - Is a predefined variable. Use that instead of typing getLocalPlayer() root - Is a predefined variable. Use that instead of typing getRootElement() When triggering events, try using localPlayer(clientside) or source,theplayer,player(serverside) as the trigger, not the root. If you trigger it on the root, it will trigger for ALL players on the server. But if you trigger on localPlayer,source,theplayer or player it will only trigger for that client. Client: local playerName = getPlayerName(localPlayer) GUIEditor_Button = {} GUIEditor_Label = {} GUIEditor_Edit = {} GUIEditor_Image = {} function loginWindow() showCursor(true) GUIEditor_Image[1] = guiCreateStaticImage(0,0,1,1,"images/LoginBack.png",true) GUIEditor_Image[2] = guiCreateStaticImage(.2,.1,.6,.4,"images/Logo.png",true,GUIEditor_Image[1]) GUIEditor_Edit[1] = guiCreateEdit(.2,.7,.2,.05,"",true,GUIEditor_Image[1]) guiEditSetMaxLength(GUIEditor_Edit[1],25) GUIEditor_Edit[2] = guiCreateEdit(.6,.7,.2,.05,"",true,GUIEditor_Image[1]) guiEditSetMasked(GUIEditor_Edit[2],true) guiEditSetMaxLength(GUIEditor_Edit[2],25) GUIEditor_Label[1] = guiCreateLabel(.2,.6,.2,.1,"Username:",true,GUIEditor_Image[1]) guiLabelSetColor(GUIEditor_Label[1],0,0,255) guiSetFont(GUIEditor_Label[1],"sa-gothic") GUIEditor_Label[2] = guiCreateLabel(.6,.6,.2,.1,"Password:",true,GUIEditor_Image[1]) guiLabelSetColor(GUIEditor_Label[2],0,0,255) guiSetFont(GUIEditor_Label[2],"sa-gothic") GUIEditor_Button[1] = guiCreateButton(.825,.1,.1,.1,"Guest",true,GUIEditor_Image[1]) guiSetFont(GUIEditor_Button[1],"sa-header") GUIEditor_Button[2] = guiCreateButton(.45,.7,.1,.1,"Login",true,GUIEditor_Image[1]) guiSetFont(GUIEditor_Button[2],"default-bold-small") GUIEditor_Button[3] = guiCreateButton(.45,.85,.1,.1,"Register",true,GUIEditor_Image[1]) guiSetFont(GUIEditor_Button[3],"default-bold-small") guiSetVisible(GUIEditor_Image[1], false) addEventHandler("onClientGUIClick", GUIEditor_Button[1], submitGuest, false) addEventHandler("onClientGUIClick", GUIEditor_Button[2], submitLogin, false) addEventHandler("onClientGUIClick", GUIEditor_Button[3], submitRegister, false) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () loginWindow() end ) function submitGuest(button,state) if button == "left" and state == "up" then guiSetInputEnabled(false) guiSetVisible(GUIEditor_Image[1], false) showCursor(false) outputChatBox("You are playing as a guest please register.") end end function submitLogin(button,state) if button == "left" and state == "up" then local username = guiGetText(GUIEditor_Edit[1]) local password = guiGetText(GUIEditor_Edit[2]) if username and password then triggerServerEvent("submitLogin", localPlayer, localPlayer, username, password) end end end function submitRegister(button,state) if button == "left" and state == "up" then local username = guiGetText(GUIEditor_Edit[1]) local password = guiGetText(GUIEditor_Edit[2]) if username and password then triggerServerEvent("submitRegister", localPlayer, localPlayer, username, password) end end end function hideLoginWindow() guiSetInputEnabled(false) guiSetVisible(GUIEditor_Image[1], false) showCursor(false) end function unknownError() outputChatBox("Error 1: Please reconnect and try again.") end function loginWrong() outputChatBox("Error 2: Wrong username/password") end function registerTaken() outputChatBox("Error 3: This name is already taken.") end addEvent("hideLoginWindow", true) addEvent("unknownError", true) addEvent("loginWrong", true) addEvent("registerTaken", true) addEventHandler("hideLoginWindow", localPlayer, hideLoginWindow) addEventHandler("unknownError", localPlayer, unknownError) addEventHandler("loginWrong", localPlayer, loginWrong) addEventHandler("registerTaken", localPlayer, registerTaken) Server: function loginHandler(thePlayer, username, password) local account = getAccount(username, password) if account then triggerClientEvent (thePlayer, "hideLoginWindow", thePlayer) else triggerClientEvent (thePlayer, "loginWrong", thePlayer) end end function registerHandler(thePlayer, username, password) if getAccount(username) then triggerClientEvent(thePlayer, "registerTaken", thePlayer) else account = addAccount(username, password) if account then triggerClientEvent(thePlayer, "hideLoginWindow", thePlayer) else triggerClientEvent(thePlayer, "unknownError", thePlayer) end end end addEvent("submitLogin", true) addEvent("submitRegister", true) addEventHandler("submitLogin", root, loginHandler) addEventHandler("submitRegister", root, registerHandler) META: Link to comment
death666machine Posted November 26, 2011 Author Share Posted November 26, 2011 thanks so much it works now +rep Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now