Jump to content

[Help] triggerClientEvent() don't work, I guess


Kazafka

Recommended Posts

I guess here

addEventHandler("onPlayerChat", resourceRoot, function(message, type_)
	if(type_ == 0) then
		triggerClientEvent("dxDrawMessageText", getRootElement(), message)
		setTimer(
			function()
				triggerClientEvent("dxDrawMessageText", getRootElement(), "")
			end,
		10000, 1)
	end
end)

is the problem, with triggerClientEvent(), client:

addEvent("dxDrawMessageText", true)
addEventHandler("dxDrawMessageText", getLocalPlayer(), function(message)
	UNITED_MESSAGE = message
end)

addEventHandler("onClientRender", root, function()
	dxDrawTextOnElement(localPlayer, UNITED_MESSAGE, 1, 20, 255, 255, 255, 255, 1, "default-bold")
end)

So, I tried to outputChatBox() inside event handler of dxDrawMessageText, but it keept doing completely nothing. My code for outputChatBox():

--Code from event handler of dxDrawMessageText
	outputChatBox(UNITED_MESSAGE)
--Rest of code from event handler of dxDrawMessageText

BTW: dxDrawTextOnElement() exists. Any idea?

Edited by VaporZ
Link to comment
  • Moderators

triggerClientEvent("dxDrawMessageText", getRootElement(), message)

triggerClientEvent("dxDrawMessageText", getRootElement(), "")

 

addEventHandler("dxDrawMessageText", getLocalPlayer(), function(message)

 

triggerClientEvent("dxDrawMessageText", resourceRoot, message)

triggerClientEvent("dxDrawMessageText", resourceRoot, "")

 

 

addEventHandler("dxDrawMessageText", resourceRoot, function(message)

 

 

If you do not understand how the event system works, then you can better replace the baseElement of the triggerclient/serverEvent + addEventHandler with resourceRoot until you have studied that.

 

Documentation:

https://wiki.multitheftauto.com/wiki/AddEvent

https://wiki.multitheftauto.com/wiki/Event_system

https://wiki.multitheftauto.com/wiki/AddEventHandler

https://wiki.multitheftauto.com/wiki/Element_tree

https://wiki.multitheftauto.com/wiki/Event_Source_Element

 

Edited by IIYAMA
  • Like 1
Link to comment
6 minutes ago, IIYAMA said:

triggerClientEvent("dxDrawMessageText", getRootElement(), message)

triggerClientEvent("dxDrawMessageText", getRootElement(), "")

 

addEventHandler("dxDrawMessageText", getLocalPlayer(), function(message)

I've seen that in tutorial of triggerClientEvent() on MTA Wiki, but OK xD 

BTW: Still nothing :| 

Edited by VaporZ
Link to comment
  • Moderators
Just now, VaporZ said:

What can u guys say to this :/ ?

You didn't update the code, so I can't say anything.

 

That tutorial is using different sourceElement, baseElement and sendTo elements. Nothing like your code.

  • Like 1
Link to comment
Just now, IIYAMA said:

You didn't update the code, so I can't say anything.

Server-side:

addEventHandler("onPlayerChat", resourceRoot, function(message, type_)
	if(type_ == 0) then
		triggerClientEvent("messageText", resourceRoot, message)
		setTimer(
			function()
				triggerClientEvent("messageText", resourceRoot, "")
			end,
		10000, 1)
	end
end)

Client-side:

addEvent("messageText", true)
addEventHandler("messageText", resourceRoot, function(message)
	UNITED_MESSAGE = message
end)

addEventHandler("onClientRender", root, function()
	dxDrawTextOnElement(localPlayer, UNITED_MESSAGE, 1, 20, 255, 255, 255, 255, 1, "default-bold")
end)

 

Link to comment
  • Moderators
3 minutes ago, VaporZ said:

Server-side:


addEventHandler("onPlayerChat", resourceRoot, function(message, type_)
	if(type_ == 0) then
		triggerClientEvent("messageText", resourceRoot, message)
		setTimer(
			function()
				triggerClientEvent("messageText", resourceRoot, "")
			end,
		10000, 1)
	end
end)

Client-side:


addEvent("messageText", true)
addEventHandler("messageText", resourceRoot, function(message)
	UNITED_MESSAGE = message
end)

addEventHandler("onClientRender", root, function()
	dxDrawTextOnElement(localPlayer, UNITED_MESSAGE, 1, 20, 255, 255, 255, 255, 1, "default-bold")
end)

 

Where are your debuglines? There are absolutely 0 of them in your code.

Edited by IIYAMA
  • Like 1
Link to comment
  • Moderators
5 minutes ago, VaporZ said:

Server-side:


addEventHandler("onPlayerChat", resourceRoot, function(message, type_)
	if(type_ == 0) then
		triggerClientEvent("messageText", resourceRoot, message)
		setTimer(
			function()
				triggerClientEvent("messageText", resourceRoot, "")
			end,
		10000, 1)
	end
end)

Client-side:


addEvent("messageText", true)
addEventHandler("messageText", resourceRoot, function(message)
	UNITED_MESSAGE = message
end)

addEventHandler("onClientRender", root, function()
	dxDrawTextOnElement(localPlayer, UNITED_MESSAGE, 1, 20, 255, 255, 255, 255, 1, "default-bold")
end)

 

You attached the onPlayerChat event to resourceRoot.

A resource can't use chat (like a player ?). You need to change it to root, what contains players. (https://wiki.multitheftauto.com/wiki/Element_tree)

Edited by stPatrick
  • Thanks 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...