Hey guys.
If I have this code;
[LUA]local function advert()
chat.AddText(
"Hello, ",
Color(255,255,255), "this", " is ",
Color(255,0,0), "red, ",
Color(0,255,0), "green, ",
Color(0,0,255), "blue")
chat.PlaySound()
end
timer.Create( "Adverts", 120, 0, advert )[/LUA]
Then how would I make it loop more than 1 message at different times?
You can do something like
[lua]Adverts = {
{ Color( 255, 255, 255 ), "White" },
{ Color( 255, 0, 0 ), "Red" },
{ Color( 0, 255, 0 ), "Green" },
{ Color( 0, 0, 255 ), "Blue" },
{ "Hello, ", Color(255,255,255), "this", " is ", Color(255,0,0), "red, ", Color(0,255,0), "green, ", Color(0,0,255), "blue" }
}
timer.Create( "Adverts", 120, 0, function()
chat.AddText( "Test: ", unpack(table.Random(Adverts)) )
chat.PlaySound()
end)[/lua]
I'd say do it serverside with [url=http://facepunch.com/threads/768062]this[/url]
Tables, smart :3
Thanks<3
Your very welcome.
If you want it to loop instead of random, You can do [lua]Adverts = {
{ Color( 255, 255, 255 ), "White" },
{ Color( 255, 0, 0 ), "Red" },
{ Color( 0, 255, 0 ), "Green" },
{ Color( 0, 0, 255 ), "Blue" },
{ "Hello, ", Color(255,255,255), "this", " is ", Color(255,0,0), "red, ", Color(0,255,0), "green, ", Color(0,0,255), "blue" }
}
local NextMsg = 0
timer.Create( "Adverts", 5, 0, function()
NextMsg = NextMsg + 1
chat.AddText( "Test: ", unpack(Adverts[NextMsg]) )
chat.PlaySound()
if table.Count(Adverts) <= NextMsg then NextMsg = 0 end
end)[/lua]
Netsurfer, using the serverside chat.AddText is pointless.
Also, NextMsg should be reset to 1, the first index in a table is 1.
Your technically correct chessnut, But if you read the code more closely
If I put the NextMsg to 1, It'd go to 2 and totally skip 1. To make it like that, It'd take just moving the line. But no use in really screwing with it since this thread is solved
And can you explain why its pointless?
Instead of using chat.AddText, you use a function chat.AddText to send a usermessage that runs chat.AddText clientside.
I see the issue is that it'll add 1 to NextMsg.
Sorry, you need to Log In to post a reply to this thread.