Jump to content

Problem with TriggerClientEvent


syn0nym

Recommended Posts

Okay, so i created a gui function in client side, then i want to trigger it using triggerClientEvent in the server side, but when the code run there a some problem. 

Client

GUIEditor = {
	window = {},
	label = {},
	edit = {},
	button = {},
}

function centerWindow (center_window)
    local screenW, screenH = guiGetScreenSize()
    local windowW, windowH = guiGetSize(center_window, false)
    local x, y = (screenW - windowW) /2,(screenH - windowH) /2
    return guiSetPosition(center_window, x, y, false)
end

GUIEditor.window[1] = guiCreateWindow (0, 0, 300, 400, "Test", false)
centerWindow (GUIEditor.window[1])
guiSetVisible (GUIEditor.window[1], false)
GUIEditor.label[1] = guiCreateLabel (20, 50, 100, 70, "Test", false,  GUIEditor.window[1])
GUIEditor.edit[1] = guiCreateEdit (20, 90, 200, 30, "", false, GUIEditor.window[1])
GUIEditor.button[1] = guiCreateButton (20, 150, 150, 40, "Button", false, GUIEditor.window[1])


function openGUI (bool)
	if (bool == true) then
		guiSetVisible (GUIEditor.window[1], true)
		showCursor (true)
	end
end

addEvent ("showGUI", true)
addEventHandler ("showGUI", root, openGUI)

 

Server

function playerJoin ()
    triggerClientEvent (source, "showGUI", source, true)
end

addEventHandler ("onPlayerJoin", root, playerJoin)

 

Edited by syn0nym
revision
Link to comment

When the onPlayerJoin event is triggered, the client-side file may not be loaded yet. You can solve this on the client-side with the "onClientResourceStart" event, so the panel will open when the files are loaded.

GUIEditor = {
        window = {},
        label = {},
        edit = {},
        button = {},
}

function centerWindow (center_window)
    local screenW, screenH = guiGetScreenSize()
    local windowW, windowH = guiGetSize(center_window, false)
    local x, y = (screenW - windowW) /2,(screenH - windowH) /2
    return guiSetPosition(center_window, x, y, false)
end

GUIEditor.window[1] = guiCreateWindow (0, 0, 300, 400, "Test", false)
centerWindow (GUIEditor.window[1])
guiSetVisible (GUIEditor.window[1], false)
GUIEditor.label[1] = guiCreateLabel (20, 50, 100, 70, "Test", false,  GUIEditor.window[1])
GUIEditor.edit[1] = guiCreateEdit (20, 90, 200, 30, "", false, GUIEditor.window[1])
GUIEditor.button[1] = guiCreateButton (20, 150, 150, 40, "Button", false, GUIEditor.window[1])


function openGUI(bool)
   if (bool == true) then
      guiSetVisible(GUIEditor.window[1], true)
      showCursor(true)
   end
end

addEvent ("showGUI", true)
addEventHandler ("showGUI", root, openGUI)

addEventHandler("onClientResourceStart", resourceRoot,
        function()
           openGUI(true) --open panel when client side files are loaded
        end
)

 

  • Thanks 1
  • Haha 1
Link to comment
6 hours ago, Burak5312 said:

When the onPlayerJoin event is triggered, the client-side file may not be loaded yet. You can solve this on the client-side with the "onClientResourceStart" event, so the panel will open when the files are loaded.

GUIEditor = {
        window = {},
        label = {},
        edit = {},
        button = {},
}

function centerWindow (center_window)
    local screenW, screenH = guiGetScreenSize()
    local windowW, windowH = guiGetSize(center_window, false)
    local x, y = (screenW - windowW) /2,(screenH - windowH) /2
    return guiSetPosition(center_window, x, y, false)
end

GUIEditor.window[1] = guiCreateWindow (0, 0, 300, 400, "Test", false)
centerWindow (GUIEditor.window[1])
guiSetVisible (GUIEditor.window[1], false)
GUIEditor.label[1] = guiCreateLabel (20, 50, 100, 70, "Test", false,  GUIEditor.window[1])
GUIEditor.edit[1] = guiCreateEdit (20, 90, 200, 30, "", false, GUIEditor.window[1])
GUIEditor.button[1] = guiCreateButton (20, 150, 150, 40, "Button", false, GUIEditor.window[1])


function openGUI(bool)
   if (bool == true) then
      guiSetVisible(GUIEditor.window[1], true)
      showCursor(true)
   end
end

addEvent ("showGUI", true)
addEventHandler ("showGUI", root, openGUI)

addEventHandler("onClientResourceStart", resourceRoot,
        function()
           openGUI(true) --open panel when client side files are loaded
        end
)

 

Thank you for helping,  it's working

  • Like 1
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...