Advertisement
GoodManUsernameGood

Untitled

Mar 17th, 2022
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.00 KB | None | 0 0
  1.  
  2.  local function DenyCommand(errorCode, client)
  3.     local text = {}
  4.     text["DEAD"] = "You need to be alive to use this command."
  5.     text["HEADSET"] = "You need a working headset to use this command."
  6.     text["NOSPEAK"] = "You need to be able to speak to use this command."
  7.     text["SPAM"] = "You need to wait a little bit to use this command again."
  8.  
  9.     Game.SendDirectChatMessage("", text[errorCode], nil, ChatMessageType.ServerMessageBox, client)
  10.     return true
  11. end
  12.  
  13. local spamLimit = 0
  14. Hook.Add("chatMessage", "captainAnnounce", function (message, client)
  15.     local split = {}
  16.     for w in string.gmatch(message, "[^%s]+") do
  17.         table.insert(split, w)
  18.     end
  19.     local command = table.remove(split, 1)
  20.  
  21.     if command ~= "!g" then return end
  22.  
  23.     if Timer.GetTime() < spamLimit then return DenyCommand("SPAM", client) end
  24.  
  25.     if client.Character == nil or client.Character.IsDead or not client.Character.IsHuman then
  26.         return DenyCommand("DEAD", client)
  27.     end
  28.  
  29.     if client.Character.SpeechImpediment > 99 then return DenyCommand("NOSPEAK", client) end
  30.  
  31.     local headsetSlot = client.Character.Inventory.GetItemInLimbSlot(InvSlotType.Headset)
  32.  
  33.     if headsetSlot == nil then return DenyCommand("HEADSET", client) end
  34.     local wifiComponent = headsetSlot.GetComponentString("WifiComponent")
  35.  
  36.     if wifiComponent == nil or not wifiComponent.CanTransmit() then
  37.         return DenyCommand("HEADSET", client)
  38.     end
  39.  
  40.     local captainMessage = table.concat(split, ' ')
  41.     if captainMessage == nil then return end
  42.  
  43.     local chatMessage = ChatMessage.Create(client.Name, captainMessage, ChatMessageType.Private, nil)
  44.     chatMessage.Color = Color(255, 255, 0, 255)
  45.  
  46.     for key, value in pairs(Client.ClientList) do
  47.         Game.SendDirectChatMessage("GLOBAL: " .. chatMessage, value)    
  48.     end
  49.  
  50.     Game.Log(client.Name .. " sent a global message: " .. captainMessage, ServerLogMessageType.Chat)
  51.  
  52.     spamLimit = Timer.GetTime() + 1
  53.  
  54.     return true
  55. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement