[Re-Release] EngineToggle

EngineToggle

FiveM Script - Vehicle Engine Toggle On/Off

Download: GitHub - Musiker15/msk_enginetoggle: FiveM Script - Vehicle EngineToggle | Keeps the engine running if you leave the vehicle without turning the engine off

I updated the old Script and added some cool things :slight_smile:

Old Topic: [Release] Engine ON/OFF Toggle

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 choose if you use a Hotkey or a Command.
  • You can choose between 3 diffrent Notifications.
  • If you set Config.VehicleKeyChain to true then only the Owner of the Vehicle or someone with a Key can start the Engine!
  • Hotwire Function in compatibility with VKC

Config

Config = {}
----------------------------------------------------------------
Config.Locale = 'de'
Config.VersionChecker = true
Config.getSharedObject = 'esx:getSharedObject'
----------------------------------------------------------------
-- Change 'false' to 'true' to toggle the engine automatically on when entering a vehicle
Config.OnAtEnter = false
----------------------------------------------------------------
Config.UseKey = true -- Set true if you want to use a Hotkey
    Config.ToggleKey = 244 -- M (https://docs.fivem.net/docs/game-references/controls/)
Config.UseCommand = false -- Set true if you want to use a Command
    Config.Commad = 'engine'
----------------------------------------------------------------
-- Vehicle Key System - set true then only the Owner of the Vehicle or someone with a Key can start the Engine
Config.VehicleKeyChain = false -- https://kiminazes-script-gems.tebex.io/package/4524211
----------------------------------------------------------------
-- !!! This function is clientside AND serverside !!!
-- Look for type == 'client' and type == 'server'
Config.Notification = function(src, type, xPlayer, message) -- xPlayer = ESX.GetPlayerFromId(src)
    if type == 'client' then -- clientside
        ESX.ShowNotification(message) -- replace this with your Notify // example: exports['okokNotify']:Alert('Crafting', message, 5000, 'info')
    elseif type == 'server' then -- serverside
        xPlayer.showNotification(message) -- replace this with your Notify // example: TriggerClientEvent('okokNotify:Alert', src, 'Crafting', message, 5000, 'info')
    end
end
----------------------------------------------------------------
Config.progressBar = function(time, message)
    exports['pogressBar']:drawBar(time, message)
end
----------------------------------------------------------------
Config.RemoveLockpickItem = true -- Set true if you like to remove item after failing lockpicking
Config.LockpickItem = 'lockpick' -- Set the itemname what you want to use
Config.startEngine = true -- Set true if you want to start the engine after successfull lockpicking
Config.Probability = {
    lockpick = 66, -- default: 66%
    alarm = 33, -- default: 33%
    enableSearchKey = true, -- Set false if you dont want this
    searchKey = 66 -- default: 66%
}
Config.LockpickKey = {
    enable = false, -- Set to true if you want to use a Hotkey
    key = 38 -- default: E // Set the Hotkey
}
Config.ProgessBar = {
    enable = true, -- Set true if you want to show a progressbar
    time = 8 -- In seconds // Time how long does it takes
}
Config.Animation = {
    InsideOutsideAnimation = true, -- Set to false if you want same Animation for inside and outside
    generalAnimation = 'WORLD_HUMAN_WELDING',
    
    insideVehicle = { -- Animation inside Vehicle
        dict = 'anim@amb@clubhouse@tutorial@bkr_tut_ig3@',
        anim = 'machinic_loop_mechandplayer'
    },
    outsideVehicle = { -- Animation outside Vehicle
        dict = 'anim@amb@clubhouse@tutorial@bkr_tut_ig3@',
        anim = 'machinic_loop_mechandplayer'
    }
}

Requirements

  • Standalone
  • ESX Framework only for Hotwire Function

Optional

VehicleKeyChain

If you want to add a permanent key:

-- clientside --
local plate = GetVehicleNumberPlateText(vehicle)
TriggerServerEvent('VKC:setKey', true, plate, 1) -- Give a Key to the Player
TriggerServerEvent('VKC:setKey', false, plate, 1) -- Remove the Key from the Player

-- or this one

-- clientside --
-- Give a Key to the Player
local plate = 'ABC 123'
SetVehicleNumberPlateText(vehicle, plate) -- Only if you don't use AdvancedParking
exports["AdvancedParking"]:UpdatePlate(vehicle, plate) -- Only if you use AdvancedParking
TriggerServerEvent('VKC:setKey', true, plate, 1)
-- Remove the Key from the Player
TriggerServerEvent('VKC:setKey', false, plate, 1)

-- serverside --
RegisterServerEvent('VKC:setKey')
AddEventHandler('VKC:setKey', function(set, plate, count)
    if set then -- Add Key
        exports["VehicleKeyChain"]:AddKey(source, plate, count)
    else -- Remove Key
        exports["VehicleKeyChain"]:RemoveKey(source, plate, count)
    end
end)

If you only want a temporary key that will be deleted after restart use this:

-- clientside --
TriggerServerEvent("VKC:giveTempKey", true, "PLATE") -- Add Temp Key
TriggerServerEvent("VKC:giveTempKey", false, "PLATE") -- Remove Temp Key

-- serverside --
RegisterNetEvent("VKC:giveTempKey")
AddEventHandler("VKC:giveTempKey", function(set, plate)
    if set then -- Add Temp Key
        exports["VehicleKeyChain"]:AddTempKey(source, plate)
    else -- Remove Temp Key
        exports["VehicleKeyChain"]:RemoveTempKey(source, plate)
    end
end)

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)
    TriggerEvent('EngineToggle:RPDamage', true)
end

if healthEngineCurrent <= cfg.engineSafeGuard+1 and cfg.limpMode == false then
    SetVehicleUndriveable(vehicle,true)
    TriggerEvent('EngineToggle:RPDamage', false)
end

My other Scripts

Paid

Free

Changelogs

Update v3.4
  • Changed a lot of things
  • Added new Configs for Notifications and ProgressBar
  • Fixed getting a TempKey if Hotwire a Vehicle failed
  • Fixed Player shaking inside car without engine running
Update v3.1.4
  • Fixed an issue were the vehicle is nil after lockpicking
Update v3.1.3

Added Probability for searchKey function

Update v3.1.2
  • Fixed Notification Bug after failed lockpicking
Update v3.1.1
  • Bugfix for this Error:
SCRIPT ERROR: @VehicleKeyChain/server/server.lua:363: Parameter "playerId" must be a number!

fixed by Kiminaze

Update v3.1
  • Added Hotwire Function in compatibility with VehicleKeyChain
Update v3.0.1
  • Bugfix for last Update v3.0
Update v3.0
  • Added Support for latest VehicleKeyChain by Kiminaze
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