Snoozy Posted January 5, 2011 Share Posted January 5, 2011 I keep getting the error ERROR: Client triggered serverside event submitLogin, but event is not added serverside I'm rather confused about this and have been unable to find the problem. function loginHandler(username,password) handler = mysql_connect(".......", ".....", "......", ".....") if ( not handler ) then outputChatBox("Unable to connect to the MySQL server") else outputChatBox("Able to connect to the MySQL server") mysql_close(handler) end if username == "g" and password == "a" then if (source) then guiSetInputEnabled(false) guiSetVisible(wdwLogin, false) showCursor(false) outputChatBox("Logged in successfully",source) spawnPlayer(source, 1959.55, -1714.46, 10) fadeCamera(source, true) setCameraTarget(source) end else outputChatBox("Invalid username and password. Please re-connect and try again.",source) end end addEvent("submitLogin",true) addEventHandler("submitLogin",root,loginHandler) AND triggerServerEvent ("submitLogin", getLocalPlayer(),username,password) When clicking the button that is executing that trigger event nothing happens ingame but in console the above error is happening. Link to comment
Aibo Posted January 5, 2011 Share Posted January 5, 2011 if your event code is server-side (is it?), then why it has client-side functions like guiSetInputEnabled(false) and guiSetVisible(wdwLogin, false)? Link to comment
Snoozy Posted January 5, 2011 Author Share Posted January 5, 2011 Ah well to ask the "why", I'm new at LUA, coming from a PAWN environment of scripting so really not used to clientside, serverside, you think changing those will fix it? Link to comment
SDK Posted January 5, 2011 Share Posted January 5, 2011 Probably not, the error happens before those functions. But you still need to keep them clientside (all GUI stuff). Is everything correct in the meta.xml? Link to comment
Snoozy Posted January 5, 2011 Author Share Posted January 5, 2011 ="client/login.lua" type="client" /> Link to comment
SDK Posted January 5, 2011 Share Posted January 5, 2011 It looks like you got most lines from here, but you're mixing server and client up. meta.xml ... <script src="login_s.lua" type="server" /> <script src="login_c.lua" type="client" /> ... login_s.lua (server): function loginHandler(username,password) handler = mysql_connect(".......", ".....", "......", ".....") if ( not handler ) then outputChatBox("Unable to connect to the MySQL server") else outputChatBox("Able to connect to the MySQL server") mysql_close(handler) end if username == "g" and password == "a" then if (source) then outputChatBox("Logged in successfully",source) spawnPlayer(source, 1959.55, -1714.46, 10) fadeCamera(source, true) setCameraTarget(source) end else outputChatBox("Invalid username and password. Please re-connect and try again.",source) end end addEvent("submitLogin",true) addEventHandler("submitLogin",root,loginHandler) login_c.lua (client) : ... -- your code when clicking the button triggerServerEvent ("submitLogin", getLocalPlayer(),username,password) ... (These files are only an example, you can use your own names and folders) Link to comment
Snoozy Posted January 5, 2011 Author Share Posted January 5, 2011 Yea I did get lines from wiki as I'm just trying to get the basics of how it all should work before going on my own anyways. So uhm are you able to call a function that will then go onto another script? I didn't know that like call a event that actually is on another lua file? Link to comment
SDK Posted January 5, 2011 Share Posted January 5, 2011 It's not only an other file, the event will be called from the client to the server. Maybe you should try rereading this tutorial as well: https://wiki.multitheftauto.com/wiki/Scripting_Introduction#What_you_need_to_know You can download some simple login resource from the community to get some examples if you're still confused. Link to comment
Snoozy Posted January 5, 2011 Author Share Posted January 5, 2011 If you don't mind I'm gonna ask a last question to you about events and so on, does this mean you can't have two events named the same cause like every event is like in a way getting connected to one big server when you start the script? Also it's working now, got a few bugs but that's some missing scripting I haven't added Link to comment
SDK Posted January 5, 2011 Share Posted January 5, 2011 1. You can have one event attached to multiple functions if that's what you mean: addEvent("thePlayerSpawned", true) addEventHandler("thePlayerSpawned",getRootElement(), giveThePlayerSomeClothes) addEventHandler("thePlayerSpawned",getRootElement(), tellEveryoneThePlayerSpawned) addEventHandler("thePlayerSpawned",getRootElement(), giveHimSomeCashToStart) Now this would trigger all functions attached to it: triggerServerEvent("thePlayerSpawned", getLocalPlayer()) 2. Events can be called from the client to the server, but also from the server to the client Link to comment
Snoozy Posted January 5, 2011 Author Share Posted January 5, 2011 Ah okay think I'm getting it now, that was quite a huge help since I didn't know that and it will sure come handy later on, thank you SDK for the help 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