Jump to content

dxDrawText Display


OGF

Recommended Posts

Posted
  
--client 
local sWidth,sHeight = guiGetScreenSize() 
function motdis () 
    local motdt = guiGetText ( motdtxtbox ) 
        triggerServerEvent ( "getdx", root, motdt ) 
end 
addEventHandler ( "onClientGUIClick", motdbut, motdis, false ) 
  
--server 
function getdxtxt ( motdt ) 
        if not ( motd == "" ) then 
            for id, player in ipairs ( getElementsByType ( "player" ) ) do 
                triggerClientEvent ( "rendertxt", player, motdt ) 
            end 
        end 
end 
addEvent ("getdx",true) 
addEventHandler("getdx", resourceRoot, getdxtxt) 
  
  
  
--client 
function rendertxt (motdt) 
local sWidth,sHeight = guiGetScreenSize() 
    texts = dxDrawText( motdt, sWidth * 0.456, sHeight * 0.051, sWidth * 0, sHeight * 0,tocolor(255,255,255,195),1.0,"bankgothic","left","top",false,false,false,true)   
    addEventHandler ( "onClientRender", root, rendertxt ) 
end 
addEvent("rendertxt",true) 
addEventHandler("rendertxt", root, rendertxt ) 
  
  

Its kind of like a message of the day thing, so it always stays at the top of players screens.

I have tried lots of things now, the problem is, the text actully displays once, but after that, the debugscript spams saying that the first argument in dxDrawText is nil. Im not sure what to do no more.

Posted (edited)
--client 
function rendertxt (motdt) 
local sWidth,sHeight = guiGetScreenSize() 
    addEventHandler('onClientPlayerJoin', getRootElement(), 
    function() 
    addEventHandler('onClientRender', root, 
    function() 
    texts = dxDrawText( motdt, sWidth * 0.456, sHeight * 0.051, sWidth * 0, sHeight * 0,tocolor(255,255,255,195),1.0,"bankgothic","left","top",false,false,false,true)   
     end 
     ) 
     end 
     ) 
addCommandHandler('remove', 
function() 
removeEventHandler('onClientRender', root, rendertxt) 
end 
) 
end 
addEvent("rendertxt",true) 
addEventHandler("rendertxt", root, rendertxt ) 

try this.

Edited by Guest
Posted

Wow works good, Forgot about nesting functions with events. Was wondering how I can remove this eventHandler from another function, because if I keep adding text, they overlap. thanks

Posted

When I try that code it displays nothing, plus no error or nothing, the remove command doesnt seem to work either.

Posted

-- client side:

local sWidth, sHeight = guiGetScreenSize ( ) 
  
function motdis ( ) 
    local motdt = guiGetText ( motdtxtbox ) 
    triggerServerEvent ( "getdx", localPlayer, motdt ) 
end 
addEventHandler ( "onClientGUIClick", motdbut, motdis, false ) 
  
local motd = "" 
  
function rendertxt ( ) 
    dxDrawText ( motd, sWidth * 0.456, sHeight * 0.051, sWidth * 0, sHeight * 0, tocolor ( 255, 255, 255, 195 ), 1.0, "bankgothic", "left", "top", false, false, false, true ) 
end 
  
addEvent ( "rendertxt", true ) 
addEventHandler ( "rendertxt", root, 
    function ( motdt ) 
        removeEventHandler ( "onClientRender", root, rendertxt ) 
        motd = motdt 
        addEventHandler ( "onClientRender", root, rendertxt ) 
    end 
) 

-- server side:

function getdxtxt ( motdt ) 
    if ( not motd ~= "" ) then 
        for _, player in ipairs ( getElementsByType ( "player" ) ) do 
            triggerClientEvent ( player, "rendertxt", player, motdt ) 
        end 
    end 
end 
addEvent ( "getdx", true ) 
addEventHandler ( "getdx", root, getdxtxt ) 

Should work.

Posted

ah ok works good now thanks, the one other thing i cant get is if a new player joins or someone reconnects the text will disappear to them. also if the player who displayed the message leaves, then the message will disappear for everyone on the server, I know its onClientPlayerJoin, do I maybe need to make an invisible edit and set text to that server sided? so when someone joins , get that text?

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