Jump to content

Function not called


Xabi

Recommended Posts

Hi all, I have a problem triggering a client event from server, resulting that the cient's function never got called, it doesn't throw any error, just stops calling client's function. Any help will be appreciated, so thanks in advance.

Server:

function checkPlayerExists(queryHandle) 
    local result = dbPoll(queryHandle, 0) 
    if(#result == 0)then 
        triggerClientEvent(player, "onPlayerNotRegistered", player) 
    else 
         ... more code here ... 
end 

Client:

function createRegisterWindow() 
    background = guiCreateStaticImage(0.0, 0.0, 1.0, 1.0, "images/background.png", true) 
    registerWindow = guiCreateWindow(0.25, 0.25, 0.5, 0.5, "Registrar nuevo personaje", true)    
    guiSetVisible(registerWindow, false) 
    guiSetVisible(background, false) 
end 
  
function showRegisterWindow() 
    if(registerWindow ~= nil)then 
        guiSetVisible(background, true) 
        guiSetVisible(registerWindow, true) 
        showCursor(true) 
        guiSetInputEnabled(false) 
    else 
        outputChatBox("Ha habido un error al crear la ventana de registro.") 
    end 
end 
  
addEvent("onPlayerNotRegistered", true) 
addEventHandler("onPlayerNotRegistered", localPlayer, showRegisterWindow) 
addEventHandler("onClientResourceStart", root, createRegisterWindow) 

Link to comment

It's previously defined as a global

function checkSerialStatus(playerNick, playerIP, playerUsername, playerSerial) 
    dbHandle = exports.sql:getDatabaseHandle() 
    player = getPlayerFromName(playerNick) 
    dbQuery(getSerialStatus, dbHandle, "SELECT `date` FROM `bans` WHERE `serial` = ? LIMIT 1", playerSerial) 
end 
addEventHandler("onPlayerConnect", getRootElement(), checkSerialStatus) 

Link to comment

---ClientSide,

function createRegisterWindow() 
    background = guiCreateStaticImage(0.0, 0.0, 1.0, 1.0, "images/background.png", true) 
    registerWindow = guiCreateWindow(0.25, 0.25, 0.5, 0.5, "Registrar nuevo personaje", true)    
    guiSetVisible(registerWindow, false) 
    guiSetVisible(background, false) 
end 
  
addEvent('onPlayerNotRegistered' ,true ) 
addEventHandler('onPlayerNotRegistered', root,  
function ( ) 
if guiGetVisible(registerWindow) == false then 
        guiSetVisible(registerWindow,true) 
        guiSetVisible(background, true) 
        showCursor(true) 
        guiSetInputEnabled(true) 
    else 
    guiSetVisible(registerWindow,false) 
    guiSetVisible(background, false) 
    showCursor(false) 
    guiSetInputEnabled(false) 
  end 
end 
) 

---ServerSide ,

function checkPlayerExists(queryHandle) 
    local result = dbPoll(queryHandle, 0) 
    if(#result == 0)then 
    triggerClientEvent(source, "onPlayerNotRegistered", source) 
    else 
    ---- ... more code here ... 
end 
end 
Link to comment
u need put element

function checkPlayerExists(element, queryHandle) 
    local result = dbPoll(queryHandle, 0) 
    if(#result == 0)then 
        triggerClientEvent(element, "onPlayerNotRegistered", element ) 
    else 
         --- ... more code here ... 
end 

i dont think so ,

Required Arguments

queryHandle: A query handle previously returned from dbQuery

timeout: How many milliseconds to wait for a result. Use 0 for an instant response (which may return nil). Use -1 to wait until a result is ready. Note: A wait here will freeze the entire server just like the executeSQL* functions

Link to comment
---ClientSide,

function createRegisterWindow() 
    background = guiCreateStaticImage(0.0, 0.0, 1.0, 1.0, "images/background.png", true) 
    registerWindow = guiCreateWindow(0.25, 0.25, 0.5, 0.5, "Registrar nuevo personaje", true)    
    guiSetVisible(registerWindow, false) 
    guiSetVisible(background, false) 
end 
  
addEvent('onPlayerNotRegistered' ,true ) 
addEventHandler('onPlayerNotRegistered', root,  
function ( ) 
if guiGetVisible(registerWindow) == false then 
        guiSetVisible(registerWindow,true) 
        guiSetVisible(background, true) 
        showCursor(true) 
        guiSetInputEnabled(true) 
    else 
    guiSetVisible(registerWindow,false) 
    guiSetVisible(background, false) 
    showCursor(false) 
    guiSetInputEnabled(false) 
  end 
end 
) 

---ServerSide ,

function checkPlayerExists(queryHandle) 
    local result = dbPoll(queryHandle, 0) 
    if(#result == 0)then 
    triggerClientEvent(source, "onPlayerNotRegistered", source) 
    else 
    ---- ... more code here ... 
end 
end 

If I use source instead of player it gives me an exception saying nil value.

Link to comment

Ok , then Try this one ,

function checkPlayerExists(player, queryHandle) 
    local result = dbPoll(queryHandle, 0) 
    if(#result == 0)then 
    triggerClientEvent(player, "onPlayerNotRegistered", player) 
    else 
    ---- ... more code here ... 
end 
end 
Link to comment

Still the same, the problem is in the clientside with the showRegisterWindow() function, even if I only write and outputChatBox or a print there, it doesn't show anything. But when I do an if with the triggerClientEvent, it returns true, so it's executing the triggerClientEvent but not showRegisterWindow().

Link to comment
That's Strange , it should show the rigsterwindow , i think the error with the serverside the SQL Codes,

Making a debug, it gets into the triggerClientEvent part, so I don't think so. I mean, testing all the SQL cases it works, only fails when executing that triggered event.

Link to comment

triggerClientEvent will return true even if the event is not added client-side I think. Your issue may be in the resource's meta.xml. Make sure the client file has the type attribute set to "client". Also,

The event handler that calls createRegisterWindow is attached to root, when it should be attached to resourceRoot. Attaching it to root will cause the event to be triggered when ANY resource is started, not just this one.

So like this:

addEventHandler("onClientResourceStart", resourceRoot, createRegisterWindow) 

For future cases, put an outputChatBox in the function called by an event triggered from the server instead of checking if triggerClientEvent returned true or not.

Link to comment
triggerClientEvent will return true even if the event is not added client-side I think. Your issue may be in the resource's meta.xml. Make sure the client file has the type attribute set to "client". Also,

The event handler that calls createRegisterWindow is attached to root, when it should be attached to resourceRoot. Attaching it to root will cause the event to be triggered when ANY resource is started, not just this one.

So like this:

addEventHandler("onClientResourceStart", resourceRoot, createRegisterWindow) 

For future cases, put an outputChatBox in the function called by an event triggered from the server instead of checking if triggerClientEvent returned true or not.

Yes, I changed that part of resourceRoot.

The meta.xml file is correct, as createRegisterWindow() function is working perfectly, the problem comes when executing that showRegisterWindow(). Even if I put just an outputChatBox inside of it, doesn't print anything.

Link to comment

Max, you're making many mistakes, don't help him if you're not good enough.

He's making a SQL based account system.

checkPlayerExists was saying nil value because you weren't passing a player element to it, search where you used it in your code and try to fix it.

isGuestAccount will always return true as you're making a SQL based account system.

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