Calling the fire siren from an external resource - inferno-collection/Fire-EMS-Pager GitHub Wiki

How to sound the fire siren from an external resource

If you want to connect the Fire/EMS Pager + Fire Siren resource with other resources, follow this guide.

> Warning: Advanced Tutorial

  1. Open the top level folder (resources/[inferno-collection]/inferno-fire-ems-pager)
  2. Open the __resource.lua file
  3. 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"
  1. Add the following entry under ui_page "html/index.html", as seen here:
-- NUI Page
ui_page "html/index.html"

-- Export function
export "SoundFireSiren"
  1. Open the client.lua file
  2. Find this section, near the middle:
-- /firesiren command
-- Used to play a fire siren at a specific station/s
RegisterCommand("firesiren", function(Source, Args)
	if Whitelist.Command.firesiren then
		local ToBeSirened = {}

		...

	-- If player is not whitelisted
	else
		NewNoti("~r~You are not whitelisted for this command.", true)
	end
end)
  1. Replace that entire section with the following:
-- Base fire siren command
-- Used to play a fire siren at a specific station/s
RegisterCommand("firesiren", function(Source, Args)
	SoundFireSiren(Args)
end)
  1. Find this section, near the bottom:
-- Draws notification on client's screen
function NewNoti(Text, Flash)
	if not Config.DisableAllMessages then
		-- 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
end
  1. Add this code above that function:
-- Sounds fire siren
-- Check if the player is whitelisted to use this command
function soundFireSiren(Args)
	if Whitelist.Command.firesiren then
		local ToBeSirened = {}
		-- Loop though all the stations provided in the command
		for _, ProvidedStation in ipairs(Args) do
			-- Loop through all the valid stations
			for _, ValidStation in ipairs(FireSiren.Stations) do
				-- If a provided station matches a valid station
				if ProvidedStation:lower() == ValidStation.Name then
					-- If station is not already playing a siren
					if not FireSiren.EnabledStations[ProvidedStation:lower()] then
						ValidStation.x, ValidStation.y, ValidStation.z = table.unpack(ValidStation.Loc)
						table.insert(ToBeSirened, ValidStation)
						-- Station is already playing a siren
					else
						NewNoti("~r~~h~One or more stations provided are already sounding!", true)
						return
					end
				end
			end
		end

		-- If the number of originally provided stations matches
		-- the number of stations, and there where stations acutally
		-- provided in the first place
		if not #Args ~= #ToBeSirened and #Args ~= 0 then
			-- Create a temporary variable to add more text to
			local NotificationText = "~g~Sounding:~y~"
			-- Loop though all stations
			for _, Station in ipairs(ToBeSirened) do
				TriggerServerEvent("Fire-EMS-Pager:StoreSiren", Station)
				-- Add station to temporary variable
				NotificationText = NotificationText .. " " .. Station.Name:upper()
			end
			NewNoti(NotificationText, false)
			Citizen.Wait(2000)
			TriggerServerEvent("Fire-EMS-Pager:SoundSirens", ToBeSirened)
		-- If there is a mismatch, i.e. invalid/no stations/s provided
		else
			NewNoti("~r~~h~Invalid stations for sounding, please check your command arguments.", true)
		end
	-- If player is not whitelisted
	else
		NewNoti("~r~You are not whitelisted for this command.", true)
	end
end
  1. You can now call this function from any resource, using this code:
exports["inferno-fire-ems-pager"]:SoundFireSiren(stations)

Where Stations is an array containing the name/s of the station/s to be sounded, with each station being a new element in said array, for example:

stations = {"pb", "fz", "ss"}
  1. Enjoy!

Note: Whitelisting still applies, if enabled. Passing incorrect stations, 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.