MaVe Posted December 4, 2008 Share Posted December 4, 2008 (edited) Hi, i read the tutorial on the MTA Wiki (http://development.mtasa.com/index.php? ... ipting_GUI) I have the following problem: When somebody connects and is registered, he can't login. Nothing happens when the Login button is pressed. Code: Server: function joinHandler(username, password) --local x,y,z --x = 1959.55 --y = -1714.46 --z = 10 if (client) then --spawnPlayer(client, x, y, z) fadeCamera(client, true) outputChatBox("Welcome to My Server", client) end end addEvent("SubmitLogin", true) addEventHandler("SubmitLogin", getRootElement(), joinHandler) Client: function CreateLoginWindow() local X = 0.375 local Y = 0.375 local Width = 0.25 local Height = 0.25 wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true) X = 0.0825 Y = 0.2 Width = 0.25 Height = 0.25 guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin) Y = 0.5 guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin) X = 0.415 Y = 0.2 Width = 0.5 Height = 0.15 edtUser = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin) Y = 0.5 edtPass = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin) guiEditSetMaxLength(edtUser, 50) guiEditSetMaxLength(edtPass, 50) X = 0.415 Y = 0.7 Width = 0.25 Height = 0.2 btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin) guiSetVisible(wdwLogin, false) end function initGUI( ) CreateLoginWindow() outputChatBox("Welcome to My MTA DM Server, please log in.") if (wdwLogin ~= nil) then guiSetVisible(wdwLogin, true) end showCursor(true) guiSetInputEnabled(true) end addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), initGUI ) addEventHandler("onClientGUIClick", btnLogin, function(button) outputChatBox("blabla 1") if button == "left" then outputChatBox("blabla 2") triggerServerEvent("SubmitLogin", getRootElement(), guiGetText(edtUser), guiGetText(edtPass)) guiSetInputEnabled(false) guiSetVisible(wdwLogin, false) showCursor(false) end end) What's wrong? Edited December 4, 2008 by Guest Link to comment
Lordy Posted December 4, 2008 Share Posted December 4, 2008 Umm.. your joinhandler function only does a fadeCamera and outputChatBox, nothing else. To make it login too, you have to code it as such too Link to comment
MaVe Posted December 4, 2008 Author Share Posted December 4, 2008 Umm.. your joinhandler function only does a fadeCamera and outputChatBox, nothing else. To make it login too, you have to code it as such too I think you dont understand my code. the joinhandler function gets executed when player clicked "login".. But my onClientGUIClick event doesnt get fired-.- Link to comment
Ace_Gambit Posted December 4, 2008 Share Posted December 4, 2008 There is a typo in the wiki example. Change "client" to "source". Link to comment
MaVe Posted December 4, 2008 Author Share Posted December 4, 2008 There is a typo in the wiki example. Change "client" to "source". which "client"? in the server part, in the line with "if (client) then" ??? Link to comment
Ace_Gambit Posted December 4, 2008 Share Posted December 4, 2008 which "client"? in the server part, in the line with "if (client) then" ??? if (source) then --spawnPlayer(source, x, y, z) fadeCamera(source, true) outputChatBox("Welcome to My Server", source) end Link to comment
MaVe Posted December 4, 2008 Author Share Posted December 4, 2008 It still doesn't work. As i said, the onClientGUIClick event doesnt get fired. I can't see my debug messages (btw: i have already removed the ";"s at the end of the row. Link to comment
Lordy Posted December 4, 2008 Share Posted December 4, 2008 Ace_Gambit: The client variable is allowed too.. It's passed with triggerServerEvent() as the local player. You don't always pass localPlayer as source, now do you? I think you dont understand my code. the joinhandler function gets executed when player clicked "login".. But my onClientGUIClick event doesnt get fired-.- I agree that I didn't look too much into that code, BUT you didn't mention what kind of problems you were having too, and my crystal ball seems to be out of order atm. Link to comment
MaVe Posted March 6, 2009 Author Share Posted March 6, 2009 Omg i couldnt get it working yet... Can somebody help me and tell me how to make the onClientGUIClicked event? Link to comment
Mr.Hankey Posted March 6, 2009 Share Posted March 6, 2009 you should move the addEventHandler ("onClientGUIClick" ...) line into the createLoginWindow as at the position where it get's called atm btnLogin doesn't exist. Link to comment
50p Posted March 6, 2009 Share Posted March 6, 2009 Take a look at this MaVe: https://community.multitheftauto.com/index.php?p= ... ils&id=241 Link to comment
MaVe Posted March 6, 2009 Author Share Posted March 6, 2009 Take a look at this MaVe: https://community.multitheftauto.com/index.php?p= ... ils&id=241 You wont believe it, i tried this aswell and got the same problem... But anyway, i already solved it by putting the addEventHandler in the onClientResourceStart event Link to comment
eAi Posted March 6, 2009 Share Posted March 6, 2009 If there's a mistake on the wiki, please fix it! Link to comment
MaVe Posted March 6, 2009 Author Share Posted March 6, 2009 If there's a mistake on the wiki, please fix it! I think i just understood it wrong, because the wiki didnt mention good enough where i should add the event handler... Link to comment
DutchCaffeine Posted March 7, 2009 Share Posted March 7, 2009 The addEventHandler can be anywhere in your script, example: function pEnter(player) print(tostring(player) .. " entered vehicle: " .. tostring(source)); end function rStart() -- this can here addEventHandler("onPlayerEnterVehicle", getRootElement(), pEnter); end -- and here addEventHandler("onPlayerEnterVehicle", getRootElement(), pEnter); addEventHandler("onResourceStart", getRootElement(), rStart); Link to comment
50p Posted March 7, 2009 Share Posted March 7, 2009 I'll try to explain how all this works. The thing is that when resource starts, it first executes all the code in the scripts (from top left to the bottom right of the file, from left to right) after that the server (or client) triggers on(Client)ResourceStart. So, follow these steps (in order from 1-6, don't read 6 if you haven't read 5! That way you will understand better): -- 1st, this function is defined but is not called, why should it be called now? function resourceStarted( ) -- 6th, finally onClientResourceStart is triggered and calls this function -- which makes a button! Now you should addEventHandler with this button because it's created -- and ready to be used button = guiCreateButton( 10, 200, 100, 20, "1337 button", false ) end -- 2nd, you call this addEventHandler function which attaches a function to an event addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource() ), resourceStarted ) -- 3rd, this function is defined but is not called, why should it be called now? function buttonClicked( ) outputChatBox( "Wow! You clicked a button! Do it again!" ); end -- 4th, you call addEventHandler function which attaches a function to an event -- but what is button? it wasn't created yet! keep going --> addEventHandler( "onClientGUIClick", button, buttonClicked, false ) -- 5th, there is nothing here, right? so, onClientResourceStart is triggered, lets do it now! (go to 6th) Link to comment
MaVe Posted March 7, 2009 Author Share Posted March 7, 2009 The addEventHandler can be anywhere in your script, example: function pEnter(player) print(tostring(player) .. " entered vehicle: " .. tostring(source)); end function rStart() -- this can here addEventHandler("onPlayerEnterVehicle", getRootElement(), pEnter); end -- and here addEventHandler("onPlayerEnterVehicle", getRootElement(), pEnter); addEventHandler("onResourceStart", getRootElement(), rStart); Yes its possible for callbacks like that, but OnClientGUIClick(ed?) you need to pass the button element, and that element is defined in onClientResourceStart, so i have to add the eventhandler-adder there. Link to comment
DutchCaffeine Posted March 7, 2009 Share Posted March 7, 2009 50p shows also a very good example. Example for buttons: function buildMyWindow() local window = guiCreateWindow(x, y, w, h, title, relative); local btn = guiCreateButton(x, y, w, h, title, relative); addEventHandler("onClientGUIClick", btn, btnClick, false); -- See i don't use getRootElement but i use the button element. end function btnClick(button) outputChatBox("my button is clicked YEEHAA", getLocalPlayer()); end Link to comment
Lordy Posted March 7, 2009 Share Posted March 7, 2009 Interesting why do you pass the red colour value as a local player? Hint: clientside outputChatBox doesn't have visibleTo argument Link to comment
robhol Posted March 7, 2009 Share Posted March 7, 2009 Interesting why do you pass the red colour value as a local player?Hint: clientside outputChatBox doesn't have visibleTo argument Rofl, owned. Link to comment
MaVe Posted March 7, 2009 Author Share Posted March 7, 2009 Don't try to help me, as i said i already found out how it works. Thanks anyway. Link to comment
50p Posted March 7, 2009 Share Posted March 7, 2009 Interesting why do you pass the red colour value as a local player?Hint: clientside outputChatBox doesn't have visibleTo argument Rofl, owned. If you want to post something on this forum use your brain sometimes and think about what you're going to post... This post was useless Alexander, I did show a good example of how scripts work and why it didn't work for him. If you want to be a scripter you should know how things work not just how to script because one day you may get a problem and you won't even know what causes it. 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