Bebras

triggerClientEvent

Recommended Posts

Hello, so my topic name is not very informative as i don't really know where the problem is...

Anyway, this is my server-side code:

function checkPlayer(playerNick) 
    local result = mysql_query(handler,"SELECT * FROM users WHERE Name = '"..playerNick.."'") 
    if( not result) then outputDebugString("MySQL Fail ("..mysql_errno(handler)..") Error:"..mysql_error(handler)) 
    end 
    if(mysql_num_rows(result) == 0) then 
        triggerClientEvent("onRegister",getRootElement()) 
        outputDebugString("Should be triggered") 
    else 
        row = mysql_fetch_row(result) 
         
    end 
    mysql_free_result(result) 
end 
addEventHandler("onPlayerConnect",getRootElement(),checkPlayer) 

and this is my client-side code:

function registerHandler() 
    outputDebugString("Function for registering is called") 
end 
addEvent("onRegister",true) 
addEventHandler("onRegister",getRootElement(),registerHandler) 

And the string "function for registering is called" isn't printed out.. I did it exactly like in the wiki, and yet i failed somehow...

where is the problem?

Share this post


Link to post

If you meant here:

addEventHandler("onRegister",getLocalPlayer(),registerHandler) 

, then it didn't help :(

Share this post


Link to post

No look:

triggerClientEvent("onRegister",getLocalPlayer()) 

You are triggering a client event and you need a player to handle that.

Share this post


Link to post

Tried it, got this error: attempt to call global 'getLocalPlayer'

Off-topic: what is "nil" is it like null?

Share this post


Link to post

It's because this:

   if(mysql_num_rows(result) == 0) then 

It checks if the rows are 0 then trigger it to the client.

and kevenz, getLocalPlayer()[localPlayer] on the server? LAL, that doesn't make any sense

Share this post


Link to post
It's because this:
   if(mysql_num_rows(result) == 0) then 

It checks if the rows are 0 then trigger it to the client.

and kevenz, getLocalPlayer()[localPlayer] on the server? LAL, that doesn't make any sense

I'm sorry, what is wrong with it? Because you just described what i want it to do

Share this post


Link to post

Wel, you should debug it:

function checkPlayer(playerNick) 
    local result = mysql_query(handler,"SELECT * FROM users WHERE Name = '"..playerNick.."'") 
outputChatBox ( "Result: "..result ) 
    if( not result) then outputDebugString("MySQL Fail ("..mysql_errno(handler)..") Error:"..mysql_error(handler)) 
    end 
outputChatBox ("mysql_num_rows: " ..mysql_num_rows(result)) 
  
    if(mysql_num_rows(result) == 0) then 
        triggerClientEvent("onRegister",getRootElement()) 
        outputDebugString("Should be triggered") 
    else 
        row = mysql_fetch_row(result) 
       outputChatBox ("row: " ..mysql_num_rows(result)) 
    end 
    mysql_free_result(result) 
end 
addEventHandler("onPlayerConnect",getRootElement(),checkPlayer) 

Share this post


Link to post
No look:
triggerClientEvent("onRegister",getLocalPlayer()) 

You are triggering a client event and you need a player to handle that.

triggerClientEvent is server-side only and getLocalPlayer is client-side only.

Share this post


Link to post
Wel, you should debug it:
function checkPlayer(playerNick) 
    local result = mysql_query(handler,"SELECT * FROM users WHERE Name = '"..playerNick.."'") 
outputChatBox ( "Result: "..result ) 
    if( not result) then outputDebugString("MySQL Fail ("..mysql_errno(handler)..") Error:"..mysql_error(handler)) 
    end 
outputChatBox ("mysql_num_rows: " ..mysql_num_rows(result)) 
  
    if(mysql_num_rows(result) == 0) then 
        triggerClientEvent("onRegister",getRootElement()) 
        outputDebugString("Should be triggered") 
    else 
        row = mysql_fetch_row(result) 
       outputChatBox ("row: " ..mysql_num_rows(result)) 
    end 
    mysql_free_result(result) 
end 
addEventHandler("onPlayerConnect",getRootElement(),checkPlayer) 

It does output: "should be triggered"

Share this post


Link to post
triggerClientEvent(PlayerToSendInfoTo, "onRegister", root) 

Thats optional, is your meta.xml allright, have you tried changing the trigger name from onRegister to "login:onRegister"??

Share this post


Link to post

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.