Jump to content

Cross GUI


shaio

Recommended Posts

1 hour ago, pa3ck said:

GUI Event -> triggerServerEvent -> triggerClientEvent

OR

setElementData with onClientElementDataChange

Could you make a simple script as an example? Like make 1 gui with a button and then when u click the button make it open a gui window on someone elses screen?

Link to comment

Now I know this is going from client to server to client. If you're doing it just by command you can do it straight from the server. 

But since you want to do it through a gui, this is an example of how you could do it:

Client-side:

addCommandHandler("msg",
	function(_,playerName,...)
		if not playerName then
			outputChatBox("No player name given")
			return
		end
		
		if #arg == 0 then
			outputChatBox("No message given")
			return
		end
		
		local player = getPlayerFromName(playerName)
		
		if player then
			local message = table.concat(arg," ")
			
			triggerServerEvent("printMsg",localPlayer,player,message)
		end
	end
,false,false)

addEvent("onMsg",true)
addEventHandler("onMsg",root,
	function(msg)
		sender = getPlayerName(source)
		message = msg
		
		if isTimer(receiveTimer) then
			resetTimer(receiveTimer)
		else
			addEventHandler("onClientRender",root,drawMessage)
			
			receiveTimer = setTimer(function()
				removeEventHandler("onClientRender",root,drawMessage)
				sender,message = nil,nil
			end,5000,1)
		end
	end
)

function drawMessage()
	dxDrawText("A message from "..sender..":", 15, 324, 279, 360, tocolor(255, 255, 255, 255), 1.50, "default", "left", "top", false, false, false, false, false)
	dxDrawText(message, 15, 368, 279, 529, tocolor(45, 203, 78, 255), 1.50, "default", "left", "top", false, true, false, false, false)
end

Server-side:

addEvent("printMsg",true)
addEventHandler("printMsg",root,
	function(player,message)
		triggerClientEvent(player,"onMsg",source,message)
	end
)

 

Edited by Savannah
Link to comment

SORRY EDIT in other post (/msg already exists) and added player check

addCommandHandler("message",
	function(_,playerName,...)
		if not playerName then
			outputChatBox("No player name given")
			return
		end
		
		if #arg == 0 then
			outputChatBox("No message given")
			return
		end
		
		local player = getPlayerFromName(playerName)
		
		if not player then
			outputChatBox("Player not found")
		else
			local message = table.concat(arg," ")
			
			triggerServerEvent("printMsg",localPlayer,player,message)
		end
	end
,false,false)

Also,

GUIeditor example:

showCursor(true)

function printMsg(playerName,message)
	if playerName:len() == 0 then
		outputChatBox("No player name given")
		return
	end
	
	if message:len() == 0 then
		outputChatBox("No message given")
		return
	end
	
	local player = getPlayerFromName(playerName)
	
	if player then			
		triggerServerEvent("printMsg",localPlayer,player,message)
	end
end

GUIEditor = {
    button = {},
    label = {},
    edit = {}
}
addEventHandler("onClientResourceStart", resourceRoot,
    function()
        GUIEditor.button[1] = guiCreateButton(399, 484, 101, 48, "Send", false)


        GUIEditor.label[1] = guiCreateLabel(315, 384, 75, 32, "player name:", false)
        guiLabelSetHorizontalAlign(GUIEditor.label[1], "right", false)
        guiLabelSetVerticalAlign(GUIEditor.label[1], "center")


        GUIEditor.label[2] = guiCreateLabel(315, 434, 75, 32, "message:", false)
        guiLabelSetHorizontalAlign(GUIEditor.label[2], "right", false)
        guiLabelSetVerticalAlign(GUIEditor.label[2], "center")


        GUIEditor.edit[1] = guiCreateEdit(405, 381, 135, 35, "", false)


        GUIEditor.edit[2] = guiCreateEdit(405, 431, 340, 35, "aa", false)    
    end
)

addEventHandler("onClientGUIClick", resourceRoot,
	function()
		if source == GUIEditor.button[1] then
			printMsg(guiGetText(GUIEditor.edit[1]),guiGetText(GUIEditor.edit[2]))
		end
	end
)

 

Edited by Savannah
Link to comment
1 hour ago, Savannah said:

SORRY EDIT in other post (/msg already exists) and added player check


addCommandHandler("message",
	function(_,playerName,...)
		if not playerName then
			outputChatBox("No player name given")
			return
		end
		
		if #arg == 0 then
			outputChatBox("No message given")
			return
		end
		
		local player = getPlayerFromName(playerName)
		
		if not player then
			outputChatBox("Player not found")
		else
			local message = table.concat(arg," ")
			
			triggerServerEvent("printMsg",localPlayer,player,message)
		end
	end
,false,false)

Also,

GUIeditor example:


showCursor(true)

function printMsg(playerName,message)
	if playerName:len() == 0 then
		outputChatBox("No player name given")
		return
	end
	
	if message:len() == 0 then
		outputChatBox("No message given")
		return
	end
	
	local player = getPlayerFromName(playerName)
	
	if player then			
		triggerServerEvent("printMsg",localPlayer,player,message)
	end
end

GUIEditor = {
    button = {},
    label = {},
    edit = {}
}
addEventHandler("onClientResourceStart", resourceRoot,
    function()
        GUIEditor.button[1] = guiCreateButton(399, 484, 101, 48, "Send", false)


        GUIEditor.label[1] = guiCreateLabel(315, 384, 75, 32, "player name:", false)
        guiLabelSetHorizontalAlign(GUIEditor.label[1], "right", false)
        guiLabelSetVerticalAlign(GUIEditor.label[1], "center")


        GUIEditor.label[2] = guiCreateLabel(315, 434, 75, 32, "message:", false)
        guiLabelSetHorizontalAlign(GUIEditor.label[2], "right", false)
        guiLabelSetVerticalAlign(GUIEditor.label[2], "center")


        GUIEditor.edit[1] = guiCreateEdit(405, 381, 135, 35, "", false)


        GUIEditor.edit[2] = guiCreateEdit(405, 431, 340, 35, "aa", false)    
    end
)

addEventHandler("onClientGUIClick", resourceRoot,
	function()
		if source == GUIEditor.button[1] then
			printMsg(guiGetText(GUIEditor.edit[1]),guiGetText(GUIEditor.edit[2]))
		end
	end
)

 

I want to know how to have a button on one client that when clicked will create a WINDOW in another client. Trigger event is suppose to do that since it allows you to set the element the event is triggered for, but it's not working. I need more help with this.

Link to comment
16 hours ago, iPrestege said:

Show us the part where you use 'triggerClientEvent' In you have to use root to send it for all clients.

so instead of specifying player at the start, trigger the event with the element as root and then verify the player with if root == player then?

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