local standardVolumeOutput = 1.0;
local volumeradio = 1.0
local volumebeeps = 0.03
local notificacoeson = false
local codec = true
local beepstempoff = false
local radioEffectId = CreateAudioSubmix('Radio')
SetAudioSubmixEffectRadioFx(radioEffectId, 0)
SetAudioSubmixEffectParamInt(radioEffectId, 0, GetHashKey('default'), 1)
AddAudioSubmixOutput(radioEffectId, 0)



local radioEffectId2 = CreateAudioSubmix('mphone')
SetAudioSubmixEffectRadioFx(radioEffectId2, 1)
SetAudioSubmixEffectParamInt(radioEffectId2, 1, GetHashKey('default'), 1)
SetAudioSubmixEffectParamFloat(radioEffectId2, 1, GetHashKey('freq_low'), 189.0)
SetAudioSubmixEffectParamFloat(radioEffectId2, 1, GetHashKey('freq_hi'), 7248.0)
AddAudioSubmixOutput(radioEffectId2, 1)

local ativos_clean = {}
local radioEffectIduso = -1

local incall = false
RegisterNetEvent('esx_voice:call')
AddEventHandler('esx_voice:call', function(estado)
	incall = estado
	--print (estado)
end)
 





RegisterNetEvent('voice:exportnot')
AddEventHandler('voice:exportnot', function(cambiar)
	notificacoeson = cambiar
end)

RegisterNetEvent('voice:exportnot2')
AddEventHandler('voice:exportnot2', function()
	codec = not codec
	SetResourceKvp('PTG-Radio:codec',tostring(codec))
	if codec == true then
		exports['mythic_notify']:SendAlert('inform', 'Rádio em modo realista', 2500, { ['background-color'] = '#ffffff', ['color'] = '#1EBD44' })
	else
		exports['mythic_notify']:SendAlert('inform', 'Radio em modo irrealista ', 2500, { ['background-color'] = '#ffffff', ['color'] = '#1EBD44' })
	end
end)

RegisterNetEvent('voice:SIRENEBOMB')
AddEventHandler('voice:SIRENEBOMB', function(valorbeeps)

	local lCoords = GetEntityCoords(GetPlayerPed(-1))
	distIs = Vdist(lCoords.x, lCoords.y, lCoords.z, -634.07, -107.67, 43.78)
	--print(distIs)
	local somm = 0.04
	
	if distIs < 200 then
		somm = 0.26
	elseif distIs < 400 then
		somm = 0.20
	elseif distIs < 700 then
		somm = 0.16
	elseif distIs < 1200 then
		somm = 0.08
	end
	
	TriggerEvent('InteractSound_CL:PlayOnAll_sirene', 'Sirene', somm)
end)

RegisterNetEvent('InteractSound_CL:PlayOnAll_sirene')
AddEventHandler('InteractSound_CL:PlayOnAll_sirene', function(soundFile, soundVolume)
    SendNUIMessage({
        transactionType     = 'playSound2',
        transactionFile     = soundFile,
        transactionVolume   = soundVolume
    })
end)

RegisterNetEvent('InteractSound_CL:PlayOnOne_mp3')
AddEventHandler('InteractSound_CL:PlayOnOne_mp3', function(soundFile, soundVolume)
    SendNUIMessage({
        transactionType     = 'playSound2',
        transactionFile     = soundFile,
        transactionVolume   = soundVolume
    })
end)

RegisterNetEvent('voice:beeps')
AddEventHandler('voice:beeps', function(valorbeeps)
	if valorbeeps == nil then return end
	if tonumber(valorbeeps) >= 1 and tonumber(valorbeeps) <= 100 then
		local valorfinalb = tonumber(valorbeeps) / 100
		volumebeeps = valorfinalb
		SetResourceKvp('PTG-Radio:beeps',valorbeeps)
		exports['mythic_notify']:SendAlert('inform', 'Volume Sons da Rádio: '..valorbeeps..'%', 2500, { ['background-color'] = '#ffffff', ['color'] = '#1EBD44' })
	else
		exports['mythic_notify']:SendAlert('inform', 'Volume Inválido', 2500, { ['background-color'] = '#ffffff', ['color'] = '#BD1E1E' })
	end
end)

