Scrolling Text

Can anybody help me with a code to make text scroll from the right to the left of your screen?


function centerText()
surface.SetTextColor( 255, 255, 255, 255 )
surface.SetTextPos( ScrW() / 18, ScrH() / 18 )
surface.DrawText( "YourText" )
end

This wouldn’t make it scroll across the screen (which is what you’re looking for) but it should show up on your screen. Just mess about with the ScrW and the ScrH to get it in the right spot.

Also search Surface Library for more information on text on screen.

[lua]
local multiplier = 5 – greater multiplier = faster scroll
local width = ScrW() – the width of hte space which the text will scroll across
local ypos = 500 – the y pos on the screen, assuming the text scrolls horizontally
local text = “Hello, World!” – the text to draw
local font = “ScoreboardText” – the font to draw it in
local textcol = color_white – the color to draw the font

hook.Add(“HUDPaint”,“DrawScrollText”,function()
local x = math.fmod(SysTime() * multiplier,width
surface.SetFont(font)
local w,h = surface.GetTextSize(text)
if x + w > width then
draw.DrawText(text,font,(x + w - width) * -1,ypos,textcol,2)
end
draw.DrawText(text,font,math.fmod(SysTime() * multiplier,width),ypos,textcol,0)
end)
[/lua]
From an old thread. Link Credits to Entoros.

What would i have to edit in the math.fmod line to make it go from the right side of the screen to the left, i been editing it but cant get it to go start from the right and go all the way to the left :frowning:

Nothing. You can try doing this instead. (Fixed a missing parenthesis also)

[lua]
local multiplier = 5 – greater multiplier = faster scroll
local width = ScrW() – the width of hte space which the text will scroll across
local ypos = 500 – the y pos on the screen, assuming the text scrolls horizontally
local text = “Hello, World!” – the text to draw
local font = “ScoreboardText” – the font to draw it in
local textcol = color_white – the color to draw the font
local toleft_toright = 1 – Change this to -1 to go left or 1 to scroll to the right

hook.Add(“HUDPaint”,“DrawScrollText”,function()
local x = math.fmod(SysTime() * multiplier,width)
surface.SetFont(font)
local w,h = surface.GetTextSize(text)
if x + w > width then
draw.DrawText(text,font,(x + w - width) * toleft_toright, ypos, textcol,2)
end
draw.DrawText(text,font,math.fmod(SysTime() * multiplier,width),ypos,textcol,0)
end)
[/lua]