1. How do I get from a list in my config a random one and use it as string?
    Like the notifier plugin which randomly chooses a broadcasted message out of the config.
     
  2. Make enumed list of messages in config, read it. And then randomize nums for calling diff messages?
     
  3. Well not messages, that was an example but yes. I mean that I got a list in my config file, and I want to get a random one out of that list.
    [DOUBLEPOST=1428577171][/DOUBLEPOST]
    Picking up the example with the messages again, my config file would look like this:

    Code:
    {
      "Messages": 
      "This is a Oxide Server",
      "I like turtles",
      "Apples are red",
      "Random messages?"
    }
    
     
  4. Still, you have array of strings, just get his length and randomize ints from 0 to Length - 1
    and call it:

    local randomizedInt = math.random(0, messages.Length -1)
    message = messages[randomizedInt]
     
  5. that does not work for me....
    Code:
    function PLUGIN:LoadDefaultConfig()
        self.Config.Messages = self.Config.Messages or
        "Message1",
        "Message2",
        "Message3"
    endfunction PLUGIN:cmdBroadcast()
            local randomizedInt = math.random(0,Messages.Length -1)
            Message = Messages[randomizedInt]
            rust.RunServerCommand("say " .. Message)
    end
    
     
  6. Your self.Config.Messages isn't a table, if you want it to be a table the values need to be between brackets:
    Code:
    self.Config.Messages = self.Config.Messages or { "Message 1", "Message 2", "Message 3" }
    And Lua tables aren't zero-index based so the first value is 1 and not 0 so you want to generate a value from 1 to length and not 0 to length - 1. And the specified table only uses values and default indexes so #<variable> can be used to obtain the amount of values in the table, also, you are using Messages[x] instead of your self.Config.Messages so unless you put that value in Messages somewhere along the way and it won't work.
    You also don't need to run the console command say, you can use the rust.BroadcastChat helper to broadcast a message.
    Code:
    function PLUGIN:cmdBroadcast()
      local message = self.Config.Messages[math.random(1, #self.Config.Messages)]
      rust.BroadcastChat(message)
    end
     
  7. Code:
    Failed to call hook 'cmdRandomBcast' on plugin 'Random Broadcaster' 
    File: randomitem.lua Line: 27 attempt to concatenate local 'message' (a nil value)
    
     
  8. Did you delete your config before trying it because the value you saved in your config before wasn't a table so it's probably still trying to load the index from that.
     
  9. Yea, totally forgot about that. Thanks ^^
     
  10. What if i wanted to give random "items" with the same way ?

    One more question how to give it to random player...
    Code:
    function PLUGIN:LoadDefaultConfig()
        self.Config.RandomItems = self.Config.RandomItems or {"Pick Axe","Wood","Brain"}endfunction PLUGIN:cmdRandom()
    local items = self.Config.RandomItems[math.random(1,#self.Config.RandomItems)]
      rust.RunServerCommand(inventory.giveid {player}  items)
    end
    
     
  11. Take a look at my RGive plugin which does exactly that.