..:D&G:.. Posted December 29, 2015 Posted December 29, 2015 Hello guys, I made this simple script to output some info messages in chat. The thing is that it only outputs the first byte (letter/number) from the table where I've inserted the messages. I know there should be a thing to get the whole string as a whole, but I don't know what it is... local messages = { "1) Message 1", "2) Message 2", "3) Message 3" } local message = math.random(1, #messages) function showInfoMessages() setTimer ( function() outputChatBox ("#D60606INFO: "..message, getRootElement(), 255, 255, 255, true) end, 10000, 0 ) end showInfoMessages() MTA:Rust Pre-Alpha Build v.0.3: https://forum.mtasa.com/viewtopic.php?f=114&t=97848 2Pac: ''Only God can judge me!''
Dealman Posted December 29, 2015 Posted December 29, 2015 It's not outputting the first byte, it's outputting your random number. It will be either 1, 2 or 3. If you want to get the table entry at that index, you need to structure it like this; outputChatBox ("#D60606INFO: "..messages[message], getRootElement(), 255, 255, 255, true) You're also only generating the the random number once, you don't really need a function for this, simply do it like this; local messages = { "1) Message 1", "2) Message 2", "3) Message 3" } -- Store the timer as a variable so you can manipulate the timer if you need to local messageTimer = setTimer(function() local randInt = math.random(1, #messages) -- Generate a new int every cycle outputChatBox ("#D60606INFO: "..tostring(messages[randInt]), getRootElement(), 255, 255, 255, true) -- Output the message at the randomly generated index end, 10000, 0) If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.
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