MSK EngineToggle - Toggle Engine On/Off

Documentation
Github Download

Description

  • The engine keeps running if you leave the vehicle without turning the engine off.
  • You can set that the engine starts automatically when entering a vehicle.
  • You can set a Command and Hotkey (RegisterKeyMapping).
  • Set your own Notification and Progressbar.
  • If you set Config.VehicleKeys to true then only the Owner of the Vehicle or someone with a Key can start the Engine!
  • Admin Command to start/stop the engine without a Key (Bypass)
  • Whitelist for models and plates that do not need a Key to start/stop the engine
  • Save the Angel of the Steering Wheel (Synced)
  • Lockpick/Hotwire Function in compatibility with VehicleKeys

Config

Open Config
Config = {}
----------------------------------------------------------------
Config.Locale = 'de'
Config.Debug = true
Config.VersionChecker = true
----------------------------------------------------------------
-- Supported Frameworks: 'ESX', 'QBCore'
Config.Framework = 'ESX'
----------------------------------------------------------------
-- !!! This function is clientside AND serverside !!!
Config.Notification = function(source, message, typ)
    if IsDuplicityVersion() then -- serverside
        exports.msk_core:Notification(source, 'Engine', message, typ)
    else -- clientside
        exports.msk_core:Notification('Engine', message, typ)
    end
end
----------------------------------------------------------------
Config.Command = {
    enable = true, -- If you set to false then the Hotkey won't work !!!
    command = 'engine'
}

Config.Hotkey = {
    enable = true, -- Set false if you don't want to use a Hotkey
    key = 'M'
}

Config.AdminCommand = {
    enable = true, -- Start/Stop Engine if you don't have a key for that vehicle
    command = 'adengine',
    groups = {'superadmin', 'admin'}
}

Config.EngineOnAtEnter = false -- Set to true to toggle the engine automatically on when entering a vehicle

-- Set to true to start the engine from the second seat (Co-Driver)
-- Someone has to be on the Driver Seat, otherwise it won't work!
-- If VehicleKeys is activated, the Co-Driver needs a key.
Config.EngineFromSecondSeat = false
----------------------------------------------------------------
-- Vehicle Key System - set true then only the Owner of the Vehicle or someone with a Key can start the Engine

-- msk_vehiclekeys: https://forum.cfx.re/t/esx-qbcore-msk-vehiclekeys-unique-items/5264475
-- vehicle_keys: https://forum.cfx.re/t/esx-qbcore-vehicles-keys-vehicles-lock-remote-control-ui-and-much-more/4857274
-- VehicleKeyChain: https://forum.cfx.re/t/release-vehicle-key-chain-v4-1-4-esx-qb/3319563

Config.VehicleKeys = {
    enable = true, -- Set true to enable this feature

    -- Supported Scripts: 'msk_vehiclekeys', 'VehicleKeyChain', 'vehicle_keys', 'okokGarage'
    script = 'msk_vehiclekeys',

    -- This is for inventories with metadata like ox_inventory
    -- Supported Inventories: ox_inventory, qs-inventory, core_inventory
    -- For okokGarage you have to set this to true!
    uniqueItems = false, -- If set to true, it will search for the item in the inventory
    item = 'keys', -- Item in your inventory for vehicle keys
    plate = 'plate' -- Metadata Keyname for "plate" in your inventory
}
----------------------------------------------------------------
Config.SaveSteeringAngle = true
Config.SaveAngleOnExit = 75 -- default: F - 75 (Exit Vehicle)
----------------------------------------------------------------
-- With this feature you can set vehicles and plates for which you don't need a key to start the engine
-- either exact plates or just a string that should be in the vehicles plate e.g. "ESX" will ignore te plate "ESX1234" too
Config.Whitelist = {
    vehicles = {
        "caddy", "caddy2",
    },
    plates = {
        "ESX", "MSK",
    },
}
----------------------------------------------------------------
Config.EnableLockpick = true -- Set false if you want to deactivate this feature

Config.progressBar = function(time, message)
    exports.msk_core:ProgressStart(time, message)
end

Config.LockpickHotkey = {
    enable = false, -- Set to true if you want to use a Hotkey
    command = 'lockpickvehicle',
    key = 'N'
}

Config.PoliceAlert = {'police', 'sheriff', 'fib'}

Config.SafetyStages = {
    -- Do NOT rename the stages! Only change the options!
    -- On deafult 'stage_1' is installed on every owned vehicle

    ['stage_1'] = {
        item = 'vehicle_alarm_1', -- Usable Item to set the stage to the vehicle
        alarm = true, -- Acustic alarm
        ownerAlert = false, -- Notify Owner
        policeAlert = false, -- Notify Police
        liveCoords = false, -- Owner gets live coords (Blip)
    },
    ['stage_2'] = {
        item = 'vehicle_alarm_2', -- Usable Item to set the stage to the vehicle
        alarm = true, -- Acustic alarm
        ownerAlert = true, -- Notify Owner
        policeAlert = false, -- Notify Police
        liveCoords = false, -- Owner gets live coords (Blip)
    },
    ['stage_3'] = {
        item = 'vehicle_alarm_3', -- Usable Item to set the stage to the vehicle
        alarm = true, -- Acustic alarm
        ownerAlert = true, -- Notify Owner
        policeAlert = true, -- Notify Police
        liveCoords = false, -- Owner gets live coords (Blip)
    },
    ['stage_4'] = {
        item = 'vehicle_alarm_4', -- Usable Item to set the stage to the vehicle
        alarm = true, -- Acustic alarm
        ownerAlert = true, -- Notify Owner
        policeAlert = true, -- Notify Police
        liveCoords = true, -- Owner gets live coords (Blip)
    },
}

Config.LockpickSettings = {
    item = 'lockpick', -- Set the usable item that you want to use
    removeItem = true, -- Set true if you like to remove item after failing lockpicking

    startEngine = true, -- Set true if you want to start the engine after successfull lockpicking
    startEngineBypass = false, -- Set true if you want to start the engine always even if the player hasn't found the key

    -- If you set to 'skillbar' then there won't be a progressbar'
    -- If you set to 'progressbar' then there won't be a skillbar
    action = 'skillbar', -- Set to 'skillbar' or 'progressbar'

    -- If Config.VehicleKeys is activated then the player is always searching for the key
    enableSearchKey = true, -- Set false if you dont want this
    searchKey = 66 -- default: 66% // Probability to find the key
}

Config.LockpickProgessbar = {
    time = 10, -- In seconds // Time how long does it takes
    lockpick = 66, -- default: 66% // Probability successfully lockpick the vehicle
}

Config.LockpickSkillbar = {
    type = 'ox_lib', -- 'ox_lib' or 'qb-skillbar'

    -- This is only if you set to 'ox_lib'
    inputs = {'w', 'a', 's', 'd'},
    difficulty = {
        -- Presets:
        -- 'easy' -> { areaSize: 50, speedMultiplier: 1 }
        -- 'medium' -> { areaSize: 40, speedMultiplier: 1.5 }
        -- 'hard' -> { areaSize: 25, speedMultiplier: 1.75 }
        -- You can also use your own type:
        -- Example: {areaSize = 60, speedMultiplier = 1}

        ['1'] = 'easy', -- 'easy', 'medium', 'hard'
        ['2'] = 'easy', -- 'easy', 'medium', 'hard'
        ['3'] = {areaSize = 60, speedMultiplier = 1}, -- 'easy', 'medium', 'hard'
        ['4'] = 'easy', -- 'easy', 'medium', 'hard'
    }
}

Config.Animation = {
    lockpick = { -- Animation for lockpicking
        dict = 'anim@amb@clubhouse@tutorial@bkr_tut_ig3@',
        anim = 'machinic_loop_mechandplayer'
    },  
    searchKey = { -- Animation for search key
        dict = 'veh@plane@velum@front@ds@base',
        anim = 'hotwire',
        time = 8, -- in seconds // How long does it take to search for the key
        enableProgressbar = true
    },
    hotwire = { -- Animation for hotwire
        dict = 'veh@forklift@base',
        anim = 'hotwire',
        action = 'progressbar', -- Set to 'skillbar' or 'progressbar' // skillbar might cause the player to get out of the vehicle...
        time = 15, -- in seconds // How long does it take to hotwire the vehicle // Only for 'progressbar'
    }
}

Requirements

Optional

Exports

All exports are CLIENTSIDE. Look at the Documentation for more information.

  • toggleEngine → Toggles the engine on/off
  • toggleHotwire → Starts the Hotwire Feature
  • GetEngineState → Get the current Enginestate of the vehicle
  • SetVehicleDamaged → Set the vehicle undrivable (Can’t start/stop engine)
  • GetVehicleDamaged → Get the vehicle is undrivable
  • SetSteeringAngle → Set the steering angle
  • GetSteeringAngle → Get the steering angle

RealisticVehicleDamage

If you use RealisticVehicleDamage, then replace following Code in client.lua on Line 333 in RealisticVehicleDamage:

if healthEngineCurrent > cfg.engineSafeGuard+1 then
    SetVehicleUndriveable(vehicle, false)
    exports.msk_enginetoggle:SetVehicleDamaged(vehicle, false)
end

if healthEngineCurrent <= cfg.engineSafeGuard+1 and cfg.limpMode == false then
    SetVehicleUndriveable(vehicle, true)
    exports.msk_enginetoggle:SetVehicleDamaged(vehicle, true)
end

QB-Vehiclefailure

