Jump to content

If chat imput active, dxDrawTextOnElement?


TrickyTommy

Recommended Posts

Hi!
I am making a script, that writes above your head that you are typing if you do so. The only problem is, it does barely work, and strangely.
When i escape from input, it won't disappear.
What i have done so far:
Client:

function recieveConsoleImput(client)
	function render()
		--if client ~= localPlayer then
			dxDrawTextOnElement (client, "l'écriture... / Writing... / Ír...", _, _, _, _, _, _, 2)
		--end
		removeEventHandler ("onClientRender", getRootElement(), render)
	end
	addEventHandler ("onClientRender", getRootElement(), render)
end
addEvent ("recieveConsoleImput", true)
addEventHandler ("recieveConsoleImput", getRootElement(), recieveConsoleImput)

function checkConsoleImput()
	if isChatBoxInputActive(localPlayer) then
		triggerServerEvent ("forwardConsoleImput", getRootElement(), localPlayer)
	end
end
addEventHandler ("onClientRender", getRootElement(), checkConsoleImput)

Server:
 

function forwardConsoleImput(client)
	triggerClientEvent ("recieveConsoleImput", getRootElement(), client)
end
addEvent ("forwardConsoleImput", true)
addEventHandler ("forwardConsoleImput", getRootElement(), forwardConsoleImput)

heyyy whats wrong? :(

Link to comment

In the client code you have made it so the render function will only run for one frame only simply because you removed the event immediately after. You need a way to make the render function end when the player stops typing. Also, I would not advise that you use the same name for your event as your function as this can cause confusion.

Edited by Pembo
Link to comment

I have not taken a look at your code but a very simple way to do this trick is by that;

addEventHandler("onClientRender",root,function()
    if getElementData(localPlayer,"typing") == true then
      -- dxDraw.....
      -- anything else you want
    end
end)
-- now this way the image (if you are using image) or the text will be only showing when the player has the 'typing' data, otherwise nothing would be shown.

-- all you have to do is to detect whenever a player is typing and whenever he is not and change his data according to that.

 

Link to comment
On 2017. 08. 19. at 23:44, SuperCroz said:

I have not taken a look at your code but a very simple way to do this trick is by that;


addEventHandler("onClientRender",root,function()
    if getElementData(localPlayer,"typing") == true then
      -- dxDraw.....
      -- anything else you want
    end
end)
-- now this way the image (if you are using image) or the text will be only showing when the player has the 'typing' data, otherwise nothing would be shown.

-- all you have to do is to detect whenever a player is typing and whenever he is not and change his data according to that.

 

Hi! I want other players to see each other's writing sign.

Link to comment
  • Administrators

So drawing upon @SuperCroz's idea, it'd be pretty simple.

addEventHandler("onClientRender",root,function()
    for i,player in pairs(getElementsByType("player")) do
      if getElementData(player,"typing") == true then
        if not getElementData(player,"showtyping") then
          setElementData(player,"showtyping",true,true)
        end
        --here is your dxDrawImage3D chat bubble or such 
      else
        if getElementData(player,"showtyping") then
          setElementData(player,"showtyping",false,true)
        end        
      end
    end
end)

Well, I think that'd work. I don't use element data too often :D

Edited by LopSided_
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...