Sign in to follow this  
Captien

Sirens Silencer

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 2

Share this post


Link to post
Share on other sites

This example was created ages ago since 2017 where setSirenSound was named another function. Anyways thanks to notifying me, updated the script for current version compatibility.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Posted (edited)

@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
  • Sad 1

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.