RegisterNetEvent('voice:defvolume')
AddEventHandler('voice:defvolume', function(valorvolume)
	if valorvolume == nil then return end
	if tonumber(valorvolume) >= 1 and tonumber(valorvolume) <= 150 then
		local valorfinalv = tonumber(valorvolume) / 100
		volumeradio = valorfinalv
		SetResourceKvp('PTG-Radio:defvolume',valorvolume)
		exports['mythic_notify']:SendAlert('inform', 'Volume da Rádio: '..valorvolume..'%', 2500, { ['background-color'] = '#ffffff', ['color'] = '#1EBD44' })
	else
		exports['mythic_notify']:SendAlert('inform', 'Volume Inválido', 2500, { ['background-color'] = '#ffffff', ['color'] = '#BD1E1E' })
	end
end)

RegisterCommand('radiovolume-', function()
	
	local tempradio = volumeradio
	tempradio = (tempradio*10 - 1)/10
	if tempradio < 0.05 then tempradio = 0.05 end
	volumeradio = tempradio
	local valorvolume2 = math.floor(volumeradio*100)	
	exports['mythic_notify']:SendAlert('inform', 'Volume da Rádio: '..valorvolume2..'%', 2500, { ['background-color'] = '#ffffff', ['color'] = '#1EBD44' })
	
	--if volumeradio < 0.06 then
	--	beepstempoff = true
	--end
	
end, false)

RegisterCommand('radiovolume+', function()  
	
	local tempradio = volumeradio
	tempradio = (tempradio*10 + 1)/10
	if tempradio > 1.5 then tempradio = 1.5 end
	volumeradio = tempradio
	local valorvolume2 = math.floor(volumeradio*100)	
	exports['mythic_notify']:SendAlert('inform', 'Volume da Rádio: '..valorvolume2..'%', 2500, { ['background-color'] = '#ffffff', ['color'] = '#1EBD44' })

	--if volumeradio > 0.05 then
	--	beepstempoff = false
	--end
	
end, false)

RegisterNetEvent('InteractSound_CL:PlayOnOne')
AddEventHandler('InteractSound_CL:PlayOnOne', function(soundFile, soundVolume)
    SendNUIMessage({
        transactionType     = 'playSound',
        transactionFile     = soundFile,
        transactionVolume   = soundVolume
    })
end)


RegisterNetEvent('InteractSound_CL:cleanup')
AddEventHandler('InteractSound_CL:cleanup', function()
	for k,v in pairs(ativos_clean) do
		MumbleSetSubmixForServerId(k, -1)
		MumbleSetVolumeOverrideByServerId(k, -1.0)
	end
	ativos_clean = {}
end)


RegisterNetEvent('InteractSound_CL:PlayOnOne1')
AddEventHandler('InteractSound_CL:PlayOnOne1', function(soundFile, soundVolume, fonte, omeunome)
	if codec == true then
		MumbleSetSubmixForServerId(fonte, radioEffectId)
		--radioEffectIduso = radioEffectId
	end
	MumbleSetVolumeOverrideByServerId(fonte, volumeradio)
	ativos_clean[fonte] = true
	if notificacoeson == true then
		exports['mythic_notify']:SendAlert('inform', 'A transmitir: '..omeunome, 2500, { ['background-color'] = '#012D7A', ['color'] = '#ffffff' })
	end
    
	if volumeradio > 0.05 then
		SendNUIMessage({
			transactionType     = 'playSound',
			transactionFile     = soundFile,
			transactionVolume   = volumebeeps
		})
	end
end)

RegisterNetEvent('InteractSound_CL:PlayOnOne2')
AddEventHandler('InteractSound_CL:PlayOnOne2', function(soundFile, soundVolume, fonte)
	MumbleSetSubmixForServerId(fonte, -1)
	MumbleSetVolumeOverrideByServerId(fonte, -1.0)
	ativos_clean[fonte] = nil
    if volumeradio > 0.05 then
		SendNUIMessage({
			transactionType     = 'playSound',
			transactionFile     = soundFile,
			transactionVolume   = volumebeeps
		})
	end
end)

local GUARDON = 0

RegisterNetEvent('InteractSound_CL:PlayOnOne1GUARD')
AddEventHandler('InteractSound_CL:PlayOnOne1GUARD', function(soundFile, soundVolume, fonte, omeunome)
	
	local playerPed = PlayerPedId()
	if IsPedInAnyPlane(playerPed) or IsPedInAnyHeli(playerPed) then
	
		local vehicle = GetVehiclePedIsIn(playerPed, false)
		if GetPedInVehicleSeat(vehicle, -1) == playerPed or GetPedInVehicleSeat(vehicle, 0) == playerPed then
			GUARDON = GUARDON + 1
			--if codec == true then
			MumbleSetSubmixForServerId(fonte, radioEffectId)
				--radioEffectIduso = radioEffectId
			--end
			MumbleSetVolumeOverrideByServerId(fonte, volumeradio)
			ativos_clean[fonte] = true
			--if notificacoeson == true then
				exports['mythic_notify']:SendAlert('inform', 'Transmissão na GUARD de: '..omeunome, 5000, { ['background-color'] = '#861010', ['color'] = '#ffffff' })
			--end
			
			--if volumeradio > 0.05 then
				SendNUIMessage({
					transactionType     = 'playSound',
					transactionFile     = soundFile,
					transactionVolume   = volumebeeps
				})
			--end
		end
	end
end)

RegisterNetEvent('InteractSound_CL:PlayOnOne2GUARD')
AddEventHandler('InteractSound_CL:PlayOnOne2GUARD', function(soundFile, soundVolume, fonte)
	
	if GUARDON > 0 then
		GUARDON = GUARDON - 1
		MumbleSetSubmixForServerId(fonte, -1)
		MumbleSetVolumeOverrideByServerId(fonte, -1.0)
		ativos_clean[fonte] = nil
		if volumeradio > 0.05 then
			SendNUIMessage({
				transactionType     = 'playSound',
				transactionFile     = soundFile,
				transactionVolume   = volumebeeps
			})
		end
	end
end)


RegisterNetEvent('InteractSound_CL:PlayOnAll')
AddEventHandler('InteractSound_CL:PlayOnAll', function(soundFile, soundVolume)
    SendNUIMessage({
        transactionType     = 'playSound',
        transactionFile     = soundFile,
        transactionVolume   = soundVolume
    })
end)

RegisterNetEvent('InteractSound_CL:PlayWithinDistance')
AddEventHandler('InteractSound_CL:PlayWithinDistance', function(playerNetId, maxDistance, soundFile, soundVolume, tango)
    local lCoords = GetEntityCoords(GetPlayerPed(-1))
    --local eCoords = GetEntityCoords(GetPlayerPed(GetPlayerFromServerId(playerNetId)))
	
	
    local distIs  = 9999
	if tango == 't2' then
		distIs = Vdist(lCoords.x, lCoords.y, lCoords.z, -576.88,-210.2,39.0)
	elseif tango == 't1' then
		distIs = Vdist(lCoords.x, lCoords.y, lCoords.z, 320.55, -1627.1, 61.42)
	end
	
	
    if(distIs <= 13 and distIs ~= nil ) then
		--print('hi')
        SendNUIMessage({
            transactionType     = 'playSound',
            transactionFile     = soundFile,
            transactionVolume   = soundVolume
        })
		Citizen.Wait(350)
		SendNUIMessage({
            transactionType     = 'playSound',
            transactionFile     = soundFile,
            transactionVolume   = soundVolume
        })
    end
end)


