Jump to content

How to create a DX label and set a variable to ?


drk

Recommended Posts

Hi guys ! I am creating a resource that when a player joins set the text in DX label with 'BLABLABLA has joined the Server !'. But I don't know how to set a variable to the DX label and how to set the text on the label when a player joins. Can anyone help me ?

Link to comment

You mean you use ... ?

outputChatBox 

Then take this as example, if the value you are trying to use is a NUMBER:

outputChatBox ( "Some message is number "..tostring ( 5 ).. " and works fine" ) 

But if it is a STRING, just use:

outputChatBox ( "Some message is number "..value.. " and works fine" ) 

If you don't use outputChatBox... Anyway the example will work but applied to dxDrawText.

Link to comment

By 'dx label ' you mean dxDrawText? If so, then:

local textVar = "BlaBlaBlah" 
  
addEventHandler( "onClientRender", root, function() 
  dxDrawText( textVar, sx, sy, sx, sy ) 
end ) 
  
addEventHandler( "onClientPlayerJoin", root, function() 
  textVar = getPlayerName( source ).." has joined the game!" 
end ) 

Link to comment

And how to set a Timer to hide the Text ( no the label ) ?

I've tried but don't work ;S The code:

  
--[[--------------------------------- 
--client/server script 
--@author iMortal 
--@description server side main script 
---------------------------------]]-- 
  
local textJoin = " " 
local textQuit = " " 
  
addEventHandler("onClientRender",root, 
  
    function() 
  
        dxDrawText( textQuit, 959.0, 246.0, 1227.0, 264.0, tocolor(0,0,0,255), 0.6, "bankgothic", "left", "top", false, false, false ) 
  
        dxDrawText( textQuit, 956.0, 243.0, 1224.0, 261.0, tocolor(255,0,0,255), 0.6, "bankgothic", "left", "top", false, false, false ) 
  
        dxDrawText( textJoin,943.0,217.0,1211.0,235.0,tocolor(0,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
  
        dxDrawText( textJoin,939.0,213.0,1207.0,231.0,tocolor(0,255,0,255),0.6,"bankgothic","left","top",false,false,false) 
  
    end 
  
) 
  
addEventHandler( "onClientPlayerJoin", root, 
 function() 
    textJoin = getPlayerName( source ).." entrou no Servidor !" 
    setTimer ( 
        function () 
            local textJoin = " " 
        end, 9000, 1 ) 
end 
) 
  
  

Link to comment
addEventHandler( "onClientPlayerJoin", root, 
 function() 
    textJoin = getPlayerName( source ).." entrou no Servidor !" 
    setTimer ( 
        function () 
            textJoin = "" 
        end, 9000, 1 ) 
end 
) 

Edited by Guest
Link to comment

Thanks very much Solidskane14 and DakiLLa ! It worked perfectly !

EDIT: When a player quit the server don't appear '-' the code:

addEventHandler( "onClientPlayerQuit", root, 
 function() 
    textQuit = getPlayerName( source ).." saiu do Servidor !" 
    setTimer ( 
        function () 
            textQuit = "" 
        end, 7000, 1 ) 
end 
) 

Link to comment
addEventHandler( "onClientPlayerQuit", root, 
 function() 
    textJoin = getPlayerName( source ).." saiu do Servidor !" 
    setTimer ( 
        function () 
            textJoin = "" 
        end, 7000, 1 ) 
end 
) 

That should work, but I don't know is that is what you want.

Link to comment

You can do that easily!

Client:

text = "" 
  
function drawMyText ( ) 
    dxDrawText ( arguments..., text, ...arguments ) --You add the position, size, font, scale, etc arguments! 
end  
  
function createDXText ( t, timeToDestroy ) 
    text = t 
    addEventHandler ( "onClientRender", getRootElement ( ), drawMyText ) 
    setTimer ( removeEventHandler, timeToDestroy, 1, "onClientRender", getRootElement ( ), drawMyText ) 
end 
  
addEvent ( "onDXText", true ) 
addEventHandler ( "onDXText", getRootElement ( ), 
function ( thetext ) 
    create3DText ( thetext, someTime ) 
end ) 
  

Server

addEventHandler ( "onPlayerQuit", getRootElement ( ), 
function ( ) 
    triggerClientEvent ( getRootElement ( ), "onDXText", source, getPlayerName ( source ).." has left the server!" ) 
end ) 

And it should work!

But there will be some issues if more than 1 player leaves o.O

I suggest you to make it easier and just use outputChatBox.

May be too mainstream and simple but is easier and probably will take you out more than 1 headache.

Edited by Guest
Link to comment
Why you need to trigger from server side? using onClientPlayerJoin, onClientPlayerQuit should work.

Lol right. I think in the moment I had a reason to use the server side, now I don't remember it.

Okay iMortal. If you need more help, just ask ;)

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