Jump to content

[HELP]-Random Messages


Exoogen

Recommended Posts

Posted

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 :(

Posted
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.

Posted

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" /> 
     

Posted
  
local messages = {"hey","hello","hi"} 
  
setTimer(function() outputChatBox(messages[math.random(1,#messages)]) end, 5000,0) 
  

oops! too much javascript :)

Posted

yes, it works fine :D 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

Posted

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 :P

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...