Advertisement
GoodManUsernameGood

Untitled

Feb 20th, 2022
863
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 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["CAPTAINID"] = "You need the captain's ID 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 ~= "!announce" 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 cardSlot = client.Character.Inventory.GetItemInLimbSlot(InvSlotType.Card)
  41.     if cardSlot == nil then return DenyCommand("CAPTAINID", client) end
  42.  
  43.     local idCard = cardSlot.GetComponentString("IdCard")
  44.     if idCard == nil then return DenyCommand("CAPTAINID", client) end
  45.     if idCard.GetJob() == nil then return DenyCommand("CAPTAINID", client) end
  46.     if idCard.GetJob().Identifier ~= "captain" then return DenyCommand("CAPTAINID", client) end
  47.  
  48.     local captainMessage = table.concat(split, ' ')
  49.     if captainMessage == nil then return end
  50.     Game.SendMessage("Captain Announces: " .. captainMessage, ChatMessageType.ServerMessageBox)
  51.     Game.SendMessage("Captain Announces: " .. captainMessage, ChatMessageType.Error)
  52.  
  53.     Game.Log(client.Name .. " sent an captain announcement: " .. captainMessage, ServerLogMessageType.Chat)
  54.  
  55.     spamLimit = Timer.GetTime() + 30
  56.  
  57.     return true
  58. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement