Jump to content

triggerServerEvent problem


Snoozy

Recommended Posts

Posted

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.

Posted

if your event code is server-side (is it?), then why it has client-side functions like guiSetInputEnabled(false) and guiSetVisible(wdwLogin, false)?

Posted

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?

Posted

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?

Posted

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)

Posted

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?

Posted

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 ;)

Posted

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

Posted

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 :)

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...