IF you use qb-vehiclefailure, then replace the following Code in client.lua on Line 530 in qb-vehiclefailure:

if healthEngineCurrent > cfg.engineSafeGuard+1 then
    SetVehicleUndriveable(vehicle, false)
    exports.msk_enginetoggle:SetVehicleDamaged(vehicle, false)
end

if healthEngineCurrent <= cfg.engineSafeGuard+1 and cfg.limpMode == false then
    local vehpos = GetEntityCoords(vehicle)
    StartParticleFxLoopedAtCoord("ent_ray_heli_aprtmnt_l_fire", vehpos.x, vehpos.y, vehpos.z-0.7, 0.0, 0.0, 0.0, 1.0, false, false, false, false)
    SetVehicleUndriveable(vehicle, true)
    exports.msk_enginetoggle:SetVehicleDamaged(vehicle, true)
end

My other Scripts

Paid

Free

11 Likes

Very Nice Release, thank you very much!

1 Like

can u make it for qbcore aswell

Very Nice :+1:

Should work with qbcore. Please try it out :slight_smile:

ok will do and let u know soon

this script needs changing abit maybe put the m button to G instead would be better

You can do that by yourself in config.lua :slight_smile:

yh did and it made my server go wired i mean loads of wired letters on screen

Synced between players?

Update v2.6.5

  • Added Server Console Print if Config.VehicleKeyChain = true to see if this Script is started or stopped.

Download: Releases · Musiker15/EngineToggle · GitHub

1 Like

Yes it is synced between players

2 Likes

Are you sure it’s synced? Because I just ran this script on my server, testing with someone in the UK (I’m in Australia), and the engine status does not sync unless we both turn the car on or off ourselves.
Running OneSync Infinity, latest (as of 5 days ago) artefact, admittedly very old framework. Configs are as default, except for keybind change. Version 2.6.5. Script is running fine, other than the lack of syncing between players.

Also, might I suggest using a locale file so server devs don’t need to manually translate the
 German, is it? Up to you if you want to do this though. :slight_smile:

1 Like

Update v2.7

  • Added locale files
  • You can change the language in config.lua
  • New Design for Version Checker

Update v2.8

  • Faster Callback
  • Fixed Notification if Player don’t have a Key and is outside of a vehicle and pressing ToggleKey

Update v2.8.1

Bugfix for v2.8

  • Changed playerPed to PlayerPedId()
1 Like

Hey, zuerst mal geiles Script!

Benutze es jetzt schon ungefÀhr eine Woche, lÀuft alles Super.
Ich habe zum einen die esx_dmvschool und den Mechaniker Job wo der Spieler keine SchlĂŒssel fĂŒr das Fahrzeug bekommt.
Wie kann ich es so konfigurieren, dass der Spieler trotz “VehicleKeyChain = true” das Fahrzeug an und ausschalten kann?

function StartDriveTest(type)
    ESX.Game.SpawnVehicle(Config.VehicleModels[type], Config.Zones.VehicleSpawnPoint.Pos, Config.Zones.VehicleSpawnPoint.Pos.h, function(vehicle)
        CurrentTest       = 'drive'
        CurrentTestType   = type
        CurrentCheckPoint = 0
        LastCheckPoint    = -1
        CurrentZoneType   = 'residence'
        DriveErrors       = 0
        IsAboveSpeedLimit = false
        CurrentVehicle    = vehicle
        LastVehicleHealth = GetEntityHealth(vehicle)

        local playerPed   = PlayerPedId()
        TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
        SetVehicleFuelLevel(vehicle, 100.0)
        DecorSetFloat(vehicle, "_FUEL_LEVEL", GetVehicleFuelLevel(vehicle))
        SetVehicleNumberPlateText(vehicle, 'SCHOOL')

        exports["kimi_callbacks"]:Trigger("VKC:createNewKey", 'SCHOOL', 1, true)
        --print('VKC: SchlĂŒssel wurde hinzugefĂŒgt')
    end)

    TriggerServerEvent('esx_dmvschool:pay', Config.Prices[type])
end

function StopDriveTest(success)
    if success then
        TriggerServerEvent('esx_dmvschool:addLicense', CurrentTestType)
        ESX.ShowNotification(_U('passed_test'))

        exports["kimi_callbacks"]:Trigger("VKC:removeKey", 'SCHOOL', 1)
        --print('VKC: SchlĂŒssel wurde entfernt')
    else
        ESX.ShowNotification(_U('failed_test'))

        exports["kimi_callbacks"]:Trigger("VKC:removeKey", 'SCHOOL', 1)
        --print('VKC: SchlĂŒssel wurde entfernt')
    end

    CurrentTest     = nil
    CurrentTestType = nil
end

Update v2.9

  • Updated VersionChecker
  • Updated Readme.md for VehicleKeyChain Support


i have a mistake