Jump to content

triggerClientEvent


Bebras

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?

Link to comment
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

Link to comment

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) 

Link to comment
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"
Link to comment

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...