Jump to content

onClientRender dxDraw


ViRuZGamiing

Recommended Posts

I have this piece of code in a onClientRender function but all my message are in 1 position.

I've tried experimenting to get the 2nd one underneath it but then it just falls off my screen. (the Dx moves to the bottom)

How can I make it so that my 2nd message (and next ones) are all below the previous one.

for i, message in pairs(messages) do 
        dxDrawText(message, 940, minHeight, 1230, (minHeight+(msgHeight*15)), tocolor(255, 255, 255, 255), 0.60, "bankgothic", "left", "top", true, true, false, false, false) 
end 

Link to comment

That's quite easy, use a counter variable that keeps track of the index ( I don't really trust the index variable in the pairs itself. ) like so;

local lineCount = 0; 
for i, message in pairs(messages) do 
    dxDrawText(message, 940, minHeight, 1230, (minHeight+(msgHeight*15)) + ( lineCount * ( msgHeight * msgHeight ) ), tocolor(255, 255, 255, 255), 0.60, "bankgothic", "left", "top", true, true, false, false, false) 
    lineCount = lineCount + 1; 
end 

If you do however trust the "i" variable, you can just change the lineCount * ( ... to i * ( ...

Link to comment

What is minHeight and msgHeight?

edit; I did make a small typo in the calculations, try something like this;

local lineCount = 0; 
for i, message in pairs(messages) do 
    dxDrawText ( message, 940, minHeight, 1230, ( minHeight + ( msgHeight * dxGetFontHeight ( 1 ) ) + ( lineCount * ( msgHeight * dxGetFontHeight ( 1 ) ) ), tocolor(255, 255, 255, 255), 0.60, "bankgothic", "left", "top", true, true, false, false, false) 
    lineCount = lineCount + 1; 
end 

Make sure that you change the dxGetFontHeight to the right size, might even replace that with 15 again if you like. :lol:

Link to comment

minHeight is the minimum top position that can be used so it's the first top position.

msgHeight is this;

msgHeight = math.ceil(string.len(message)/22) 

Since my chat has a max of 22 Characters horizontal I calculate what my bottom position needs to be depending on how many lines I use (example; 48 characters, 48/22 = 2.18... => ceil = 3) then I multiple the value to the height of 1 line which is 15 different from my minheight

Link to comment
local index = 0; 
local line_spacing = 10.0; 
  
for i, message in pairs(messages) do 
    dxDrawText(message, 940, (minHeight + (index * line_spacing)), 1230, ((minHeight + (index * line_spacing)) +(msgHeight*15)), tocolor(255, 255, 255, 255), 0.60, "bankgothic", "left", "top", true, true, false, false, false) 
     
    index = index + 1; 
end 

If messages is a table with indexes auto assigned you can:

local line_spacing = 10.0; 
  
for i, message in ipairs(messages) do 
    dxDrawText(message, 940, (minHeight + ((i - 1) * line_spacing)), 1230, (minHeight + ((i - 1) * line_spacing) +(msgHeight*15)), tocolor(255, 255, 255, 255), 0.60, "bankgothic", "left", "top", true, true, false, false, false) 
end 

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