aralmo Posted October 29, 2008 Share Posted October 29, 2008 Im working on a login / register screen for my first gamemod ever in MTA, but im having some weird problems with it. Perhaps some experienced user can help me I have two problems. The first is that when i connect to my localhost server for first time the client script don't work, i must disconnect and connect again and then it loads ok. I think is some kind of bug with the download manager?. The second one is a problem calling the client event that shows the login screen, it only works the first time i call it. Thats my code: Server side: function playerJoinHandler() outputChatBox("Player connecting...",source) triggerClientEvent("ShowLoginGUIEvent",source) --trigger the client event of the player end addEventHandler("onPlayerJoin", getRootElement(), playerJoinHandler) function SubmitLoginHandler(user,pass) outputChatBox("slh",source) local acc = getAccount(user) if (not acc) then outputChatBox("This name is not registered.",source) triggerClientEvent("ShowLoginGUIEvent",source) --trigger the client event of the player else if (logIn(source,acc,pass)) then outputChatBox("Login correct.",source) else outputChatBox("Login incorrect.",source) triggerClientEvent("ShowLoginGUIEvent",source) --trigger the client event of the player end end end addEvent("SubmitLoginEvent",true) addEventHandler("SubmitLoginEvent",getRootElement(),SubmitLoginHandler); Client side: function guiShowLogin() outputChatBox("Login.", getLocalPlayer()) CreateLoginWindow() addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) if (wdwLogin ~= nil) then guiSetVisible(wdwLogin, true) end showCursor(true) guiSetInputEnabled(true) end addEventHandler("ShowLoginGUIEvent", getLocalPlayer(),guiShowLogin,false) Link to comment
aralmo Posted October 29, 2008 Author Share Posted October 29, 2008 Just realized that source wasn't pointing exactly to the player object . Link to comment
50p Posted October 29, 2008 Share Posted October 29, 2008 You are trying to trigger client event but the event is not added. When you try to trigger client event when player joins the server it won't be possible if the client hasn't got the script on his PC. The player must download the script first. Use onClientResourceStart. Link to comment
Lordy Posted October 29, 2008 Share Posted October 29, 2008 And you trigger it for all clients.. Although using the getlocalplayer in event handler is good too, it's better imo to trigger it only for the player who joined. Check the first argument on triggerclientevent from wiki. Link to comment
aralmo Posted October 29, 2008 Author Share Posted October 29, 2008 50p Thanks!, now it works perfect. And you trigger it for all clients.. Although using the getlocalplayer in event handler is good too, it's better imo to trigger it only for the player who joined. Check the first argument on triggerclientevent from wiki. Do you mean the SubmitLoginEvent in server side? im triggering it without propagation on the root element is that right? or should i create a new eventhandler when a player connects and attach the event to it? By the way im very impressed with the scripting in MTA much better than SA-MP's PAWNO imho. I'm definitely switching to it Link to comment
Gamesnert Posted October 29, 2008 Share Posted October 29, 2008 The second one is a problem calling the client event that shows the login screen, it only works the first time i call it.Thats my code: Server side: function playerJoinHandler() outputChatBox("Player connecting...",source) triggerClientEvent("ShowLoginGUIEvent",source) --trigger the client event of the player end addEventHandler("onPlayerJoin", getRootElement(), playerJoinHandler) function SubmitLoginHandler(user,pass) outputChatBox("slh",source) local acc = getAccount(user) if (not acc) then outputChatBox("This name is not registered.",source) triggerClientEvent("ShowLoginGUIEvent",source) --trigger the client event of the player else if (logIn(source,acc,pass)) then outputChatBox("Login correct.",source) else outputChatBox("Login incorrect.",source) triggerClientEvent("ShowLoginGUIEvent",source) --trigger the client event of the player end end end addEvent("SubmitLoginEvent",true) addEventHandler("SubmitLoginEvent",getRootElement(),SubmitLoginHandler); Client side: function guiShowLogin() outputChatBox("Login.", getLocalPlayer()) CreateLoginWindow() addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) if (wdwLogin ~= nil) then guiSetVisible(wdwLogin, true) end showCursor(true) guiSetInputEnabled(true) end addEventHandler("ShowLoginGUIEvent", getLocalPlayer(),guiShowLogin,false) You're having problems with it. Ok let's see... 1. Adding addEvent in client-side might help? 2. triggerClientEvent("ShowLoginGUIEvent",source) Should be: triggerClientEvent(source,"ShowLoginGUIEvent",source) 3. Source isn't specified in function SubmitLoginHandler. Are you using it while doing triggerServerEvent? Link to comment
aralmo Posted October 31, 2008 Author Share Posted October 31, 2008 Gamesnert: Yeah thanks, im using it without target because the event was attached to the player element. But that its not working at all. Right now i got a login/registration page, a working character sheet and a skill upgrade window. Everything works perfect if you don't change the nickname before login. So my next question is, there's anyway i can attach a client event to the client element, not the player? because the player element changes when you change your nick. Right now i have something like this Client code: addEvent("MyClientEvent",true) addEventHandler("MyClientEvent",getLocalPlayer(),myEventHandler) Server code: function clientLogin(old,new) triggerClientEventHandler(source,"MyClientEvent",source,false) end It works if old=new in clientLogin else it dosn't ejecutes the handler on client-side. Thats making me crazy, did all the stuff in about 5 hours but those small things took-me like 2 days until now. [edit] oh! and another noob question is lua object-oriented? can you create a class with inheritance on it? Thanks. Link to comment
Lordy Posted October 31, 2008 Share Posted October 31, 2008 Are you sure that player element changes on nick change? I don't think so. And it's triggerClientEvent() not triggerClientEventHandler() client addEvent("myEvent", true) addEventHandler("myEvent", getRootElement(), handlerFunction) server triggerClientEvent(thePlayer, "myEvent", getRootElement(), variable) I think it should work that way. Haven't checked my resources or wiki atm Link to comment
aralmo Posted October 31, 2008 Author Share Posted October 31, 2008 Yeah, youre right. Too much time without sleep i guess, tested it again right now and it was already working good. Sorry bout the time waste. 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