Citizen.CreateThread(function()	
	Citizen.Wait(6000)
	
	local settings_data_1 = tonumber(GetResourceKvpString('PTG-Radio:defvolume'))
	local settings_data_2 = tonumber(GetResourceKvpString('PTG-Radio:beeps'))
	--local tostring(settings_data_3) = GetResourceKvpString('PTG-Radio:desnotif')
	--local tostring(settings_data_4) = GetResourceKvpString('PTG-Radio:desnotif2')
	local settings_data_5 = GetResourceKvpString('PTG-Radio:codec')
	
	if settings_data_1 then
		TriggerEvent('voice:defvolume',  settings_data_1)
	end
	if settings_data_2 then
		TriggerEvent('voice:beeps',  settings_data_2)
	end
	--if settings_data_3 == true then
	--	TriggerEvent('voice:desnotif')
	--end
	--if settings_data_4 == true then
	--	TriggerEvent('voice:desnotif2')
	--end
	if settings_data_5 == 'false' then
		TriggerEvent('voice:exportnot2')
	end	
	
end)

--RegisterCommand('megatest', function()
--	TriggerEvent('voice:megaphoneitem')
--
--end)

local megafone = false

RegisterNetEvent('voice:megaphoneitem')
AddEventHandler('voice:megaphoneitem', function()

	if megafone == true then megafone = false return end
	
	local breakthis = 0
	local ped = PlayerPedId()
	local model = `prop_megaphone_01`
	
	
	
	RequestModel(model)
	
	while not HasModelLoaded(model) do
		Citizen.Wait(100)
		breakthis = breakthis + 1
		if breakthis > 100 then
			break
		end
	end

	RequestAnimDict('cellphone@')
	breakthis = 0

	while not HasAnimDictLoaded('cellphone@') do
		Citizen.Wait(100)
		breakthis = breakthis + 1
		if breakthis > 100 then
			break
		end
	end
	
    local pole = CreateObject(model, GetEntityCoords(ped), true, false, false)
    AttachEntityToEntity(pole, ped, GetEntityBoneIndexByName(ped, "BONETAG_L_HAND"), vector3(0.15, 0.07, 0.02), vector3(250.0, 0.0, 320.0), false, false, false, false, 2, true)
    SetModelAsNoLongerNeeded(model)	

    TaskPlayAnim(ped, 'cellphone@', "cellphone_photo_idle", 8.0, -8.0, -1, 49, 0.0, false, false, false)
					
	megafone = true
	-- TRIGGER EVENT CREATE VOICE MIX SERVER
	TriggerServerEvent('InteractSound_SV:megaphone', true)
	TriggerEvent('voice:mega')
	while megafone do
		Citizen.Wait(0)
		local unarmed = `WEAPON_UNARMED`
		SetCurrentPedWeapon(ped, unarmed)
		
		if not IsEntityPlayingAnim(ped, 'cellphone@', 'cellphone_photo_idle', 3) then
			 TaskPlayAnim(ped, 'cellphone@', "cellphone_photo_idle", 8.0, -8.0, -1, 49, 0.0, false, false, false)
		end
		
		if IsControlJustReleased(0, 73) or IsControlJustReleased(0, 194) or IsControlJustReleased(0, 182) or incall == true then			
			break
		end
	
	end

	ClearPedTasks(ped)
	megafone = false
	TriggerEvent('voice:mega2')		
	TriggerServerEvent('InteractSound_SV:megaphone', false)
    DeleteObject(pole)
    RemoveAnimDict('cellphone@')
	
end)

