Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PLUGIN.Title = "ChatChannel"
- PLUGIN.Description = "Channel for other Languages"
- PLUGIN.Author = ""
- PLUGIN.Version = V(0, 0, 1)
- PLUGIN.HasConfig = false
- local SCData = nil
- function PLUGIN:Init ()
- -- Add chat command
- command.AddChatCommand("esd", self.Plugin, "cmdESdes")
- command.AddChatCommand("esl", self.Plugin, "cmdESLeave")
- command.AddChatCommand("es", self.Plugin, "cmdESMess")
- command.AddChatCommand("e", self.Plugin, "cmdESMess")
- self:LoadSavedData()
- end
- function PLUGIN:LoadSavedData()
- -- Open the datafile if it exists, otherwise we'll create a new one.
- SCData = datafile.GetDataTable("ChatChannel")
- SCData = SCData or { }
- end
- function PLUGIN:SaveData()
- -- Save the DataTable
- datafile.SaveDataTable("ChatChannel")
- end
- function PLUGIN:cmdESdes(player)
- for key, _ in pairs(SCData) do
- SCData[key] = nil
- end
- SCData = {}
- self:SaveData()
- end
- function PLUGIN:cmdESMess(player, cmd, args)
- if not player then return end
- local playerSteamID = rust.UserIDFromPlayer(player)
- if not SCData[playerSteamID] then
- SCData[playerSteamID] = { }
- SCData[playerSteamID].steamid = playerSteamID
- SCData[playerSteamID].username = player.displayName
- self:SaveData()
- message = "<color=lightblue>[ESP] "..player.displayName..": </color><color=gray> joined the channel!</color>"
- self:SendMessage(message)
- end
- if args[0] then
- local args = self:ArgsToTable(args, "chat")
- local target, message = args[1], ""
- local i = 1
- while args[i] do
- message = message..args[i].." "
- i = i + 1
- end
- message = "<color=lightblue>[ESP] "..player.displayName..": </color>"..message
- self:SendMessage(message)
- end
- end
- function PLUGIN:cmdESLeave(player, cmd, args)
- if not player then return end
- local playerSteamID = rust.UserIDFromPlayer(player)
- if SCData[playerSteamID] then
- message = "<color=lightblue>[ESP] "..player.displayName..": </color><color=gray> left the channel!</color>"
- self:SendMessage(message)
- SCData[playerSteamID] = nil
- self:SaveData()
- return
- end
- end
- function PLUGIN:SendMessage(message)
- for key, _ in pairs(SCData) do
- targetPlayer = global.BasePlayer.Find(SCData[key].steamid)
- if targetPlayer then
- rust.SendChatMessage(targetPlayer, message)
- end
- end
- end
- function PLUGIN:ArgsToTable(args, src)
- local argsTbl = {}
- if src == "chat" then
- local length = args.Length
- for i = 0, length - 1, 1 do
- argsTbl[i + 1] = args[i]
- end
- return argsTbl
- end
- if src == "console" then
- local i = 1
- while args:HasArgs(i) do
- argsTbl[i] = args:GetString(i - 1)
- i = i + 1
- end
- return argsTbl
- end
- return argsTbl
- end
- --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement