Solved Does chat.add broadcast?

Discussion in 'Rust Development' started by Scriptzyy, Oct 21, 2016.

  1. Hey all,

    I'm currently coding a JS plugin and I've managed to get the following to print out a message in chat:

    Code:
    OnEntityDeath: function(entity, info){
      info.Initiator.sendConsoleCommand("chat.add", "", "Hello World!");
    }
    
    I'm curious if this message can only be seen by the "Initiator" or if it's a broadcast to the whole chat. Unfortunately I don't have anyone online right now to tell me :p

    Thanks in advance <3
     
  2. Wulf

    Wulf Community Admin

    I'd suggest using Oxide's broadcast functions. The chat.add command will only add the chat to the target's client chat. The chat.say command would send it to the server for all to see, but as I mentioned you could use the wrappers Oxide provides too.
     
  3. Oh my bad, I forgot to mention that my goal is to have the message only show to the client. You answered the question either way though, thanks!
     
  4. Wulf

    Wulf Community Admin

    Oxide also offers helpers for those. ;)
     
  5. I'll look into it for my next BarrelPoints update :p
     
  6. Wulf

    Wulf Community Admin

    No need for the Init message (console noise and duplication), and you can use Rust's sending too instead of a chat command. Your check for "loot-barrel" I shortened too. You may be able to just check for "barrel" if you wanted to even.
    Code:
    var BarrelPoints = {
      Title: "BarrelPoints",
      Author: "Scriptzyy",
      Version: V(0, 1, 0),
      Description: "Gives players RewardPoints for destroying barrels.",
      HasConfig: true,  LoadDefaultConfig: function(){
        this.Config.options = {
          pointsPerBarrel: "5"
        }
      },  OnEntityDeath: function(entity, info){
        if(entity.ShortPrefabName.Contains == "loot-barrel" || entity.ShortPrefabName == "oil_barrel" || entity.ShortPrefabName == "oil-barrel"){
          info.Initiator.SendMessage("<color=#a6d8b0>You have gained +" + this.Config.options.pointsPerBarrel + " RP!</color>");
          info.Initiator.SendConsoleCommand("sr add " + info.Initiator.displayName + " " + this.Config.options.pointsPerBarrel);
        }
      }
    }
     
  7. Oh wow, thanks! Update 0.1.1 coming up soon aha :)