Corsaro Quad Posted November 26, 2011 Posted November 26, 2011 (edited) Hi. I've started to write the login GUI. I followed the tutorial on MTA wiki but there is a problem, in my mind, on triggering the server event. And I want to play a mp3 file when the player join into the server, but it doesn't work... This is the client code: function createLoginWindow() lblReportTxt = "Please LogIn." wdwLogin = guiCreateWindow(504,255,407,175,"Welcome!",false) lblReport = guiCreateLabel(15,27,70,16,lblReportTxt,false,wdwLogin) btnLogin = guiCreateButton(316,146,80,20,"LogIn",false,wdwLogin) lblUser = guiCreateLabel(85,62,61,17,"Username: ",false,wdwLogin) lblPass = guiCreateLabel(85,106,61,17,"Password:",false,wdwLogin) edtUser = guiCreateEdit(146,62,217,17,"",false,wdwLogin) guiEditSetMaxLength(edtUser,20) edtPass = guiCreateEdit(147,106,216,17,"",false,wdwLogin) guiEditSetMasked(edtPass,true) guiEditSetMaxLength(edtPass,20) -- make the window invisible guiSetVisible(wdwLogin, false) end addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () --getGamemodeVersion() welcomeSound = playSound("sounds/theme.mp3") setSoundVolume(welcomeSound, 0.5) -- create the log in window and its components createLoginWindow() -- output a brief welcome message to the player outputChatBox("Welcome to My MTA:SA Server, please log in.") -- if the GUI was successfully created, then show the GUI to the player if (wdwLogin ~= nil) then guiSetVisible(wdwLogin, true) else -- if the GUI hasnt been properly created, tell the player outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") end -- enable the players cursor (so they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening guiSetInputEnabled(true) end ) function clientSubmitLogin(button,state) if button == "left" and state == "up" then -- get the text entered in the 'username' field local username = guiGetText(edtUser) -- get the text entered in the 'password' field local password = guiGetText(edtPass) -- if the username and password both exist if username and password then -- trigger the server event 'submitLogin' and pass the username and password to it triggerServerEvent("submitLogin", getRootElement(), username, password) -- hide the gui, hide the cursor and return control to the player guiSetInputEnabled(false) guiSetVisible(wdwLogin, false) showCursor(false) else -- otherwise, output a message to the player, do not trigger the server -- and do not hide the gui outputChatBox("Please enter a username and password.") end end end And this is the server code: function loginHandler(username,password) -- check that the username and password are correct if username == "user" and password == "apple" then -- the player has successfully logged in, so spawn them if (source) then spawn(source) fadeCamera(source, true) setCameraTarget(source, source) outputChatBox("Connected!", source) end else -- if the username or password are not correct, output a message to the player outputChatBox("Invalid username and password. Please re-connect and try again.",source) end end addEvent("submitLogin",true) addEventHandler("submitLogin",root,loginHandler) Thanks for your support. Edited November 26, 2011 by Guest
BinSlayer1 Posted November 26, 2011 Posted November 26, 2011 clientside errors: addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) should be in the createLoginWindow function also: triggerServerEvent("submitLogin", getRootElement(), username, password) should be: triggerServerEvent("submitLogin", getLocalPlayer(), username, password) About the server side part, why are you checking is username is 'user' and pass is 'apple' ? Doesn't make any sense Also.. spawn(source) ? spawn is no predefined function.. that would be spawnPlayer https://wiki.multitheftauto.com/wiki/SpawnPlayer
Corsaro Quad Posted November 26, 2011 Author Posted November 26, 2011 clientside errors:addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) should be in the createLoginWindow function also: triggerServerEvent("submitLogin", getRootElement(), username, password) should be: triggerServerEvent("submitLogin", getLocalPlayer(), username, password) About the server side part, why are you checking is username is 'user' and pass is 'apple' ? Doesn't make any sense Also.. spawn(source) ? spawn is no predefined function.. that would be spawnPlayer https://wiki.multitheftauto.com/wiki/SpawnPlayer Thanks. It works. (spawn(source) is my personal function) But now it doesn't work the playSound... How can I resolve this?
^Dev-PoinT^ Posted November 26, 2011 Posted November 26, 2011 what about use this? function play () welcomeSound = playSound("sounds/theme.mp3") setSoundVolume(welcomeSound, 0.5) end addEventHandler("onClientPlayerJoin", getRootElement(), play)
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