• chat.AddText adding line numbers at the end of a hint
    5 replies, posted
A friend of mine created a chat script to display hints clientside for players on my server. local hints = { "Click F4 and go to Jobs to choose a job", "Click F4 and go to Commands to see all the commands you can use", "Hold C to see your inventory", "Want to hang out with your friends? Remember to visit the local Pub and watch some movies!", "Found an issue? Report it on the forums or contact the server Owner", "The rules list is updated at least weekly, so stay tuned if there's a new update", "Type /cheque <name> <amount of money> to write a cheque for someone", "As a Mayor, click F2 to edit the taxes or buy Government perks", "Remember to visit our forums!", "Type /give <amount> to give money to the player you're looking at", "Type /drop <amount> to drop money", "Type /hit to place a hit on someone", "If you are unsure what to do as a certain job, read the job description", "Type /advert to make an advert", "Type /pm <name> <message> to PM someone", "Invite your friends and tell them about this server if you like it!", "If you don't like something about the server, you are more than welcome to say it on the forums" } timer.Create("random_hint_in_chat" , 120 , 0 , function() chat.AddText(Color(255,255,255,200),table.Random(hints)) end) So the problem is, there's always random numbers at the end of a hint, so if it's "type /wanted to make someone wanted", it appears with a number at the end of it. The number is always the number of the line the hint is on. He nor I could not find a fix to this issue, so I would be really grateful if someone told me how to fix it. Cheers.
table.Random is returning two values, the table value and the index. [url]http://wiki.garrysmod.com/page/table/Random[/url]
use (table.Random(haystack)) to only return the first value
I will try your advices, thanks.
If a method call isn't working how you think it should, or you're seeing strange results, break it down into smaller pieces and simplify it. Prove to yourself that each step is doing what you think it is doing. That being said I would just give the array a random index using the size of the array. [lua] timer.Create("random_hint_in_chat" , 120 , 0 , function() chat.AddText(Color(255,255,255,200),hints[math.random(1, #hints)]) end) [/lua]
[QUOTE=Feihc;45600515]If a method call isn't working how you think it should, or you're seeing strange results, break it down into smaller pieces and simplify it. Prove to yourself that each step is doing what you think it is doing. That being said I would just give the array a random index using the size of the array. [lua] timer.Create("random_hint_in_chat" , 120 , 0 , function() chat.AddText(Color(255,255,255,200),hints[math.random(1, #hints)]) end) [/lua][/QUOTE] Yours works. The other ones give me errors in console. Thanks a lot to all of you! // Closing thread
Sorry, you need to Log In to post a reply to this thread.