Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.90 KB | None | 0 0
  1. PLUGIN.Title        = "ChatChannel"
  2. PLUGIN.Description  = "Channel for other Languages"
  3. PLUGIN.Author       = ""
  4. PLUGIN.Version      = V(0, 0, 1)
  5. PLUGIN.HasConfig    = false
  6.  
  7. local SCData = nil
  8.  
  9. function PLUGIN:Init ()
  10.  
  11.  
  12.   -- Add chat command
  13.     command.AddChatCommand("esd", self.Plugin, "cmdESdes")
  14.     command.AddChatCommand("esl", self.Plugin, "cmdESLeave")
  15.     command.AddChatCommand("es", self.Plugin, "cmdESMess")
  16.         command.AddChatCommand("e", self.Plugin, "cmdESMess")
  17.     self:LoadSavedData()
  18. end
  19.  
  20. function PLUGIN:LoadSavedData()
  21.     -- Open the datafile if it exists, otherwise we'll create a new one.
  22.     SCData = datafile.GetDataTable("ChatChannel")
  23.     SCData = SCData or { }
  24. end
  25.  
  26. function PLUGIN:SaveData()
  27.     -- Save the DataTable
  28.     datafile.SaveDataTable("ChatChannel")
  29. end
  30.    function PLUGIN:cmdESdes(player)
  31.    for key, _ in pairs(SCData) do
  32.      
  33.    SCData[key] = nil
  34.    end
  35.    SCData = {}
  36.     self:SaveData()
  37.  end
  38.  
  39.  
  40.  
  41.  
  42.  
  43. function PLUGIN:cmdESMess(player, cmd, args)
  44.     if not player then return end
  45.  local playerSteamID = rust.UserIDFromPlayer(player)
  46.      if not SCData[playerSteamID] then
  47. SCData[playerSteamID] = { }
  48. SCData[playerSteamID].steamid = playerSteamID
  49. SCData[playerSteamID].username = player.displayName
  50. self:SaveData()
  51.  
  52.  
  53.  message = "<color=lightblue>[ESP] "..player.displayName..": </color><color=gray> joined the channel!</color>"
  54.  
  55. self:SendMessage(message)
  56.  
  57. end
  58. if args[0] then
  59.          local args = self:ArgsToTable(args, "chat")
  60.     local target, message = args[1], ""
  61.     local i = 1
  62.     while args[i] do
  63.         message = message..args[i].." "
  64.         i = i + 1
  65.     end
  66.     message = "<color=lightblue>[ESP] "..player.displayName..": </color>"..message
  67.      
  68. self:SendMessage(message)
  69.  
  70. end
  71. end
  72.  
  73.  
  74. function PLUGIN:cmdESLeave(player, cmd, args)
  75.     if not player then return end
  76.  local playerSteamID = rust.UserIDFromPlayer(player)
  77.      if SCData[playerSteamID] then
  78.       message = "<color=lightblue>[ESP] "..player.displayName..": </color><color=gray> left the channel!</color>"
  79. self:SendMessage(message)
  80. SCData[playerSteamID] = nil
  81. self:SaveData()
  82.  
  83. return
  84. end
  85.  
  86.  
  87.  
  88. end
  89.  
  90. function PLUGIN:SendMessage(message)
  91.     for key, _ in pairs(SCData) do
  92.         targetPlayer = global.BasePlayer.Find(SCData[key].steamid)
  93.         if targetPlayer then
  94.  
  95.    rust.SendChatMessage(targetPlayer, message)
  96.    end  
  97.  
  98.  end
  99.  
  100. end
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108. function PLUGIN:ArgsToTable(args, src)
  109.     local argsTbl = {}
  110.     if src == "chat" then
  111.         local length = args.Length
  112.         for i = 0, length - 1, 1 do
  113.             argsTbl[i + 1] = args[i]
  114.         end
  115.         return argsTbl
  116.     end
  117.     if src == "console" then
  118.         local i = 1
  119.         while args:HasArgs(i) do
  120.             argsTbl[i] = args:GetString(i - 1)
  121.             i = i + 1
  122.         end
  123.         return argsTbl
  124.     end
  125.     return argsTbl
  126. end
  127. --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement