This repository has been archived by the owner on Mar 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Calling the pager from an external resource
Christopher M edited this page Sep 16, 2019
·
4 revisions
If you want to connect the Fire/EMS Pager + Fire Siren resource with other resources, follow this guide.
- Open the top level folder (resources/[inferno-collection]/inferno-fire-ems-pager)
- Open the
__resource.lua
file - Find this section, near the middle:
-- Client Script
client_script "client.lua"
-- Server Script
server_script "server.lua"
-- NUI Page
ui_page "html/index.html"
- Add the following entry under
ui_page "html/index.html"
, as seen here:
-- NUI Page
ui_page "html/index.html"
-- Export function
export "PagePagers"
- Open the
client.lua
file - Find this section, near the middle:
-- /page command
-- Used to page out a tone/s
RegisterCommand("page", function(Source, Args)
-- Number of provided tones
local ToneCount = 0
-- Whether the arguments has details or not
local HasDetails = false
-- Local array to store tones to be paged
local ToBePaged = {}
-- Check if the player is whitelisted to use this command
if Whitelist.Command.page then
-- If tones are not already being paged
if not Pager.Paging then
...
-- If tones are already being paged
else
-- Draw new notification on client's screen
NewNoti("~r~~h~Tones are already being paged.", true)
end
-- If player is not whitelisted
else
-- Draw error message on player screen
NewNoti("~r~You are not whitelisted for this command.", true)
end
end)
- Replace that entire section with the following:
-- /page command
-- Used to page out a tone/s
RegisterCommand("page", function(Source, Args)
PagePagers(Args)
end)
- Find this section, near the bottom:
-- Draws notification on client's screen
function NewNoti(Text, Flash)
-- Tell GTA that a string will be passed
SetNotificationTextEntry("STRING")
-- Pass temporary variable to notification
AddTextComponentString(Text)
-- Draw new notification on client's screen
DrawNotification(Flash, true)
end
- Add this code above that function:
-- Used to page out a tone/s
function PagePagers(Args)
-- Number of provided tones
local ToneCount = 0
-- Whether the arguments has details or not
local HasDetails = false
-- Local array to store tones to be paged
local ToBePaged = {}
-- Check if the player is whitelisted to use this command
if Whitelist.Command.page then
-- If tones are not already being paged
if not Pager.Paging then
-- Loop though all the tones provided in the command
for _, ProvidedTone in ipairs(Args) do
-- Loop through all the valid tones
for _, ValidTone in ipairs(Pager.Tones) do
-- If a provided tone matches a valid tone
if ProvidedTone:lower() == ValidTone then
-- Add it to the list of tones to be paged
table.insert(ToBePaged, ValidTone)
-- No need to keep searching for this tone
break
-- Checks for the separator character
elseif ProvidedTone:lower() == Config.PageSep then
-- Set true, used for checking and loop breaking
HasDetails = true
-- Counts up to the number of valid tones provided
-- plus 1, to include the separator
for _ = ToneCount + 1, 1, -1 do
-- Remove tones from arguments to leave only details
table.remove(Args, 1)
end
-- Break from loop
break
end
end
-- If a break is needed
if HasDetails then
-- Break from loop
break
end
-- Increase count
ToneCount = ToneCount + 1
end
-- If the number of originally provided tones matches the
-- number of tones, and there where tones acutally provided
-- in the first place
if not ToneCount ~= #ToBePaged and ToneCount ~= 0 then
-- Create a temporary variable to add more text to
local NotificationText = "~g~Paging:~y~"
-- Loop though all the tones
for _, Tone in ipairs(ToBePaged) do
-- Add a tone to temporary string
NotificationText = NotificationText .. " " .. Tone:upper()
end
-- Draw new notification on client's screen
NewNoti(NotificationText, false)
-- Bounces tones off of server
TriggerServerEvent("Fire-EMS-Pager:PageTones", ToBePaged, HasDetails, Args)
-- If there is a mismatch, i.e. invalid/no tone/s provided
else
-- Draw new notification on client's screen
NewNoti("~r~~h~Invalid tones, please check your command arguments.", true)
end
-- If tones are already being paged
else
-- Draw new notification on client's screen
NewNoti("~r~~h~Tones are already being paged.", true)
end
-- If player is not whitelisted
else
-- Draw error message on player screen
NewNoti("~r~You are not whitelisted for this command.", true)
end
end
- You can now call this function from any resource, using this code:
exports["inferno-fire-ems-pager"]:PagePagers(Tones)
Where Tones
is an array containing the name/s of the tone/s to be paged, with each tone being a new element in said array, for example:
Tones = {"fire", "medical", "rescue"}
- Enjoy!
Paste this code where you want to page tones:
-- Client Scripts
-- No details
TriggerServerEvent("Fire-EMS-Pager:PageTones", {"your", "tones", "here"}, false)
-- With details
TriggerServerEvent("Fire-EMS-Pager:PageTones", {"your", "tones", "here"}, true, {"Your", "details", "here", "in", "array", "form"})
-- Server Scripts
-- No details
TriggerEvent("Fire-EMS-Pager:PageTones", {"your", "tones", "here"}, false)
-- With details
TriggerEvent("Fire-EMS-Pager:PageTones", {"your", "tones", "here"}, true, {"Your", "details", "here", "in", "array", "form"})
This method is not recommended because it not only bypasses whitelisting, but also allows tones to be played right over the top of other tones, as there is no checking if tones are already playing.
Note: Whitelisting still applies, if enabled. Passing incorrect tones, or an invalid argument will break your script, ensure you are passing an array, and never trust user input!
If you have any troubles, suggestions, feedback, etc, please check the Wiki, create a new issue, and/or contact us on Discord.