BabaGaNooSH Posted May 25, 2013 Share Posted May 25, 2013 Hi Before I get started let it be known this is going to be the first script and I appreciate any help I can get.. ok i know what math.random does and I have it currenty set to generate #'s 1-100 I have Also set a commandHandler to activate it e.g callrandom What i need help with is how to display said random number in a local chatbox e.g player hits /callrandom and then a number 1-100 appears on the screen. i'm not asking for someone to just give me a script as i am trying to learn i'm just looking for someone to point me in the right place to look Thanks again Link to comment
csiguusz Posted May 25, 2013 Share Posted May 25, 2013 Search the wiki for functions that you may need. For displaying a text in the text box use outputChatBox. Link to comment
adamb Posted May 25, 2013 Share Posted May 25, 2013 number = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} numbers = number [ math.random ( #number ) ] function randomnum outputChatBox ( " The random number is ".. numbers ..". " ) end addCommandHandler ( "callrandom", randomnum ) Not sure at all whether it will work, its my first time trying to help. Link to comment
csiguusz Posted May 25, 2013 Share Posted May 25, 2013 Why are you using a table? Isn't math.random ( 10 ) easier? And the brackets are missing from your function. Link to comment
manawydan Posted May 25, 2013 Share Posted May 25, 2013 local myNumber = math.random(1,10) Link to comment
adamb Posted May 25, 2013 Share Posted May 25, 2013 Why are you using a table? Isn't math.random ( 10 ) easier?And the brackets are missing from your function. I'm not a that... experienced scripter. PS; MAGYAR TESOO! Link to comment
csiguusz Posted May 25, 2013 Share Posted May 25, 2013 You don't have to be so experienced to know how to define a function. PS: Örülök neki! De magyarul inkább csak a magyar fórumon. Link to comment
BabaGaNooSH Posted May 27, 2013 Author Share Posted May 27, 2013 Ty Guys Its been a help Link to comment
Schlammy Posted May 27, 2013 Share Posted May 27, 2013 number = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} numbers = number [ math.random ( #number ) ] function randomnum outputChatBox ( " The random number is ".. numbers ..". " ) end addCommandHandler ( "callrandom", randomnum ) This will not work correctly. try this. function randomnum(player) local numbers = tostring(math.random(1,100)) outputChatBox ( " The random number is ".. numbers ..". ", player ) end addCommandHandler ( "callrandom", randomnum) Link to comment
beatles1 Posted May 27, 2013 Share Posted May 27, 2013 When you want a whole number between 1 and that number you only need to specify one argument in math.random. So here it would be math.random(100) instead of math.random(1, 100). If it only gets one argument it takes it as an upper value and uses 1 as the lower value. http://lua-users.org/wiki/MathLibraryTutorial Link to comment
Rick_Grimes Posted July 14, 2022 Share Posted July 14, 2022 (edited) ... try this: number = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} function randomnum() numbers = number [ math.random ( #number ) ] outputChatBox ( " The random number is ".. numbers ..". " ) end addCommandHandler ( "callrandom", randomnum ) Edited July 14, 2022 by NiNja1382 Link to comment
Moderators Vinyard Posted July 14, 2022 Moderators Share Posted July 14, 2022 Locking this as the thread is almost ten years old. Link to comment
Recommended Posts