RegisterNetEvent('voice:megaphoneitem_mic')
AddEventHandler('voice:megaphoneitem_mic', function()

	if megafone == true then megafone = false return end
	
	local breakthis = 0
	local ped = PlayerPedId()
	local model = `prop_microphone_02`
	
	
	
	RequestModel(model)
	
	while not HasModelLoaded(model) do
		Citizen.Wait(100)
		breakthis = breakthis + 1
		if breakthis > 100 then
			break
		end
	end

	RequestAnimDict('anim@heists@humane_labs@finale@keycards')
	breakthis = 0

	while not HasAnimDictLoaded('anim@heists@humane_labs@finale@keycards') do
		Citizen.Wait(100)
		breakthis = breakthis + 1
		if breakthis > 100 then
			break
		end
	end
	
    local pole = CreateObject(model, GetEntityCoords(ped), true, false, false)
    AttachEntityToEntity(pole, GetPlayerPed(PlayerId()), GetPedBoneIndex(GetPlayerPed(PlayerId()), 18905), 0.11, 0.03, 0.03, -100.0, 0.0, -10.0, 1, 1, 0, 1, 0, 1)
    SetModelAsNoLongerNeeded(model)	

    TaskPlayAnim(ped, 'anim@heists@humane_labs@finale@keycards', "ped_a_enter_loop", 8.0, -8.0, -1, 49, 0.0, false, false, false)
					
	megafone = true
	-- TRIGGER EVENT CREATE VOICE MIX SERVER
	--TriggerServerEvent('InteractSound_SV:megaphone', true)
	TriggerEvent('voice:mega')
	while megafone do
		Citizen.Wait(0)
		local unarmed = `WEAPON_UNARMED`
		SetCurrentPedWeapon(ped, unarmed)
		
		if not IsEntityPlayingAnim(ped, 'anim@heists@humane_labs@finale@keycards', 'ped_a_enter_loop', 3) then
			 TaskPlayAnim(ped, 'anim@heists@humane_labs@finale@keycards', "ped_a_enter_loop", 8.0, -8.0, -1, 49, 0.0, false, false, false)
		end
		
		if IsControlJustReleased(0, 73) or IsControlJustReleased(0, 194) or IsControlJustReleased(0, 182) or incall == true then			
			break
		end
	
	end

	ClearPedTasks(ped)
	megafone = false
	TriggerEvent('voice:mega2')		
	--TriggerServerEvent('InteractSound_SV:megaphone', false)
    DeleteObject(pole)
    RemoveAnimDict('anim@heists@humane_labs@finale@keycards')
	
end)

RegisterNetEvent('voice:megaphonevoz')
AddEventHandler('voice:megaphonevoz', function(state, fonte)

	if state == true then
		--print('effect', fonte)
		MumbleSetSubmixForServerId(fonte, radioEffectId2)
	else
		MumbleSetSubmixForServerId(fonte, -1)
	end

end) 

Lua online compiler

Write, Run & Share Lua code online using OneCompiler's Lua online compiler for free. It's one of the robust, feature-rich online compilers for Lua language, running the latest Lua version 5.4. Getting started with the OneCompiler's Lua editor is easy and fast. The editor shows sample boilerplate code when you choose language as Lua and start coding.

Taking inputs (stdin)

OneCompiler's Lua online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample Lua program which takes name as input and prints hello message with your name.

name = io.read("*a")
print ("Hello ", name)

About Lua

Lua is a light weight embeddable scripting language which is built on top of C. It is used in almost all kind of applications like games, web applications, mobile applications, image processing etc. It's a very powerful, fast, easy to learn, open-source scripting language.

Syntax help

Variables

  • By default all the variables declared are global variables
  • If the variables are explicitly mentioned as local then they are local variables.
  • Lua is a dynamically typed language and hence only the values will have types not the variables.

Examples

-- global variables
a = 10

-- local variables

local x = 30
Value TypeDescription
numberRepresents numbers
stringRepresents text
nilDifferentiates values whether it has data or not
booleanValue can be either true or false
functionRepresents a sub-routine
userdataRepresents arbitary C data
threadRepresents independent threads of execution.
tableCan hold any value except nil

Loops

1. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while(condition)
do
--code
end

2. Repeat-Until:

Repeat-Until is also used to iterate a set of statements based on a condition. It is very similar to Do-While, it is mostly used when you need to execute the statements atleast once.

repeat
   --code
until( condition )

3. For:

For loop is used to iterate a set of statements based on a condition.

for init,max/min value, increment
do
   --code
end

Functions

Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increase re-usuability and modularity.

optional_function_scope function function_name( argument1, argument2, argument3........, argumentn)
--code
return params with comma seperated
end