ViRuZGamiing Posted January 29, 2016 Posted January 29, 2016 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 "If debugging is the process of removing software bugs, then programming must be the process of putting them in."
tosfera Posted January 29, 2016 Posted January 29, 2016 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 * ( ... If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]
ViRuZGamiing Posted January 29, 2016 Author Posted January 29, 2016 Nope, did not change anything. Still on the same position. Did use the lineCount. "If debugging is the process of removing software bugs, then programming must be the process of putting them in."
tosfera Posted January 29, 2016 Posted January 29, 2016 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. If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]
ViRuZGamiing Posted January 29, 2016 Author Posted January 29, 2016 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 "If debugging is the process of removing software bugs, then programming must be the process of putting them in."
NewbProgramming Posted January 29, 2016 Posted January 29, 2016 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 You can Private Message me and I will help you with Lua questions. 10 / 10 Lua scripter. 8 / 10 MTA scripter. 10 / 10 C++ embedded Lua.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now