Jump to content

[AJUDA]Sirenes Mods


Recommended Posts

  • Other Languages Moderators

Não é tão complicado. Para desativar o som de sirene e giroflex, basta usar essa função no lado client.

function fClientResourceStart( )
	setWorldSoundEnabled( 17, 10, false, true );
	setWorldSoundEnabled( 17, 11, false, true );
end
addEventHandler( "onClientResourceStart", resourceRoot, fClientResourceStart );

As funções que você deverá usar são:

CLIENT-SIDE

bindKey( ); -- // para fazer uma função de toggle (down, up), verificando se o jogador está segurando ou não a tecla H
playSound3D( ); -- // para tocar o áudio
setSoundVolume( ); -- // para alterar o volume da sirene
setSoundMinDistance( ); -- // altere para 1.0
setSoundMaxDistance( ); -- // a distância que os jogadores irão ouvir
attachElements( ); -- // fazer com que o elemento áudio grude no jogador responsável por apertar a tecla H
triggerServerEvent( ); -- // para sincronizar o áudio (client -> server)

SERVER-SIDE

triggerClientEvent( ); -- // mandar o áudio e o jogador responsável por apertar a tecla H para o client

 

  • Like 1
Link to comment
  • Other Languages Moderators

@EDIT

SERVER-SIDE

setVehicleSirensOn( ); -- // para desativar as luzes da sirene

Obrigado por avisar, @Lord Henry. É que eu fiz o script completo aqui para eu mesmo testar. O código está funcionando perfeitamente, realmente faltava essa função para ficar xuxu. :D

  • Like 1
Link to comment

Desculpe a demora para ver o tópico, então eu poderia fazer assim?

Client-Side

function disableSound ()
  setWorldSoundEnabled (17, 10, false, true)
  setWorldSoundEnabled (17, 11, false, true)
end
addEventHandler ("onClientResourceStart", resourceRoot, disableSound)

Client-Side

fub

function startSound ()
  for id, vehicle (getElementType(vehicle)) == "vehicle" do -- Não entendo muito de loops, me corrijam pls
    local veh = getPedOccupiedVehicle(localPlayer)
    if veh = (id == 596) then
      local pos = getElementPosition (localPlayer)
      local som = playSound3D ("som.mp3", pos)
      setSoundMinDistance (som, 1.0)
      setSoundMaxDistance (som, 25.0)
      -- Não tenho ideia de como fazer  triggerEvent
    end
  end
end
bindKey ("h", "down", startSound)

ESTARIA CORRETO DESSA FORMA?

Link to comment
  • Other Languages Moderators

Aqui o script completo.

CLIENT-SIDE

-- // TABELA DE VEÍCULOS QUE TERÃO NOVAS SIRENES
local tVehicles 	= { [ 597 ] = true, [ 416 ] = true };

-- // TABELA DOS CLIENTES
local tAudio		= { };

-- // FUNÇÕES
function fClientResourceStart( )
	setWorldSoundEnabled( 17, 10, false, true );
	setWorldSoundEnabled( 17, 11, false, true );
end

function fPlayModifySiren( _, keyState )
	local vehicle = getPedOccupiedVehicle( localPlayer );
	
	if ( vehicle and tVehicles[ getElementModel( vehicle ) ] ) then
		if ( keyState == "down" ) then
			triggerServerEvent( "toggleSirens", resourceRoot, true );
		elseif ( keyState == "up" ) then
			triggerServerEvent( "toggleSirens", resourceRoot, false );
		end
	end
end

function fStartSiren( client )
	if ( not tAudio[ client ] ) then
		if ( tAudio[ client ] and isElement( tAudio[ client ] ) ) then
			destroyElement( tAudio[ client ] );
		end
		
		tAudio[ client ] = playSound3D( "sfx/siren.mp3", Vector3( getElementPosition( client ) ) );
		setSoundVolume( tAudio[ client ], 1.0 );
		setSoundMinDistance( tAudio[ client ], 1.0 );
		setSoundMaxDistance( tAudio[ client ], 100.0 );
		attachElements( tAudio[ client ], client );
	end
end

function fStopSiren( client )
	if ( tAudio[ client ] ) then
		if ( tAudio[ client ] and isElement( tAudio[ client ] ) ) then
			destroyElement( tAudio[ client ] );
			tAudio[ client ] = nil;
		end
	end
end

-- // EVENTOS
addEvent( "startSiren", true );
addEvent( "stopSiren", true );
addEventHandler( "startSiren", resourceRoot, fStartSiren );
addEventHandler( "stopSiren", resourceRoot, fStopSiren );
addEventHandler( "onClientResourceStart", resourceRoot, fClientResourceStart );

-- // KEYS
bindKey( "h", "both", fPlayModifySiren );

SERVER-SIDE

-- // FUNÇÕES
function fToggleSirens( state )
	if ( state ) then
		setVehicleSirensOn( getPedOccupiedVehicle( client ), false );		
		triggerClientEvent( root, "startSiren", resourceRoot, client );
	else
		triggerClientEvent( root, "stopSiren", resourceRoot, client );
	end
end

-- // EVENTOS
addEvent( "toggleSirens", true );
addEventHandler( "toggleSirens", resourceRoot, fToggleSirens );

 

  • Thanks 1
Link to comment
1 minute ago, asrzk said:

Aqui o script completo.

CLIENT-SIDE


-- // TABELA DE VEÍCULOS QUE TERÃO NOVAS SIRENES
local tVehicles 	= { [ 597 ] = true, [ 416 ] = true };

-- // TABELA DOS CLIENTES
local tAudio		= { };

-- // FUNÇÕES
function fClientResourceStart( )
	setWorldSoundEnabled( 17, 10, false, true );
	setWorldSoundEnabled( 17, 11, false, true );
end

function fPlayModifySiren( _, keyState )
	local vehicle = getPedOccupiedVehicle( localPlayer );
	
	if ( vehicle and tVehicles[ getElementModel( vehicle ) ] ) then
		if ( keyState == "down" ) then
			triggerServerEvent( "toggleSirens", resourceRoot, true );
		elseif ( keyState == "up" ) then
			triggerServerEvent( "toggleSirens", resourceRoot, false );
		end
	end
end

function fStartSiren( client )
	if ( not tAudio[ client ] ) then
		if ( tAudio[ client ] and isElement( tAudio[ client ] ) ) then
			destroyElement( tAudio[ client ] );
		end
		
		tAudio[ client ] = playSound3D( "sfx/siren.mp3", Vector3( getElementPosition( client ) ) );
		setSoundVolume( tAudio[ client ], 1.0 );
		setSoundMinDistance( tAudio[ client ], 1.0 );
		setSoundMaxDistance( tAudio[ client ], 100.0 );
		attachElements( tAudio[ client ], client );
	end
end

function fStopSiren( client )
	if ( tAudio[ client ] ) then
		if ( tAudio[ client ] and isElement( tAudio[ client ] ) ) then
			destroyElement( tAudio[ client ] );
			tAudio[ client ] = nil;
		end
	end
end

-- // EVENTOS
addEvent( "startSiren", true );
addEvent( "stopSiren", true );
addEventHandler( "startSiren", resourceRoot, fStartSiren );
addEventHandler( "stopSiren", resourceRoot, fStopSiren );
addEventHandler( "onClientResourceStart", resourceRoot, fClientResourceStart );

-- // KEYS
bindKey( "h", "both", fPlayModifySiren );

SERVER-SIDE


-- // FUNÇÕES
function fToggleSirens( state )
	if ( state ) then
		setVehicleSirensOn( getPedOccupiedVehicle( client ), false );		
		triggerClientEvent( root, "startSiren", resourceRoot, client );
	else
		triggerClientEvent( root, "stopSiren", resourceRoot, client );
	end
end

-- // EVENTOS
addEvent( "toggleSirens", true );
addEventHandler( "toggleSirens", resourceRoot, fToggleSirens );

 

Nossa! :) Muito obrigado mano ❤️

Link to comment
  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...