Advertisement
GoodManUsernameGood

Untitled

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