Skip to content

Instantly share code, notes, and snippets.

@cm8263
Created September 16, 2019 07:52
Show Gist options
  • Save cm8263/44d2443a3248c44325f846c52af9e8d3 to your computer and use it in GitHub Desktop.
Save cm8263/44d2443a3248c44325f846c52af9e8d3 to your computer and use it in GitHub Desktop.
Searches /911 command for keywords and pages accordingly
-- Code refactored by Inferno (ChristopherM)
-- Takes an array and returns a string
function ArgsToText(Words)
-- Define local temp var
local Text = ""
-- Loop though all entires in array and add to var
for _, Word in ipairs(Words) do Text = Text .. Word .. " " end
-- Return temp var
return Text
end
-- /911 command
RegisterCommand("911", function(Source, Args)
-- New chat message
TriggerClientEvent("chat:addMessage", -1, {
color = { 255, 0, 0},
multiline = true,
args = {"^5^*911 | ^0(^5" .. GetPlayerName(Source) .." | " .. Source .."^0)", ArgsToText(Args)}
})
-- Temp array
local Tones = {}
-- Loop though all entires in array
for _, Word in ipairs(Args) do
-- If array contains the word fire
if Word == "fire" then
-- Add fire to the list of tones to page
table.insert(Tones, "fire")
-- Else if array contains the word ems
elseif Word == "ems" then
-- Add medical to the list of tones to page
table.insert(Tones, "medical")
-- Else if array contains the word crash
elseif Word == "crash" then
-- Add fire to the list of tones to page
table.insert(Tones, "fire")
-- Add rescue to the list of tones to page
table.insert(Tones, "rescue")
end
end
-- If tones table is not empty, page tones
if Tones ~= {} then TriggerEvent("Fire-EMS-Pager:PageTones", Tones, false) end
end)
-- 911 Dispatch command
RegisterCommand("911d", function(Source, Args)
-- New chat message
TriggerClientEvent("chat:addMessage", -1, {
color = { 255, 0, 0},
multiline = true,
args = {"^5Dispatch | ^0(^5" .. GetPlayerName(Source) .." | " .. Source .."^0)", ArgsToText(Args)}
})
end)
-- Twitter command
RegisterCommand("twt", function(Source, Args)
-- New chat message
TriggerClientEvent("chat:addMessage", -1, {
color = { 255, 0, 0},
multiline = true,
args = {"^6Twitter: ^6(^6" .. GetPlayerName(Source) .." ^6 | ^6" .. Source .."^6)", ArgsToText(Args)}
})
end)
-- Show ID command
RegisterCommand("id", function(Source, Args)
-- New chat message
TriggerClientEvent("chat:addMessage", -1, {
color = { 255, 0, 0},
multiline = true,
args = {"^3Shows ID: ^3(^3" .. GetPlayerName(Source) .." ^3 | ^3" .. Source .."^3)", ArgsToText(Args)}
})
end)
-- Made by FAXES.
-- Add "OOC: " to the front of every message in chat
AddEventHandler("chatMessage", function(Source, Name, Msg)
Args = Sringsplit(Msg, " ")
CancelEvent()
if string.find(Args[1], "/") then
local cmd = Args[1]
table.remove(Args, 1)
else
TriggerClientEvent("chatMessage", -1, "OOC: " .. Name, { 255, 255, 255 }, Msg)
end
end)
-- String splitter
function Sringsplit(Inputstr, Sep)
if Sep == nil then
Sep = "%s"
end
local t = {}
local i = 1
for Str in string.gmatch(Inputstr, "([^" .. Sep .. "]+)") do
t[i] = Str
i = i + 1
end
return t
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment