Jump to content

[UPDATED] Sirens Silencer


Captien

Recommended Posts

Hello Guys,

Welcome again to another tutorial. Today i'm going to introduce to you guys the Sirens Silencer.

If you want to be stealth and raid the criminals without they notice you, this will be your solution.

The script is very simple.
 

When player enters a Emergency Vehicle, the script will work by pressing B. The silencer is also saved for future uses if you park yours car and took another one and then came back. The silencer will be waiting you.

Server-side:

Spoiler

mp.events.add('syncSirens', (player, vehicle) => {
    if (vehicle && mp.vehicles.exists(vehicle.id)) vehicle.setVariable('silentMode', !vehicle.getVariable('silentMode'))
});

 

Client-side:

Spoiler

let localPlayer = mp.players.local;

mp.keys.bind(0x42, true, _ => {
    if (localPlayer.vehicle && localPlayer.vehicle.getPedInSeat(-1) === localPlayer.handle && localPlayer.vehicle.getClass() === 18) {
        localPlayer.vehicle.getVariable('silentMode') ? mp.game.graphics.notify(`Silent mode is deactivated.`) : mp.game.graphics.notify(`Silent mode is activated.`);
        mp.events.callRemote('syncSirens', localPlayer.vehicle)
    }
});

mp.events.add('entityStreamIn', (entity) => {
    if (entity.type === 'vehicle' && entity.getClass() === 18 && entity.hasVariable('silentMode')) entity.getVariable('silentMode') ? entity.setSirenSound(true) : entity.setSirenSound(false);
    
});

mp.events.addDataHandler("silentMode", (entity, value) => {
    if (entity.type === "vehicle") entity.setSirenSound(value);
});

 

If you need any help, don't hesitate to post your problem in this topic.

You're free to use, change, copy this script. (Don't Forget some credits)

Hope you enjoyed the Tutorial.
Have a nice day!

Regards,
Captien.

Edited by Captien
Added improved version
  • Like 6
Link to comment
Share on other sites

  • 1 year later...
  • 3 weeks later...
  • 1 month later...
21 minutes ago, DatMayo said:

Is there a way to get this sync? Setting the value of another emergency car will not effect other players :/

ofcourse, trigger a server event whenever you changing the siren sound property, catch the event on your server then send an event to all players.

Link to comment
Share on other sites

@Captien this is an error:

 

mp.events.add('entityStreamIn', (entity) => { if (entity.type === 'vehicle' && entity.getClass() === 18 && entity.hasVariable('silentMode')) localPlayer.vehicle.getVariable('silentMode') ? entity.setSirenSound(true) : entity.setSirenSound(false); });

should be

mp.events.add('entityStreamIn', (entity) => {
    if (entity.type === 'vehicle' && entity.getClass() === 18 && entity.hasVariable('silentMode')) entity.getVariable('silentMode') ? entity.setSirenSound(true) : entity.setSirenSound(false);
    
});
Edited by Flow
  • Like 1
  • Sad 1
Link to comment
Share on other sites

  • 2 months later...
  • 1 month 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...