Exoogen Posted October 28, 2014 Posted October 28, 2014 Hi guys, how can i use math.random for make random messages in game? For exaple: every 3 minutes "PRESS F6 and open the SHOP PANEL" or "Press F4 ..." Help
Woovie Posted October 28, 2014 Posted October 28, 2014 local messages = ["hey","hello","hi"] setTimer(function() outputChatBox(messages[math.random(1,#messages)]) end, 5000,0) This will output a random message every 5 seconds. "The humble beet is the answer to all riddles." - Rolf
Exoogen Posted October 28, 2014 Author Posted October 28, 2014 I don't know why but doesn't work D: mrandom.lua : local messages = ["hey","hello","hi"] setTimer(function() outputChatBox(messages[math.random(1,#messages)]) end, 5000,0) meta.xml "Exoogen" description="kk" />
Anubhav Posted October 28, 2014 Posted October 28, 2014 local messages = {"hey","hello","hi"} setTimer(function() outputChatBox(messages[math.random(1,#messages)]) end, 5000,0) See my some resources: Skin shop: https://community.multitheftauto.com/in ... ls&id=8008 Note script: https://community.multitheftauto.com/in ... ls&id=8009 Rules Panel: https://community.multitheftauto.com/in ... ls&id=8246 Random Money: https://community.multitheftauto.com/in ... ls&id=8718
Woovie Posted October 29, 2014 Posted October 29, 2014 local messages = {"hey","hello","hi"} setTimer(function() outputChatBox(messages[math.random(1,#messages)]) end, 5000,0) oops! too much javascript "The humble beet is the answer to all riddles." - Rolf
Anubhav Posted October 29, 2014 Posted October 29, 2014 Hahaha See my some resources: Skin shop: https://community.multitheftauto.com/in ... ls&id=8008 Note script: https://community.multitheftauto.com/in ... ls&id=8009 Rules Panel: https://community.multitheftauto.com/in ... ls&id=8246 Random Money: https://community.multitheftauto.com/in ... ls&id=8718
Woovie Posted October 29, 2014 Posted October 29, 2014 It works fine, I just tested it. "The humble beet is the answer to all riddles." - Rolf
Exoogen Posted October 29, 2014 Author Posted October 29, 2014 yes, it works fine and thanks. Can you explain me why that script isn't written like another normal script ? Usually in a script there are a function with the function name, istruction and an EventHandler. In this case the function and instructions are written together.. PS: Sorry for my very bad english, i'm italian
Woovie Posted October 29, 2014 Posted October 29, 2014 Here's how it would look otherwise. local messages = {"hello","hi","hey"} local time = 5000 function pickMessage() local whatMessage = math.random(1,#messages) return messages[whatMessage] end function outputRandomMessage() local message = pickMessage outputChatBox(message) end function resourceStart() setTimer(outputRandomMessage,time,0) end addEventHandler("onResourceStart", resourceRoot, resourceStart) That's an overly unnecessary way to do it essentially "The humble beet is the answer to all riddles." - Rolf
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