Jump to content

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


drk

Recommended Posts

Posted

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 ?

Posted

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.

Posted

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 ) 

Posted

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 
) 
  
  

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

Edited by Guest
Posted

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 
) 

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

Posted

don't just set text to zero, but remove the onClientRender event handler.

it is extremely inefficent when it comes to leaving dx drawing when its not needed.

Posted (edited)

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
Posted

I don't know but I hate the chat box ahahah' I want to create in DX. And thanks for all that have tried to help. I've solved the problem. Easy :D

Sorry for my FUCK english ;)

Posted
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 ;)

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